Skip to content

Commit 7d12a9f

Browse files
mahmoudmagdy1-1rdeutzalikonsoftforgeHLeithner
authored
[6.0] Add Support for Github Codespaces (#45719)
* Add support for github codespaces * rm unnecessary line * Fix Naming to match Cypress tests & Cypress configuration * update to php 8.3. for 6.0 * change apache image & remove deperecated dependency & move .vscode --------- Co-authored-by: Robert Deutz <[email protected]> Co-authored-by: Nicola Galgano <[email protected]> Co-authored-by: Phil Walton <[email protected]> Co-authored-by: Harald Leithner <[email protected]> Co-authored-by: Allon Moritz <[email protected]>
1 parent 5b41b0c commit 7d12a9f

File tree

5 files changed

+293
-0
lines changed

5 files changed

+293
-0
lines changed

.devcontainer/Dockerfile

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Start from the official PHP 8.3 image with Apache
2+
FROM php:8.3-apache-bookworm
3+
4+
# Install system dependencies, Node.js, Composer, and Cypress dependencies
5+
RUN apt-get update && apt-get install -y \
6+
# System tools and git
7+
git \
8+
unzip \
9+
curl \
10+
sudo \
11+
# PHP extensions dependencies
12+
libpng-dev \
13+
libonig-dev \
14+
libxml2-dev \
15+
libzip-dev \
16+
# MySQL client AND server
17+
default-mysql-client \
18+
default-mysql-server \
19+
# Cypress dependencies
20+
xvfb \
21+
libgtk2.0-0 \
22+
libgtk-3-0 \
23+
libgbm-dev \
24+
libnotify-dev \
25+
libnss3 \
26+
libxss1 \
27+
libasound2 \
28+
libxtst6 \
29+
xauth \
30+
libldap2-dev \
31+
libgd-dev \
32+
&& \
33+
# Install the required PHP extensions for Zip and MySQL
34+
docker-php-ext-install zip mysqli gd ldap && \
35+
# Install Node.js (LTS version)
36+
curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - && \
37+
apt-get install -y nodejs && \
38+
# Install Composer globally
39+
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \
40+
# Install Xdebug
41+
pecl install xdebug && \
42+
# Clean up apt cache to reduce image size
43+
apt-get clean && rm -rf /var/lib/apt/lists/*
44+
45+
# After installing everything
46+
RUN sed -i 's|/var/www/html|/workspaces/joomla-cms|g' /etc/apache2/sites-available/000-default.conf \
47+
&& sed -i 's|/var/www/html|/workspaces/joomla-cms|g' /etc/apache2/apache2.conf
48+
49+
# Enable Apache's rewrite module and set the ServerName to prevent warnings
50+
RUN a2enmod rewrite \
51+
&& echo "ServerName localhost" >> /etc/apache2/apache2.conf
52+
53+
# Create a custom PHP configuration file to enable file uploads
54+
RUN echo "upload_tmp_dir = /tmp" > /usr/local/etc/php/conf.d/custom-php.ini && \
55+
echo "post_max_size = 64M" >> /usr/local/etc/php/conf.d/custom-php.ini && \
56+
echo "upload_max_filesize = 64M" >> /usr/local/etc/php/conf.d/custom-php.ini

.devcontainer/devcontainer.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "Joomla Dev Environment",
3+
"dockerComposeFile": "docker-compose.yml",
4+
"service": "app",
5+
"workspaceFolder": "/workspaces/joomla-cms",
6+
"features": {
7+
"ghcr.io/devcontainers/features/desktop-lite:1": {}
8+
},
9+
"portsAttributes": {
10+
"80" : {
11+
"label": "Web Server (Joomla & phpmyadmin)",
12+
"onAutoForward": "silent"
13+
},
14+
"6080": {
15+
"label": "Cypress GUI",
16+
"onAutoForward": "silent"
17+
}
18+
},
19+
"postCreateCommand": "bash ./.devcontainer/post-create.sh",
20+
"customizations": {
21+
"vscode": {
22+
"extensions": [
23+
"xdebug.php-debug",
24+
"bmewburn.vscode-intelephense-client",
25+
"esbenp.prettier-vscode"
26+
],
27+
"settings": {
28+
"launch": {
29+
"version": "0.2.0",
30+
"configurations": [
31+
{
32+
"name": "Listen for Xdebug",
33+
"type": "php",
34+
"request": "launch",
35+
"port": 9003,
36+
"log": false
37+
}
38+
]
39+
}
40+
}
41+
}
42+
},
43+
"remoteUser": "root"
44+
}

.devcontainer/docker-compose.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
services:
2+
app:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
volumes:
7+
- ..:/workspaces/joomla-cms:cached
8+
- ./xdebug.ini:/usr/local/etc/php/conf.d/99-xdebug.ini
9+
ports:
10+
- "80:80"
11+
- "3306:3306"
12+
- "6080:6080"
13+
command: sleep infinity
14+
15+
mysql:
16+
image: mysql:8.0
17+
command: --default-authentication-plugin=mysql_native_password
18+
restart: unless-stopped
19+
environment:
20+
MYSQL_ROOT_PASSWORD: root
21+
MYSQL_DATABASE: test_joomla
22+
MYSQL_USER: joomla_ut
23+
MYSQL_PASSWORD: joomla_ut
24+
volumes:
25+
- "mysql-data:/var/lib/mysql"
26+
27+
volumes:
28+
mysql-data:

.devcontainer/post-create.sh

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#!/bin/bash
2+
3+
# Exit immediately if a command exits with a non-zero status.
4+
set -e
5+
6+
echo "--- Starting Joomla Core Post-Creation Setup ---"
7+
8+
# Configuration variables
9+
DB_NAME="test_joomla"
10+
DB_USER="joomla_ut"
11+
DB_PASS="joomla_ut"
12+
ADMIN_USER="ci-admin"
13+
ADMIN_REAL_NAME="jane doe"
14+
ADMIN_PASS="joomla-17082005"
15+
ADMIN_EMAIL="[email protected]"
16+
JOOMLA_ROOT="/workspaces/joomla-cms"
17+
18+
# Allow git commands to run safely in the container
19+
git config --global --add safe.directory $JOOMLA_ROOT
20+
21+
# --- 1. Wait for MariaDB Service ---
22+
echo "--> Waiting for MariaDB to become available..."
23+
while ! mysqladmin ping -h"mysql" --silent; do
24+
sleep 1
25+
done
26+
echo "✅ MariaDB is ready."
27+
28+
# --- 2. Install Core Dependencies ---
29+
echo "--> Installing Composer and NPM dependencies..."
30+
composer install
31+
npm install
32+
echo "✅ Dependencies installed."
33+
34+
# --- 3. Install Joomla from Repository Source ---
35+
echo "--> Installing Joomla using the local repository source..."
36+
php installation/joomla.php install \
37+
--site-name="Joomla CMS Test" \
38+
--admin-user="$ADMIN_REAL_NAME" \
39+
--admin-username="$ADMIN_USER" \
40+
--admin-password="$ADMIN_PASS" \
41+
--admin-email="$ADMIN_EMAIL" \
42+
--db-type="mysqli" \
43+
--db-host="mysql" \
44+
--db-name="$DB_NAME" \
45+
--db-user="$DB_USER" \
46+
--db-pass="$DB_PASS" \
47+
--db-prefix="jos_" \
48+
--db-encryption="0" \
49+
--public-folder=""
50+
echo "✅ Joomla installed."
51+
52+
# --- 4. Configure Joomla for Development ---
53+
echo "--> Applying development settings..."
54+
# Enable debug mode and maximum error reporting for easier troubleshooting.
55+
php cli/joomla.php config:set error_reporting=maximum
56+
echo "✅ Development settings applied."
57+
58+
# --- 5. Install and Configure phpMyAdmin ---
59+
PMA_ROOT="${JOOMLA_ROOT}/phpmyadmin"
60+
echo "--> Downloading phpMyAdmin into $PMA_ROOT..."
61+
PMA_VERSION=5.2.2
62+
mkdir -p $PMA_ROOT
63+
curl -o /tmp/phpmyadmin.tar.gz https://files.phpmyadmin.net/phpMyAdmin/${PMA_VERSION}/phpMyAdmin-${PMA_VERSION}-all-languages.tar.gz
64+
tar xf /tmp/phpmyadmin.tar.gz --strip-components=1 -C $PMA_ROOT
65+
rm /tmp/phpmyadmin.tar.gz
66+
cp $PMA_ROOT/config.sample.inc.php $PMA_ROOT/config.inc.php
67+
sed -i "/\['AllowNoPassword'\] = false/a \$cfg['Servers'][\$i]['host'] = 'mysql';" $PMA_ROOT/config.inc.php
68+
69+
# --- 6. Apply Codespaces Host Fix ---
70+
# This ensures Joomla generates correct URLs when accessed through the forwarded port.
71+
echo "--> Applying Codespaces URL fix..."
72+
cat > "${JOOMLA_ROOT}/fix.php" << 'EOF'
73+
<?php
74+
// Fix for incorrect host when running behind the Codespaces reverse proxy.
75+
if (isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST'] === 'localhost:80') {
76+
if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
77+
$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
78+
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
79+
}
80+
}
81+
EOF
82+
83+
# Include fix in both entry points
84+
cp $JOOMLA_ROOT/fix.php $JOOMLA_ROOT/administrator/fix.php
85+
sed -i '2i require_once __DIR__ . "/fix.php";' $JOOMLA_ROOT/index.php
86+
sed -i '2i require_once __DIR__ . "/../fix.php";' $JOOMLA_ROOT/administrator/index.php
87+
88+
echo "--> Ignoring local changes..."
89+
# For TRACKED files, tell Git to stop watching them for changes
90+
git update-index --assume-unchanged "index.php"
91+
git update-index --assume-unchanged "administrator/index.php"
92+
git update-index --assume-unchanged "package-lock.json"
93+
git update-index --assume-unchanged "tests/System/integration/install/Installation.cy.js"
94+
git update-index --assume-unchanged "tests/System/support/commands/config.mjs"
95+
96+
# For NEW UNTRACKED files, add them to the local exclude file
97+
echo "cypress.config.js" >> ".git/info/exclude"
98+
echo "fix.php" >> ".git/info/exclude"
99+
echo "administrator/fix.php" >> ".git/info/exclude"
100+
echo "phpmyadmin" >> ".git/info/exclude"
101+
echo "codespace-details.txt" >> ".git/info/exclude"
102+
103+
# --- 7. Finalize Permissions and Testing Tools ---
104+
echo "--> Setting up file permissions and Cypress..."
105+
sed -i \
106+
-e "/\/\/ If exists, delete PHP configuration file to force a new installation/d" \
107+
-e "/cy.task('deleteRelativePath', 'configuration.php');/d" \
108+
-e "/cy.installJoomla(config);/d" \
109+
tests/System/integration/install/Installation.cy.js
110+
sed -i "s/return cy.task('writeRelativeFile', { path: 'configuration.php', content });/return cy.task('writeRelativeFile', { path: 'configuration.php', content, mode: 0o775 });/" tests/System/support/commands/config.mjs
111+
112+
# Ensure Cypress is executable and owned by the web server user
113+
chmod +x ./node_modules/.bin/cypress
114+
cp cypress.config.dist.mjs cypress.config.js
115+
npx cypress install
116+
sed -i -e "s|baseUrl:.*|baseUrl: 'http://localhost:80',|" -e "s/db_host: 'localhost'/db_host: 'mysql'/g" -e "s/db_user: 'root'/db_user: 'joomla_ut'/g" -e "s/db_password: ''/db_password: 'joomla_ut'/g" cypress.config.js
117+
118+
# Restart Apache to apply all changes
119+
echo '<Directory /workspaces/joomla-cms>
120+
AllowOverride All
121+
Require all granted
122+
</Directory>' | sudo tee -a /etc/apache2/apache2.conf
123+
service apache2 restart
124+
125+
# Set the group to www-data and enforce group permissions
126+
echo "--> Applying final group ownership and permissions..."
127+
chgrp -R www-data $JOOMLA_ROOT
128+
chmod -R g+rws $JOOMLA_ROOT
129+
130+
echo "✅ Environment finalized."
131+
132+
# --- 8. Display Setup Details ---
133+
# Save the details to a file for easy reference.
134+
DETAILS_FILE="${JOOMLA_ROOT}/codespace-details.txt"
135+
{
136+
echo ""
137+
echo "---"
138+
echo "🚀 Joomla Core development environment is ready! 🚀"
139+
echo ""
140+
echo "This information has been saved to codespace-details.txt"
141+
echo ""
142+
echo "Joomla Admin Login:"
143+
echo " URL: Open the 'Ports' tab, find the 'Web Server' (80), and click the Globe icon. Then add /administrator"
144+
echo " Username: $ADMIN_USER"
145+
echo " Password: $ADMIN_PASS"
146+
echo ""
147+
echo "phpMyAdmin Login:"
148+
echo " URL: Open the 'Web Server' port and add /phpmyadmin"
149+
echo " Username: $DB_USER"
150+
echo " Password: $DB_PASS"
151+
echo ""
152+
echo "Cypress E2E Testing:"
153+
echo " Run interactive tests: npx cypress open"
154+
echo " Run headless tests: npx cypress run"
155+
echo ""
156+
echo "Xdebug for PHP Debugging:"
157+
echo " Xdebug is pre-configured on port 9003. Use the 'Run and Debug' panel in VS Code and select 'Listen for Xdebug'."
158+
echo "---"
159+
} | tee "$DETAILS_FILE"

.devcontainer/xdebug.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[xdebug]
2+
zend_extension=xdebug
3+
xdebug.mode=debug
4+
xdebug.start_with_request=yes
5+
xdebug.client_port=9003
6+
xdebug.client_host=localhost

0 commit comments

Comments
 (0)