diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 9cb459b..0e3920b 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -63,7 +63,7 @@ jobs: PHP_VERSION: 7.2 docker_build: - name: "Docker build: ${{ matrix.os_flavour }} for alpine" + name: "Docker build: PS ${{ matrix.ps_version }} for alpine" runs-on: ubuntu-latest timeout-minutes: 15 needs: [docker_dry_build] @@ -100,11 +100,20 @@ jobs: env: DOCKER_IMAGE: prestashop/prestashop-flashlight:${{ matrix.ps_version }} + - name: Test the image tooling(xdebug) + run: docker run --env PS_DOMAIN='localhost:80' --entrypoint bash $DOCKER_IMAGE -c 'php -m -c | grep xdebug' + env: + DOCKER_IMAGE: prestashop/prestashop-flashlight:${{ matrix.ps_version }} + docker_build_debian: - name: "Docker build: 8.1.2 for debian" + name: "Docker build: PS ${{ matrix.ps_version }} for debian" runs-on: ubuntu-latest timeout-minutes: 15 needs: [docker_dry_build] + strategy: + fail-fast: true + matrix: + ps_version: ["1.6.1.24", "1.7.6.9", "1.7.7.8", "1.7.8.11", "8.1.4"] steps: - name: Checkout repository uses: actions/checkout@v4 @@ -113,7 +122,12 @@ jobs: run: ./build.sh env: OS_FLAVOUR: "debian" - PS_VERSION: "8.1.2" + PS_VERSION: ${{ matrix.ps_version }} + + - name: Test the image with a dry run + run: docker run --env PS_DOMAIN='localhost:80' --env DRY_RUN='true' $DOCKER_IMAGE + env: + DOCKER_IMAGE: prestashop/prestashop-flashlight:${{ matrix.ps_version }}-debian docker_build_nightly: name: "Docker build: PS nightly" @@ -131,7 +145,7 @@ jobs: docker_build_cross_compile: name: "Docker build x-compile for aarch64" runs-on: ubuntu-latest - timeout-minutes: 20 + timeout-minutes: 45 needs: docker_build_debian steps: - name: Checkout repository diff --git a/.gitignore b/.gitignore index 6c56220..00e0125 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ sonar-project.properties PrestaShop/ +prestashop/ vendor/ .prestashop-tags .prestashop-minor-tags diff --git a/README.md b/README.md index 8b9d4bd..fa2b64d 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ PrestaShop Flashlight can be used as a **development environment**, a **CI/CD as - [Custom post-scripts](./examples/with-post-scripts/) - [Ngrok tunneling](./examples/ngrok-tunnel) - [Auto installation of modules](./examples/auto-install-modules/) +- [Xdebug a store](./examples/xdebug-prestashop/) - Develop a PrestaShop Theme (coming soon) - Use in GitHub Action (coming soon) @@ -55,34 +56,35 @@ You can check this implementation anytime in [prestashop-version.json](./prestas ## Environment variables -| Variable | Description | Default value | -| -------------------------- | -------------------------------------------------------------------------------------------------------- | -------------------------------------- | -| PS_DOMAIN¹ | the public domain (and port) to reach your PrestaShop instance | N/A (example: `localhost:8000`) | -| NGROK_TUNNEL_AUTO_DETECT² | the ngrok agent base API url, to guess the tunnel domain of your shop | N/A (example `http://ngrok:4040`) | -| PS_PROTOCOL | if PS_PROTOCOL equals `https` the public URL will be `https://$PS_DOMAIN` | `http` (example: `https`) | -| SSL_REDIRECT | if enabled the public URL will be `https://$PS_DOMAIN` (if not using `PS_PROTOCOL`) | `false` (example: `true`) | -| DEBUG_MODE | if enabled the Debug mode will be enabled on PrestaShop | `false` | -| INSTALL_MODULES_DIR | module directory containing zips to be installed with the PrestaShop CLI | empty string (example: `/ps-modules`) | -| INIT_SCRIPTS_DIR | script directory with executable files to be run prior to PrestaShop startup | `/tmp/init-scripts` | -| POST_SCRIPTS_DIR | script directory with executable files to be run after the PrestaShop startup | `/tmp/post-scripts` | -| INIT_SCRIPTS_USER | the user running the executable files to be run prior to PrestaShop startup | `www-data` | -| POST_SCRIPTS_USER | the user running the executable files to be run after the PrestaShop startup | `www-data` | -| INIT_ON_RESTART | if enabled the PS_DOMAIN auto search and dump fix will be replayed on container restart | `false` | -| DUMP_ON_RESTART | if enabled the dump restoration replayed on container restart | `false` | -| INSTALL_MODULES_ON_RESTART | if enabled zip modules will be reinstalled on container restart | `false` | -| INIT_SCRIPTS_ON_RESTART | if enabled custom init scripts will be replayed on container restart | `false` | -| POST_SCRIPTS_ON_RESTART | if enabled custom post scripts will be replayed on container restart | `false` | -| ON_INIT_SCRIPT_FAILURE | if set to `continue`, PrestaShop Flashlight will continue the boot process even if an init script failed | `fail` | -| ON_POST_SCRIPT_FAILURE | if set to `continue`, PrestaShop Flashlight won't exit in case of script failure | `fail` | -| ON_INSTALL_MODULES_FAILURE | if set to `continue`, module installation failure will not block the init process | `fail` | -| DRY_RUN | if enabled, the run.sh script will exit without really starting a web server | `false` | -| MYSQL_HOST | MySQL host | `mysql` | -| MYSQL_USER | MySQL user | `prestashop` | -| MYSQL_PASSWORD | MySQL password | `prestashop` | -| MYSQL_PORT | MySQL server port | `3306` | -| MYSQL_DATABASE | MySQL database name | `prestashop` | -| MYSQL_EXTRA_DUMP | extra SQL dump to be restored in PrestaShop | empty string (example: `/tmp/foo.sql`) | -| PS_FOLDER | prestashop sources directory | `/var/www/html` | +| Variable | Description | Default value | +| -------------------------- | ------------------------------------------------------------------------------------------------------------ | -------------------------------------- | +| PS_DOMAIN¹ | the public domain (and port) to reach your PrestaShop instance | N/A (example: `localhost:8000`) | +| NGROK_TUNNEL_AUTO_DETECT² | the ngrok agent base API url, to guess the tunnel domain of your shop | N/A (example `http://ngrok:4040`) | +| DEBUG_MODE | if enabled the Debug mode will be enabled on PrestaShop | `false` | +| DRY_RUN | if enabled, the run.sh script will exit without really starting a web server | `false` | +| DUMP_ON_RESTART | if enabled the dump restoration replayed on container restart | `false` | +| INIT_ON_RESTART | if enabled the PS_DOMAIN auto search and dump fix will be replayed on container restart | `false` | +| INIT_SCRIPTS_DIR | script directory with executable files to be run prior to PrestaShop startup | `/tmp/init-scripts` | +| INIT_SCRIPTS_ON_RESTART | if enabled custom init scripts will be replayed on container restart | `false` | +| INIT_SCRIPTS_USER | the user running the executable files to be run prior to PrestaShop startup | `www-data` | +| INSTALL_MODULES_DIR | module directory containing zips to be installed with the PrestaShop CLI | empty string (example: `/ps-modules`) | +| INSTALL_MODULES_ON_RESTART | if enabled zip modules will be reinstalled on container restart | `false` | +| MYSQL_DATABASE | MySQL database name | `prestashop` | +| MYSQL_EXTRA_DUMP | extra SQL dump to be restored in PrestaShop | empty string (example: `/tmp/foo.sql`) | +| MYSQL_HOST | MySQL host | `mysql` | +| MYSQL_PASSWORD | MySQL password | `prestashop` | +| MYSQL_PORT | MySQL server port | `3306` | +| MYSQL_USER | MySQL user | `prestashop` | +| ON_INIT_SCRIPT_FAILURE | if set to `continue`, PrestaShop Flashlight will continue the boot process even if an init script failed | `fail` | +| ON_INSTALL_MODULES_FAILURE | if set to `continue`, module installation failure will not block the init process | `fail` | +| ON_POST_SCRIPT_FAILURE | if set to `continue`, PrestaShop Flashlight won't exit in case of script failure | `fail` | +| POST_SCRIPTS_DIR | script directory with executable files to be run after the PrestaShop startup | `/tmp/post-scripts` | +| POST_SCRIPTS_ON_RESTART | if enabled custom post scripts will be replayed on container restart | `false` | +| POST_SCRIPTS_USER | the user running the executable files to be run after the PrestaShop startup | `www-data` | +| PS_FOLDER | prestashop sources directory | `/var/www/html` | +| PS_PROTOCOL | if PS_PROTOCOL equals `https` the public URL will be `https://$PS_DOMAIN` | `http` (example: `https`) | +| SSL_REDIRECT | if enabled the public URL will be `https://$PS_DOMAIN` (if not using `PS_PROTOCOL`) | `false` (example: `true`) | +| XDEBUG_ENABLED | if enabled Xdebug will be enabled in PHP. See settings here: `$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini` | `false` (example: `true`) | > Note: > diff --git a/assets/alpine-base-install.sh b/assets/alpine-base-install.sh new file mode 100755 index 0000000..bdbe14c --- /dev/null +++ b/assets/alpine-base-install.sh @@ -0,0 +1,56 @@ +#!/bin/sh +set -eu + +# Install base tools, PHP requirements and dev-tools +apk --no-cache add -U \ + bash less vim geoip git tzdata zip curl jq autoconf \ + nginx nginx-mod-http-headers-more nginx-mod-http-geoip \ + nginx-mod-stream nginx-mod-stream-geoip ca-certificates \ + gnu-libiconv php-common mariadb-client sudo libjpeg libxml2 \ + build-base linux-headers freetype-dev zlib-dev libjpeg-turbo-dev \ + libpng-dev oniguruma-dev libzip-dev icu-dev libmcrypt-dev libxml2-dev + +# Configure php-fpm and nginx +/tmp/php-configuration.sh +rm -rf /var/log/php* /etc/php*/php-fpm.conf /etc/php*/php-fpm.d +mkdir -p /var/log/php /var/run/php /var/run/nginx +chown nginx:nginx /var/run/nginx +chown www-data:www-data /var/log/php /var/run/php + +# Install composer +curl -s https://getcomposer.org/installer | php +mv composer.phar /usr/bin/composer + +# Compute the short version (8.1.27 becomes 8.1) +PHP_SHORT_VERSION=$(echo "$PHP_VERSION" | cut -d '.' -f1-2) + +# Install phpunit +PHPUNIT_VERSION=$(jq -r '."'"${PHP_SHORT_VERSION}"'".phpunit' < /tmp/php-flavours.json) +wget -q -O /usr/bin/phpunit "https://phar.phpunit.de/phpunit-${PHPUNIT_VERSION}.phar" +chmod +x /usr/bin/phpunit + +# Install phpstan +PHPSTAN_VERSION=$(jq -r '."'"${PHP_SHORT_VERSION}"'".phpstan' < /tmp/php-flavours.json) +wget -q -O /usr/bin/phpstan "https://github.com/phpstan/phpstan/raw/${PHPSTAN_VERSION}/phpstan.phar" +chmod a+x /usr/bin/phpstan + +# Install php-cs-fixer +PHP_CS_FIXER=$(jq -r '."'"${PHP_SHORT_VERSION}"'".php_cs_fixer' < /tmp/php-flavours.json) +wget -q -O /usr/bin/php-cs-fixer "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/releases/download/${PHP_CS_FIXER}/php-cs-fixer.phar" +chmod a+x /usr/bin/php-cs-fixer + +# Install xdebug +PHP_XDEBUG=$(jq -r '."'"${PHP_SHORT_VERSION}"'".xdebug' < /tmp/php-flavours.json) +pecl install "xdebug-$PHP_XDEBUG" +docker-php-ext-enable xdebug + +# Install Node.js (shipping yarn and npm) and pnpm +if [ "0.0.0" != "$NODE_VERSION" ]; then + apk --no-cache add -U python3 nodejs npm yarn + npm install -g pnpm@latest +fi + +# Cleanup dev packages, keep libraries +apk --no-cache del -U build-base autoconf gcc g++ libgcc nginx-vim mariadb xz-dev musl-dev linux-headers freetype-dev zlib-dev libjpeg-turbo-dev libpng-dev oniguruma-dev libzip-dev icu-dev libmcrypt-dev libxml2-dev +apk --no-cache add -U mariadb-client freetype zlib libjpeg-turbo libpng oniguruma libzip icu libmcrypt libxml2 +rm -rf /var/cache/apk/* diff --git a/assets/debian-base-install.sh b/assets/debian-base-install.sh new file mode 100755 index 0000000..01454d5 --- /dev/null +++ b/assets/debian-base-install.sh @@ -0,0 +1,102 @@ +#!/bin/bash +set -eu + +# Disable man pages and documentation +tee -a /etc/dpkg/dpkg.cfg.d/01_nodoc << END +path-exclude=/usr/share/locale/* +path-exclude=/usr/share/man/* +path-exclude=/usr/share/doc/* +path-include=/usr/share/doc/*/copyright +END +rm -rf /usr/share/doc \ + /usr/share/man \ + /usr/share/locale + +# Get debian version and codename +# shellcheck disable=SC1091 +. /etc/os-release + +# Update certificates and install base deps +export DEBIAN_FRONTEND=noninteractive +curl -s -L -H "Content-Type: application/octet-stream" \ + --data-binary "@/etc/apt/trusted.gpg.d/php.gpg" \ + "https://packages.sury.org/php/apt.gpg" +apt-get update +apt-get install --no-install-recommends -qqy ca-certificates +apt-get install --no-install-recommends -o Dpkg::Options::="--force-confold" -qqy bash less vim git sudo mariadb-client \ + tzdata zip unzip curl wget make jq netcat-traditional build-essential \ + lsb-release libgnutls30 gnupg libiconv-hook1 libonig-dev nginx libnginx-mod-http-headers-more-filter libnginx-mod-http-geoip \ + libnginx-mod-http-geoip libnginx-mod-stream; +echo "deb [trusted=yes] https://packages.sury.org/php/ $VERSION_CODENAME main" > /etc/apt/sources.list.d/php.list +rm /etc/apt/preferences.d/no-debian-php +apt-get update +LIB_FREETYPE_DEV=$(apt-cache search '^libfreetype[0-9]+-dev$' | awk 'NR==1{print $1}') +LIB_XML_DEV=$(apt-cache search '^libxml[0-9]+-dev$' | awk 'NR==1{print $1}') +apt-get install --no-install-recommends -qqy \ + php-gd \ + "$LIB_FREETYPE_DEV" \ + zlib1g-dev \ + libjpeg-dev \ + libpng-dev \ + libzip-dev \ + libicu-dev \ + libmcrypt-dev \ + "$LIB_XML_DEV" + +# Configure php-fpm and nginx +/tmp/php-configuration.sh +rm -rf /var/log/php* /etc/php*/php-fpm.conf /etc/php*/php-fpm.d +mkdir -p /var/log/php /var/run/php /var/run/nginx +adduser --group nginx +adduser --system nginx +chown nginx:nginx /var/run/nginx +chown www-data:www-data /var/log/php /var/run/php + +# Install composer +curl -s https://getcomposer.org/installer | php \ + && mv composer.phar /usr/bin/composer + +# Compute the short version (8.1.27 becomes 8.1) +PHP_SHORT_VERSION=$(echo "$PHP_VERSION" | cut -d '.' -f1-2) + +# Install phpunit +PHPUNIT_VERSION=$(jq -r '."'"${PHP_SHORT_VERSION}"'".phpunit' < /tmp/php-flavours.json) +wget -q -O /usr/bin/phpunit "https://phar.phpunit.de/phpunit-${PHPUNIT_VERSION}.phar" +chmod +x /usr/bin/phpunit + +# Install phpstan +PHPSTAN_VERSION=$(jq -r '."'"${PHP_SHORT_VERSION}"'".phpstan' < /tmp/php-flavours.json) +wget -q -O /usr/bin/phpstan "https://github.com/phpstan/phpstan/raw/${PHPSTAN_VERSION}/phpstan.phar" +chmod a+x /usr/bin/phpstan + +# Install php-cs-fixer +PHP_CS_FIXER=$(jq -r '."'"${PHP_SHORT_VERSION}"'".php_cs_fixer' < /tmp/php-flavours.json) +wget -q -O /usr/bin/php-cs-fixer "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/releases/download/${PHP_CS_FIXER}/php-cs-fixer.phar" +chmod a+x /usr/bin/php-cs-fixer + +# Install xdebug +PHP_XDEBUG=$(jq -r '."'"${PHP_SHORT_VERSION}"'".xdebug' < /tmp/php-flavours.json) +pecl install "xdebug-${PHP_XDEBUG}" +docker-php-ext-enable xdebug + +# Install Node.js (shipping yarn and npm) and pnpm +if [ "0.0.0" != "$NODE_VERSION" ]; then + apt-get install --no-install-recommends -qqy nodejs python3 npm + npm install -g yarn@latest pnpm@latest --force +fi + +# Cleanup dev packages, keep libraries +apt-get clean +apt-get purge -qqy build-essential gcc g++ ghc "$LIB_FREETYPE_DEV" linux-libc-dev libncurses-dev \ + libghc-zlib-dev libjpeg-dev libpng-dev libzip-dev libicu-dev libmcrypt-dev "$LIB_XML_DEV" +apt-get autoremove -qqy + +LIB_FREETYPE=$(apt-cache search '^libfreetype[0-9]+$' | awk 'NR==1{print $1}') +LIB_JPEG=$(apt-cache search '^libjpeg[0-9-]+-turbo$' | awk 'NR==1{print $1}') +LIB_PNG=$(apt-cache search '^libpng[0-9-]+$' | awk 'NR==1{print $1}') +LIB_ZIP=$(apt-cache search '^libzip[0-9]+$' | awk 'NR==1{print $1}') +LIB_ICU=$(apt-cache search '^libicu[0-9]+$' | awk 'NR==1{print $1}') +LIB_MCRYPT=$(apt-cache search '^libmcrypt[0-9]+$' | awk 'NR==1{print $1}') +LIB_XML=$(apt-cache search '^libxml[0-9]+$' | awk 'NR==1{print $1}') +apt-get install -qqy "$LIB_FREETYPE" "$LIB_JPEG" "$LIB_PNG" "$LIB_ZIP" "$LIB_ICU" "$LIB_MCRYPT" "$LIB_XML" +rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/assets/hydrate.sh b/assets/hydrate.sh index 8b9e1d0..20be981 100755 --- a/assets/hydrate.sh +++ b/assets/hydrate.sh @@ -83,7 +83,7 @@ else fi # 10. Tear down mysql -killall --wait --quiet mysqld | true +killall mysqld | true # 11. Some clean up mv "${PS_FOLDER}/admin" "${PS_FOLDER}/${PS_FOLDER_ADMIN}" diff --git a/assets/php-configuration.sh b/assets/php-configuration.sh index 438df13..8b0e22e 100755 --- a/assets/php-configuration.sh +++ b/assets/php-configuration.sh @@ -36,11 +36,20 @@ else mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" rm -f "$PHP_INI_DIR/php.ini-production"; fi +pear config-set php_ini "$PHP_INI_DIR/php.ini" -# Flashlight is a testinf platform, keep things simple +# Flashlight is a testing platform, keep things simple sed -i 's/memory_limit = .*/memory_limit = -1/' "$PHP_INI_DIR/php.ini" sed -i 's/upload_max_filesize = .*/upload_max_filesize = 40M/' "$PHP_INI_DIR/php.ini" sed -i 's/post_max_size = .*/post_max_size = 40M/' "$PHP_INI_DIR/php.ini" +# Configure Xdebug +cat < "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" +[xdebug] +;xdebug.mode = debug +;xdebug.start_with_request = yes +;xdebug.discover_client_host = 1 +EOF + # Remove php assets that might have been installed by package unaware of $PHP_INI_DIR rm -rf /etc/php* /usr/lib/php* diff --git a/assets/run.sh b/assets/run.sh index c7cae36..459d235 100755 --- a/assets/run.sh +++ b/assets/run.sh @@ -1,22 +1,23 @@ #!/bin/sh set -eu -export DRY_RUN="${DRY_RUN:-false}" export DEBUG_MODE="${DEBUG_MODE:-false}" -export INIT_ON_RESTART="${INIT_ON_RESTART:-false}" +export DRY_RUN="${DRY_RUN:-false}" export DUMP_ON_RESTART="${DUMP_ON_RESTART:-false}" -export INSTALL_MODULES_ON_RESTART="${INSTALL_MODULES_ON_RESTART:-false}" +export INIT_ON_RESTART="${INIT_ON_RESTART:-false}" +export INIT_SCRIPTS_DIR="${INIT_SCRIPTS_DIR:-/tmp/init-scripts/}" export INIT_SCRIPTS_ON_RESTART="${INIT_SCRIPTS_ON_RESTART:-false}" -export POST_SCRIPTS_ON_RESTART="${POST_SCRIPTS_ON_RESTART:-false}" -export SSL_REDIRECT="${SSL_REDIRECT:-false}" -export PS_PROTOCOL="${PS_PROTOCOL:-http}" +export INIT_SCRIPTS_USER="${INIT_SCRIPTS_USER:-www-data}" +export INSTALL_MODULES_ON_RESTART="${INSTALL_MODULES_ON_RESTART:-false}" +export MYSQL_VERSION="${MYSQL_VERSION:-5.7}" export ON_INIT_SCRIPT_FAILURE="${ON_INIT_SCRIPT_FAILURE:-fail}" export ON_INSTALL_MODULES_FAILURE="${ON_INSTALL_MODULES_FAILURE:-fail}" -export MYSQL_VERSION="${MYSQL_VERSION:-5.7}" -export INIT_SCRIPTS_DIR="${INIT_SCRIPTS_DIR:-/tmp/init-scripts/}" export POST_SCRIPTS_DIR="${POST_SCRIPTS_DIR:-/tmp/post-scripts/}" -export INIT_SCRIPTS_USER="${INIT_SCRIPTS_USER:-www-data}" +export POST_SCRIPTS_ON_RESTART="${POST_SCRIPTS_ON_RESTART:-false}" export POST_SCRIPTS_USER="${POST_SCRIPTS_USER:-www-data}" +export PS_PROTOCOL="${PS_PROTOCOL:-http}" +export SSL_REDIRECT="${SSL_REDIRECT:-false}" +export XDEBUG_ENABLED="${XDEBUG_ENABLED:-false}" INIT_LOCK=/tmp/flashlight-init.lock DUMP_LOCK=/tmp/flashlight-dump.lock @@ -125,6 +126,12 @@ if [ ! -f $INIT_LOCK ] || [ "$INIT_ON_RESTART" = "true" ]; then sed -ie "s~define('_PS_MODE_DEV_', false);~define('_PS_MODE_DEV_',\ true);~g" "$PS_FOLDER/config/defines.inc.php" echo "* Debug mode set" fi + +# If Xdebug is enabled +if [ "$XDEBUG_ENABLED" = "true" ]; then + sed -ie 's~^;~~g' "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" + echo "* Xdebug enabled" + fi touch $INIT_LOCK else echo "* Init already performed (see INIT_ON_RESTART)" diff --git a/docker/alpine.Dockerfile b/docker/alpine.Dockerfile index 05ace2b..5f0e1b3 100644 --- a/docker/alpine.Dockerfile +++ b/docker/alpine.Dockerfile @@ -16,50 +16,14 @@ ENV PS_FOLDER=/var/www/html ENV PHP_INI_DIR=/usr/local/etc/php ENV COMPOSER_HOME=/var/composer -# Install base tools, PHP requirements and dev-tools ENV PHP_ENV=development -COPY ./assets/php-configuration.sh /tmp/ -RUN apk --no-cache add -U \ - bash less vim geoip git tzdata zip curl jq make \ - nginx nginx-mod-http-headers-more nginx-mod-http-geoip \ - nginx-mod-stream nginx-mod-stream-geoip ca-certificates \ - gnu-libiconv php-common mariadb-client sudo freetype-dev \ - zlib-dev libjpeg-turbo-dev libpng-dev oniguruma-dev \ - libzip-dev icu-dev libmcrypt-dev libxml2 libxml2-dev \ - && /tmp/php-configuration.sh - -# Configure php-fpm and nginx -RUN rm -rf /var/log/php* /etc/php*/php-fpm.conf /etc/php*/php-fpm.d \ - && mkdir -p /var/log/php /var/run/php /var/run/nginx \ - && chown nginx:nginx /var/run/nginx \ - && chown www-data:www-data /var/log/php /var/run/php COPY ./assets/php-fpm.conf /usr/local/etc/php-fpm.conf COPY ./assets/nginx.conf /etc/nginx/nginx.conf COPY ./php-flavours.json /tmp - -# Install composer -RUN curl -s https://getcomposer.org/installer | php \ - && mv composer.phar /usr/bin/composer - -# Install phpunit -RUN PHPUNIT_VERSION=$(jq -r '."'"${PHP_VERSION}"'".phpunit' < /tmp/php-flavours.json) \ - && wget -q -O /usr/bin/phpunit "https://phar.phpunit.de/phpunit-${PHPUNIT_VERSION}.phar" \ - && chmod +x /usr/bin/phpunit - -# Install phpstan -RUN PHPSTAN_VERSION=$(jq -r '."'"${PHP_VERSION}"'".phpstan' < /tmp/php-flavours.json) \ - && wget -q -O /usr/bin/phpstan "https://github.com/phpstan/phpstan/raw/${PHPSTAN_VERSION}/phpstan.phar" \ - && chmod a+x /usr/bin/phpstan - -# Install php-cs-fixer -RUN PHP_CS_FIXER=$(jq -r '."'"${PHP_VERSION}"'".php_cs_fixer' < /tmp/php-flavours.json) \ - && wget -q -O /usr/bin/php-cs-fixer "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/releases/download/${PHP_CS_FIXER}/php-cs-fixer.phar" \ - && chmod a+x /usr/bin/php-cs-fixer - -# Install Node.js and pnpm (yarn and npm are included) -RUN if [ "0.0.0" = "$NODE_VERSION" ]; then exit 0; fi \ - && apk --no-cache add -U python3 nodejs npm yarn \ - && npm install -g pnpm@latest +COPY ./assets/php-configuration.sh /tmp/ +COPY ./assets/alpine-base-install.sh /tmp/ +RUN /tmp/alpine-base-install.sh \ + && rm -f /tmp/alpine-base-install.sh /tmp/php-configuration.sh # -------------------------------- # Flashlight install and dump SQL @@ -85,8 +49,8 @@ RUN mkdir -p "$PS_FOLDER" /tmp/unzip-ps \ && rm -rf /tmp/prestashop.zip /tmp/unzip-ps # Install and configure MariaDB -RUN adduser --system mysql; \ - apk --no-cache add -U --no-commit-hooks --no-scripts mariadb; +RUN adduser --system mysql \ + && apk --no-cache add -U --no-commit-hooks --no-scripts mariadb; COPY ./assets/mariadb-server.cnf /etc/my.cnf.d/mariadb-server.cnf # Ship a VERSION file diff --git a/docker/debian.Dockerfile b/docker/debian.Dockerfile index 07c4ecc..8cae66f 100644 --- a/docker/debian.Dockerfile +++ b/docker/debian.Dockerfile @@ -15,81 +15,15 @@ ARG GIT_SHA ARG NODE_VERSION ENV PS_FOLDER=/var/www/html ENV COMPOSER_HOME=/var/composer - -# Update certificates and install base deps -RUN export DEBIAN_FRONTEND=noninteractive \ - && curl -s -L -H "Content-Type: application/octet-stream" --data-binary "@/etc/apt/trusted.gpg.d/php.gpg" "https://packages.sury.org/php/apt.gpg" \ - && apt-get update \ - && apt-get install --no-install-recommends -qqy ca-certificates \ - && apt-get install --no-install-recommends -qqy bash less vim git \ - tzdata zip unzip curl wget make jq netcat-traditional \ - lsb-release libgnutls30 gnupg libiconv-hook1 libonig-dev \ - nginx libnginx-mod-http-headers-more-filter libnginx-mod-http-geoip \ - libnginx-mod-http-geoip libnginx-mod-stream mariadb-client sudo \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* - -# PHP requirements and dev-tools ENV PHP_ENV=development -COPY ./assets/php-configuration.sh /tmp/ -RUN . /etc/os-release \ - && echo "deb [trusted=yes] https://packages.sury.org/php/ ${VERSION_CODENAME} main" > /etc/apt/sources.list.d/php.list \ - && rm /etc/apt/preferences.d/no-debian-php \ - && export DEBIAN_FRONTEND=noninteractive \ - && apt-get update \ - && apt-get install --no-install-recommends -qqy \ - php-gd \ - libfreetype-dev \ - libghc-zlib-dev \ - libjpeg-dev \ - libpng-dev \ - libzip-dev \ - libicu-dev \ - libmcrypt-dev \ - libxml2-dev \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* \ - && /tmp/php-configuration.sh - -# Configure php-fpm and nginx -RUN rm -rf /var/log/php* /etc/php*/php-fpm.conf /etc/php*/php-fpm.d \ - && mkdir -p /var/log/php /var/run/php /var/run/nginx \ - && adduser --group nginx \ - && adduser --system nginx \ - && chown nginx:nginx /var/run/nginx \ - && chown www-data:www-data /var/log/php /var/run/php COPY ./assets/php-fpm.conf /usr/local/etc/php-fpm.conf COPY ./assets/nginx.conf /etc/nginx/nginx.conf COPY ./php-flavours.json /tmp - -# Install composer -RUN curl -s https://getcomposer.org/installer | php \ - && mv composer.phar /usr/bin/composer - -# Install phpunit -RUN PHPUNIT_VERSION=$(jq -r '."'"${PHP_VERSION}"'".phpunit' < /tmp/php-flavours.json) \ - && wget -q -O /usr/bin/phpunit "https://phar.phpunit.de/phpunit-${PHPUNIT_VERSION}.phar" \ - && chmod +x /usr/bin/phpunit - -# Install phpstan -RUN PHPSTAN_VERSION=$(jq -r '."'"${PHP_VERSION}"'".phpstan' < /tmp/php-flavours.json) \ - && wget -q -O /usr/bin/phpstan "https://github.com/phpstan/phpstan/raw/${PHPSTAN_VERSION}/phpstan.phar" \ - && chmod a+x /usr/bin/phpstan - -# Install php-cs-fixer -RUN PHP_CS_FIXER=$(jq -r '."'"${PHP_VERSION}"'".php_cs_fixer' < /tmp/php-flavours.json) \ - && wget -q -O /usr/bin/php-cs-fixer "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/releases/download/${PHP_CS_FIXER}/php-cs-fixer.phar" \ - && chmod a+x /usr/bin/php-cs-fixer - -# Install Node.js and pnpm (yarn and npm are included) -RUN if [ "0.0.0" = "$NODE_VERSION" ]; then exit 0; fi \ - && export DEBIAN_FRONTEND=noninteractive \ - && apt-get update \ - && apt-get install --no-install-recommends -qqy nodejs python3 npm \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* \ - && npm install -g yarn@latest pnpm@latest --force +COPY ./assets/php-configuration.sh /tmp/ +COPY ./assets/debian-base-install.sh /tmp/ +RUN /tmp/debian-base-install.sh \ + && rm -f /tmp/debian-base-install.sh /tmp/php-configuration.sh # -------------------------------- # Flashlight install and dump SQL diff --git a/examples/xdebug-prestashop/README.md b/examples/xdebug-prestashop/README.md new file mode 100644 index 0000000..1b3a9ef --- /dev/null +++ b/examples/xdebug-prestashop/README.md @@ -0,0 +1,31 @@ +# XDEBUG PrestaShop + +You found a bug in PrestaShop? Want to track down a weird behavior? XDEBUG can help you, even within a docker environment. Here is an example to showcase the integration of this tool with PrestaShop Flashlight. + +# Requirements + +To enable XDEBUG capabilities within your favorite IDE, you have to mount the PrestaShop sources from your local host to the target PrestaShop Flashlight docker container. + +```sh +CONTAINER_NAME=flashlight-nightly +PS_FLASHLIGHT_TAG=nightly +docker create --name "$CONTAINER_NAME" "prestashop/prestashop-flashlight:$PS_FLASHLIGHT_TAG" +docker cp "$CONTAINER_NAME:/var/www/html" ./PrestaShop +docker rm "$CONTAINER_NAME" +``` + +Now you will have the exact copy of the `PS_FLASHLIGHT_TAG` prestashop source code copied locally. +You are now all set to start PrestaShop Flashlight with your local source binding: + +``` +docker compose up prestashop +``` + +# Usage + +@TODO: describe here some IDE configurations + +# External ressources + +- xdebug with VSCode: https://marketplace.visualstudio.com/items?itemName=xdebug.php-debug +- xdebug with PHPStorm: https://www.jetbrains.com/help/phpstorm/configuring-xdebug.html diff --git a/examples/xdebug-prestashop/docker-compose.yml b/examples/xdebug-prestashop/docker-compose.yml new file mode 100644 index 0000000..306448c --- /dev/null +++ b/examples/xdebug-prestashop/docker-compose.yml @@ -0,0 +1,39 @@ +name: flashlight-xdebug-prestashop +services: + prestashop: + image: prestashop/prestashop-flashlight:nightly + depends_on: + mysql: + condition: service_healthy + environment: + - PS_DOMAIN=localhost:8000 + - INIT_SCRIPTS_DIR=/tmp/init-scripts + - INIT_SCRIPTS_USER=root + - XDEBUG_ENABLED=true + volumes: + - ./PrestaShop:/var/www/html:rw + ports: + - 8000:80 + + mysql: + image: mariadb:lts + healthcheck: + test: + [ + "CMD", + "mysqladmin", + "ping", + "--host=localhost", + "--user=root", + "--password=prestashop", + ] + interval: 10s + timeout: 10s + retries: 5 + environment: + - MYSQL_HOST=mysql + - MYSQL_USER=prestashop + - MYSQL_PASSWORD=prestashop + - MYSQL_ROOT_PASSWORD=prestashop + - MYSQL_PORT=3306 + - MYSQL_DATABASE=prestashop diff --git a/php-flavours.json b/php-flavours.json index 009b5dc..bdf16bc 100644 --- a/php-flavours.json +++ b/php-flavours.json @@ -4,55 +4,63 @@ "debian": "7.1-fpm-buster", "php_cs_fixer": "v3.3.0", "phpstan": "1.4.10", - "phpunit": "7.5.20" + "phpunit": "7.5.20", + "xdebug": "2.9.8" }, "7.2": { "alpine": "7.2-fpm-alpine", "debian": "7.2-fpm-buster", "php_cs_fixer": "v3.4.0", "phpstan": "HEAD", - "phpunit": "8.5.34" + "phpunit": "8.5.34", + "xdebug": "3.1.6" }, "7.3": { "alpine": "7.3-fpm-alpine", "debian": "7.3-fpm-buster", "php_cs_fixer": "v3.4.0", "phpstan": "HEAD", - "phpunit": "9.6.13" + "phpunit": "9.6.13", + "xdebug": "3.1.6" }, "7.4": { "alpine": "7.4-fpm-alpine", "debian": "7.4-fpm-buster", "php_cs_fixer": "v3.40.0", "phpstan": "HEAD", - "phpunit": "9.6.13" + "phpunit": "9.6.13", + "xdebug": "3.1.6" }, "8.0": { "alpine": "8.0-fpm-alpine", "debian": "8.0-fpm-bullseye", "php_cs_fixer": "v3.40.0", "phpstan": "HEAD", - "phpunit": "9.6.13" + "phpunit": "9.6.13", + "xdebug": "3.3.1" }, "8.1": { "alpine": "8.1-fpm-alpine", "debian": "8.1-fpm-bookworm", "php_cs_fixer": "v3.40.0", "phpstan": "HEAD", - "phpunit": "10.4.2" + "phpunit": "10.4.2", + "xdebug": "3.3.1" }, "8.2": { "alpine": "8.2-fpm-alpine", "debian": "8.2-fpm-bookworm", "php_cs_fixer": "v3.40.0", "phpstan": "HEAD", - "phpunit": "10.4.2" + "phpunit": "10.4.2", + "xdebug": "3.3.1" }, "8.3": { "alpine": "8.3-fpm-alpine", "debian": "8.3-fpm-bookworm", "php_cs_fixer": "v3.40.0", "phpstan": "HEAD", - "phpunit": "10.4.2" + "phpunit": "10.4.2", + "xdebug": "3.3.1" } }