From bba4f8fba532679f0e46afb84d704f7d1d6b8ee0 Mon Sep 17 00:00:00 2001 From: Constantine Karnaukhov Date: Sun, 7 Feb 2021 01:33:42 +0400 Subject: [PATCH] feat: massive updates - update base image versions - use php8 as latest version - update Xdebug to v3 - provide both major versions of composer v1 and v2 with ability to switch between them --- .gitlab-ci.yml | 52 ++++++++++++++----- Dockerfile | 16 ++---- README.md | 8 +-- docs/configure.md | 3 +- spaceonfire/bin/entrypoint.sh | 70 +++++++++++++++----------- spaceonfire/bin/install.sh | 10 ++++ spaceonfire/bin/select-composer.sh | 15 ++++++ spaceonfire/composer/v1/bin/.gitignore | 2 + spaceonfire/composer/v2/bin/.gitignore | 2 + test/xdebug/docker-compose.yml | 3 +- 10 files changed, 122 insertions(+), 59 deletions(-) create mode 100644 spaceonfire/bin/select-composer.sh create mode 100644 spaceonfire/composer/v1/bin/.gitignore create mode 100644 spaceonfire/composer/v2/bin/.gitignore diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ece5ab5..ce69c90 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,10 +3,10 @@ stages: - latest variables: - PHP_7_2: 7.2.33 - PHP_7_3: 7.3.22 - PHP_7_4: 7.4.10 - PHP_8_0: 8.0-rc + PHP_8_0: 8.0.2 + PHP_7_4: 7.4.15 + PHP_7_3: 7.3.27 + PHP_7_2: 7.2.34 .build: stage: build @@ -34,6 +34,7 @@ build-next-7-2: DOCKER_IMAGE_TAG: next-7.2 PHP_BASEIMAGE_VERSION: $PHP_7_2 CACHE_FROM: $CI_REGISTRY_IMAGE:next-7.2 + PHP_EXTENSIONS: "dom exif gd iconv intl json mysqli opcache pdo_mysql pdo_sqlite soap xsl zip" only: - next @@ -43,6 +44,7 @@ build-master-7-2: DOCKER_IMAGE_TAG: latest-7.2 PHP_BASEIMAGE_VERSION: $PHP_7_2 CACHE_FROM: $CI_REGISTRY_IMAGE:latest-7.2 + PHP_EXTENSIONS: "dom exif gd iconv intl json mysqli opcache pdo_mysql pdo_sqlite soap xsl zip" only: - master @@ -52,6 +54,7 @@ build-tags-7-2: DOCKER_IMAGE_TAG: $CI_COMMIT_REF_NAME-7.2 PHP_BASEIMAGE_VERSION: $PHP_7_2 CACHE_FROM: $CI_REGISTRY_IMAGE:latest-7.2 + PHP_EXTENSIONS: "dom exif gd iconv intl json mysqli opcache pdo_mysql pdo_sqlite soap xsl zip" only: - tags @@ -64,6 +67,7 @@ build-next-7-3: DOCKER_IMAGE_TAG: next-7.3 PHP_BASEIMAGE_VERSION: $PHP_7_3 CACHE_FROM: $CI_REGISTRY_IMAGE:next-7.3 + PHP_EXTENSIONS: "dom exif gd iconv intl json mysqli opcache pdo_mysql pdo_sqlite soap xsl zip" only: - next @@ -73,6 +77,7 @@ build-master-7-3: DOCKER_IMAGE_TAG: latest-7.3 PHP_BASEIMAGE_VERSION: $PHP_7_3 CACHE_FROM: $CI_REGISTRY_IMAGE:latest-7.3 + PHP_EXTENSIONS: "dom exif gd iconv intl json mysqli opcache pdo_mysql pdo_sqlite soap xsl zip" only: - master @@ -82,6 +87,7 @@ build-tags-7-3: DOCKER_IMAGE_TAG: $CI_COMMIT_REF_NAME-7.3 PHP_BASEIMAGE_VERSION: $PHP_7_3 CACHE_FROM: $CI_REGISTRY_IMAGE:latest-7.3 + PHP_EXTENSIONS: "dom exif gd iconv intl json mysqli opcache pdo_mysql pdo_sqlite soap xsl zip" only: - tags @@ -94,6 +100,7 @@ build-next-7-4: DOCKER_IMAGE_TAG: next-7.4 PHP_BASEIMAGE_VERSION: $PHP_7_4 CACHE_FROM: $CI_REGISTRY_IMAGE:next-7.4 + PHP_EXTENSIONS: "dom exif gd iconv intl json mysqli opcache pdo_mysql pdo_sqlite soap xsl zip" only: - next @@ -103,6 +110,7 @@ build-master-7-4: DOCKER_IMAGE_TAG: latest-7.4 PHP_BASEIMAGE_VERSION: $PHP_7_4 CACHE_FROM: $CI_REGISTRY_IMAGE:latest-7.4 + PHP_EXTENSIONS: "dom exif gd iconv intl json mysqli opcache pdo_mysql pdo_sqlite soap xsl zip" only: - master @@ -112,6 +120,7 @@ build-tags-7-4: DOCKER_IMAGE_TAG: $CI_COMMIT_REF_NAME-7.4 PHP_BASEIMAGE_VERSION: $PHP_7_4 CACHE_FROM: $CI_REGISTRY_IMAGE:latest-7.4 + PHP_EXTENSIONS: "dom exif gd iconv intl json mysqli opcache pdo_mysql pdo_sqlite soap xsl zip" only: - tags @@ -121,14 +130,31 @@ build-tags-7-4: build-next-8-0: extends: .build variables: - DOCKER_IMAGE_TAG: next-8.0-rc + DOCKER_IMAGE_TAG: next-8.0 PHP_BASEIMAGE_VERSION: $PHP_8_0 XDEBUG_VERSION: master - PHP_EXTENSIONS: "dom exif gd iconv intl mysqli opcache pdo_mysql pdo_sqlite soap xsl zip" - CACHE_FROM: $CI_REGISTRY_IMAGE:next-8.0-rc + CACHE_FROM: $CI_REGISTRY_IMAGE:next-8.0 only: - next +build-master-8-0: + extends: .build + variables: + DOCKER_IMAGE_TAG: latest-8.0 + PHP_BASEIMAGE_VERSION: $PHP_8_0 + CACHE_FROM: $CI_REGISTRY_IMAGE:latest-8.0 + only: + - master + +build-tags-8-0: + extends: .build + variables: + DOCKER_IMAGE_TAG: $CI_COMMIT_REF_NAME-8.0 + PHP_BASEIMAGE_VERSION: $PHP_8_0 + CACHE_FROM: $CI_REGISTRY_IMAGE:latest-8.0 + only: + - tags + # Latest # ========================================= @@ -137,8 +163,8 @@ build-next-latest: stage: latest variables: DOCKER_IMAGE_TAG: next - PHP_BASEIMAGE_VERSION: $PHP_7_4 - CACHE_FROM: $CI_REGISTRY_IMAGE:next-7.4 + PHP_BASEIMAGE_VERSION: $PHP_8_0 + CACHE_FROM: $CI_REGISTRY_IMAGE:next-8.0 only: - next @@ -147,8 +173,8 @@ build-master-latest: stage: latest variables: DOCKER_IMAGE_TAG: latest - PHP_BASEIMAGE_VERSION: $PHP_7_4 - CACHE_FROM: $CI_REGISTRY_IMAGE:latest-7.4 + PHP_BASEIMAGE_VERSION: $PHP_8_0 + CACHE_FROM: $CI_REGISTRY_IMAGE:latest-8.0 only: - master @@ -157,7 +183,7 @@ build-tags-latest: stage: latest variables: DOCKER_IMAGE_TAG: $CI_COMMIT_REF_NAME - PHP_BASEIMAGE_VERSION: $PHP_7_4 - CACHE_FROM: $CI_REGISTRY_IMAGE:latest-7.4 + PHP_BASEIMAGE_VERSION: $PHP_8_0 + CACHE_FROM: $CI_REGISTRY_IMAGE:latest-8.0 only: - tags diff --git a/Dockerfile b/Dockerfile index b32dd6c..99f48b6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG PHP_BASEIMAGE_VERSION=7.4.10 +ARG PHP_BASEIMAGE_VERSION=8.0.2 FROM php:${PHP_BASEIMAGE_VERSION}-fpm-alpine LABEL maintainer="Constantine Karnaukhov " @@ -10,8 +10,8 @@ ENV \ # Fix for iconv: https://github.com/docker-library/php/issues/240 LD_PRELOAD="/usr/lib/preloadable_libiconv.so php" -ARG XDEBUG_VERSION=2.9.8 -ARG PHP_EXTENSIONS="dom exif gd iconv intl json mysqli opcache pdo_mysql pdo_sqlite soap xsl zip" +ARG XDEBUG_VERSION=3.0.2 +ARG PHP_EXTENSIONS="dom exif gd iconv intl mysqli opcache pdo_mysql pdo_sqlite soap xsl zip" # Install dependencies RUN apk add --update \ @@ -65,14 +65,7 @@ RUN apk add --update \ rm -rf /tmp/xdebug && \ docker-php-source delete && \ apk del gcc musl-dev linux-headers libffi-dev augeas-dev make autoconf && \ - rm -rf /var/cache/apk/* && \ - mkdir -p $COMPOSER_HOME && \ - EXPECTED_COMPOSER_SIGNATURE=$(wget -q -O - https://composer.github.io/installer.sig) && \ - php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \ - php -r "if (hash_file('SHA384', 'composer-setup.php') === '${EXPECTED_COMPOSER_SIGNATURE}') { echo 'Composer.phar Installer verified'; } else { echo 'Composer.phar Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \ - php composer-setup.php --install-dir=/usr/bin --filename=composer && \ - php -r "unlink('composer-setup.php');" && \ - composer global require hirak/prestissimo + rm -rf /var/cache/apk/* # tweak php-fpm config RUN echo "" > /usr/local/etc/php/conf.d/05-php.ini && \ @@ -116,6 +109,7 @@ RUN mkdir -p /etc/nginx && \ ln -s /etc/nginx/sites-available/default.conf /etc/nginx/sites-enabled/default.conf # Add spaceonfire +ENV PATH="${PATH}:${COMPOSER_HOME}/bin:${COMPOSER_HOME}/vendor/bin" COPY ./spaceonfire/ /opt/spaceonfire/ RUN chmod -R +x /opt/spaceonfire/bin/* && /opt/spaceonfire/bin/install.sh diff --git a/README.md b/README.md index 4a1a474..b4a6adc 100644 --- a/README.md +++ b/README.md @@ -21,10 +21,10 @@ Docker образ, основанный на Alpine Linux, с установле | Docker Tag | PHP Version | | ------------------------------------- | ----------- | -| `latest` / `latest-7.4` / `2.4.2-7.4` | 7.4.10 | -| `latest-7.3` / `2.4.2-7.3` | 7.3.22 | -| `latest-7.2` / `2.4.2-7.2` | 7.2.33 | -| `next-8.0-rc` | 8.0.0-rc | +| `latest` / `latest-8.0` / `2.5.0-8.0` | 8.0.2 | +| `latest-7.4` / `2.5.0-7.4` | 7.4.15 | +| `latest-7.3` / `2.5.0-7.3` | 7.3.27 | +| `latest-7.2` / `2.5.0-7.2` | 7.2.34 | ## Быстрый старт diff --git a/docs/configure.md b/docs/configure.md index d511152..af37a91 100644 --- a/docs/configure.md +++ b/docs/configure.md @@ -28,5 +28,6 @@ | `DOMAIN` | Укажите свой домен, чтобы добавить настройку RewriteDomain в конфиг ssmtp | | `SSMTP_DEFAULT_FROM` | Укажите email, с которого должная отправляться почта по-умолчанию | | `ENABLE_XDEBUG` | Укажите "1", включить расширение Xdebug | -| `XDEBUG_REMOTE_HOST` | Укажите свой IP адрес для `xdebug.remote_host`. [Подробнее про Xdebug](./xdebug.md) | +| `XDEBUG_REMOTE_HOST` | Укажите свой IP адрес для `xdebug.client_host`. [Подробнее про Xdebug](./xdebug.md) | | `XDEBUG_IDEKEY` | Укажите свой IDE key для `xdebug.idekey`. [Подробнее про Xdebug](./xdebug.md) | +| `COMPOSER_VERSION` | Выберите мажорную версию Composer (`v1` или `v2`, по-умолчанию `v1`) | diff --git a/spaceonfire/bin/entrypoint.sh b/spaceonfire/bin/entrypoint.sh index b50343c..479e803 100644 --- a/spaceonfire/bin/entrypoint.sh +++ b/spaceonfire/bin/entrypoint.sh @@ -1,14 +1,14 @@ #!/bin/bash # Set custom webroot -if [ ! -z "$WEBROOT" ]; then +if [ -n "$WEBROOT" ]; then sed -i "s#root /var/www/html;#root ${WEBROOT};#g" /etc/nginx/sites-available/default.conf else WEBROOT=/var/www/html fi # Recreate nginx user with passed UID and GID -if [ ! -z "$PUID" ]; then +if [ -n "$PUID" ]; then if [ -z "$PGID" ]; then PGID=${PUID} fi @@ -21,9 +21,17 @@ if [ ! -z "$PUID" ]; then fi # Setup access rights for nginx group -setfacl -RL -m g:nginx:rwx $COMPOSER_HOME >> /dev/null 2>&1 +{ + setfacl -RLm g:nginx:rwx "$COMPOSER_HOME" + setfacl -RLdm g:nginx:rwx "$COMPOSER_HOME" + setfacl -RLm g:nginx:rwx /opt/spaceonfire/composer/v1 + setfacl -RLdm g:nginx:rwx /opt/spaceonfire/composer/v1 + setfacl -RLm g:nginx:rwx /opt/spaceonfire/composer/v2 + setfacl -RLdm g:nginx:rwx /opt/spaceonfire/composer/v2 +} >>/dev/null 2>&1 + if [[ "$SKIP_SETFACL" != "1" ]]; then - setfacl -RL -m g:nginx:rwx /var/www/html/ >> /dev/null 2>&1 + setfacl -RLdm g:nginx:rwx /var/www/html/ >>/dev/null 2>&1 fi # Copy default index.html @@ -31,10 +39,14 @@ if [ $(ls $WEBROOT/index.{php,htm,html} 2>/dev/null | wc -l) -eq 0 ]; then cp -f /opt/spaceonfire/html/index.html $WEBROOT fi -if [ ! -z "$SOF_PRESET" ]; then +if [ -n "$SOF_PRESET" ]; then /opt/spaceonfire/bin/select-preset.sh $SOF_PRESET fi +if [ -n "$COMPOSER_VERSION" ]; then + /opt/spaceonfire/bin/select-composer.sh $COMPOSER_VERSION +fi + /opt/spaceonfire/bin/ssmtp-setup.php # Set Nginx read timeout @@ -42,13 +54,13 @@ if [[ -z "$NGINX_READ_TIMEOUT" ]] && [[ "$APPLICATION_ENV" != "production" ]]; t NGINX_READ_TIMEOUT=9999 fi -if [[ ! -z "$NGINX_READ_TIMEOUT" ]]; then +if [[ -n "$NGINX_READ_TIMEOUT" ]]; then FastCgiParamsFile="/etc/nginx/fastcgi_params" if ! grep -q fastcgi_read_timeout "$FastCgiParamsFile"; then { echo "" echo "fastcgi_read_timeout $NGINX_READ_TIMEOUT;" - } >> $FastCgiParamsFile + } >>$FastCgiParamsFile fi fi @@ -59,21 +71,21 @@ if [[ $lastlinephpconf == *"php_flag[display_errors]"* ]]; then fi # Display PHP error's or not -if [[ "$ERRORS" != "1" ]] ; then - echo "php_flag[display_errors] = off" >> /usr/local/etc/php-fpm.conf +if [[ "$ERRORS" != "1" ]]; then + echo "php_flag[display_errors] = off" >>/usr/local/etc/php-fpm.conf else - echo "php_flag[display_errors] = on" >> /usr/local/etc/php-fpm.conf + echo "php_flag[display_errors] = on" >>/usr/local/etc/php-fpm.conf fi # Display Version Details or not -if [[ "$HIDE_NGINX_HEADERS" == "0" ]] ; then +if [[ "$HIDE_NGINX_HEADERS" == "0" ]]; then sed -i "s/server_tokens off;/server_tokens on;/g" /etc/nginx/nginx.conf else sed -i "s/expose_php = On/expose_php = Off/g" /usr/local/etc/php-fpm.conf fi # Pass real-ip to logs when behind ELB, etc -if [[ "$REAL_IP_HEADER" == "1" ]] ; then +if [[ "$REAL_IP_HEADER" == "1" ]]; then vhosts=('/etc/nginx/sites-available/default.conf' '/etc/nginx/sites-available/default-ssl.conf') for vhost in vhosts; do sed -i "s/#real_ip_header X-Forwarded-For;/real_ip_header X-Forwarded-For;/" $vhost @@ -85,30 +97,30 @@ if [[ "$REAL_IP_HEADER" == "1" ]] ; then fi #Display errors in docker logs -if [ ! -z "$PHP_ERRORS_STDERR" ]; then - echo "log_errors = On" >> /usr/local/etc/php/conf.d/docker-vars.ini - echo "error_log = /dev/stderr" >> /usr/local/etc/php/conf.d/docker-vars.ini +if [ -n "$PHP_ERRORS_STDERR" ]; then + echo "log_errors = On" >>/usr/local/etc/php/conf.d/docker-vars.ini + echo "error_log = /dev/stderr" >>/usr/local/etc/php/conf.d/docker-vars.ini fi # Increase the memory_limit -if [ ! -z "$PHP_MEM_LIMIT" ]; then +if [ -n "$PHP_MEM_LIMIT" ]; then sed -i "s/memory_limit = 128M/memory_limit = ${PHP_MEM_LIMIT}M/g" /usr/local/etc/php/conf.d/docker-vars.ini fi # Increase the post_max_size -if [ ! -z "$PHP_POST_MAX_SIZE" ]; then +if [ -n "$PHP_POST_MAX_SIZE" ]; then sed -i "s/post_max_size = 100M/post_max_size = ${PHP_POST_MAX_SIZE}M/g" /usr/local/etc/php/conf.d/docker-vars.ini fi # Increase the upload_max_filesize -if [ ! -z "$PHP_UPLOAD_MAX_FILESIZE" ]; then +if [ -n "$PHP_UPLOAD_MAX_FILESIZE" ]; then sed -i "s/upload_max_filesize = 100M/upload_max_filesize= ${PHP_UPLOAD_MAX_FILESIZE}M/g" /usr/local/etc/php/conf.d/docker-vars.ini fi # Enable xdebug only if [ "$APPLICATION_ENV" != "production" ]; then XdebugFile='/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini' - if [[ "$ENABLE_XDEBUG" == "1" ]] ; then + if [[ "$ENABLE_XDEBUG" == "1" ]]; then if [ -f $XdebugFile ]; then echo "Xdebug enabled" else @@ -120,7 +132,7 @@ if [ "$APPLICATION_ENV" != "production" ]; then if [ -f $XdebugFile ]; then # Get default route ip if not set if [ -z "$XDEBUG_REMOTE_HOST" ]; then - XDEBUG_REMOTE_HOST=$(ip route|awk '/default/ { print $3 }') + XDEBUG_REMOTE_HOST=$(ip route | awk '/default/ { print $3 }') fi # See if file contains xdebug text. @@ -129,15 +141,14 @@ if [ "$APPLICATION_ENV" != "production" ]; then else { echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" - echo "xdebug.remote_enable=1" - echo "xdebug.remote_autostart=1" - echo "xdebug.remote_connect_back=0" - echo "xdebug.remote_host=${XDEBUG_REMOTE_HOST}" + echo "xdebug.mode=debug" + echo "xdebug.start_with_request=1" echo "xdebug.idekey=${XDEBUG_IDEKEY:-docker}" + echo "xdebug.client_host=${XDEBUG_REMOTE_HOST}" echo "xdebug.var_display_max_depth=-1" echo "xdebug.var_display_max_children=-1" echo "xdebug.var_display_max_data=-1" - } > $XdebugFile + } >$XdebugFile fi fi fi @@ -150,12 +161,13 @@ if [ "$APPLICATION_ENV" != "production" ]; then fi # Run custom scripts -if [[ "$RUN_SCRIPTS" == "1" ]] ; then +if [[ "$RUN_SCRIPTS" == "1" ]]; then if [ -d "/var/www/html/scripts/" ]; then - # make scripts executable incase they aren't - chmod -Rf 750 /var/www/html/scripts/*; sync; + # make scripts executable in case they aren't + chmod -Rf 750 /var/www/html/scripts/* + sync # run scripts in number order - for i in /var/www/html/scripts/*; do $i ; done + for i in /var/www/html/scripts/*; do $i; done else echo "Can't find script directory" fi diff --git a/spaceonfire/bin/install.sh b/spaceonfire/bin/install.sh index 0939a5c..76d5ab1 100644 --- a/spaceonfire/bin/install.sh +++ b/spaceonfire/bin/install.sh @@ -1,6 +1,16 @@ #!/bin/bash set -e +# Install composer +EXPECTED_COMPOSER_SIGNATURE=$(wget -q -O - https://composer.github.io/installer.sig) +wget -q -O /tmp/composer-setup.php https://getcomposer.org/installer +php -r "if (hash_file('SHA384', '/tmp/composer-setup.php') !== '${EXPECTED_COMPOSER_SIGNATURE}') { throw new Exception('Composer.phar Installer corrupt'); }" +COMPOSER_HOME=/opt/spaceonfire/composer/v1 php /tmp/composer-setup.php --1 --install-dir=/opt/spaceonfire/composer/v1/bin --filename=composer +COMPOSER_HOME=/opt/spaceonfire/composer/v2 php /tmp/composer-setup.php --2 --install-dir=/opt/spaceonfire/composer/v2/bin --filename=composer +rm -f /tmp/composer-setup.php +/opt/spaceonfire/bin/select-composer.sh v1 +composer global require hirak/prestissimo + # Copy default error pages for errorPage in /opt/spaceonfire/html/*.html; do filename=$(basename $errorPage) diff --git a/spaceonfire/bin/select-composer.sh b/spaceonfire/bin/select-composer.sh new file mode 100644 index 0000000..a0595d1 --- /dev/null +++ b/spaceonfire/bin/select-composer.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -e + +if [ "$COMPOSER_HOME" = "" ] && [ ! -L "$COMPOSER_HOME" ]; then + echo "COMPOSER_HOME not defined or not a link." + exit 1 +fi + +if [ ! -d "/opt/spaceonfire/composer/$1" ]; then + echo "Unknown composer version: $1. Try to use \"v1\" or \"v2\"" + exit 1 +fi + +rm -f "$COMPOSER_HOME" +ln -sf "/opt/spaceonfire/composer/$1" "$COMPOSER_HOME" diff --git a/spaceonfire/composer/v1/bin/.gitignore b/spaceonfire/composer/v1/bin/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/spaceonfire/composer/v1/bin/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/spaceonfire/composer/v2/bin/.gitignore b/spaceonfire/composer/v2/bin/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/spaceonfire/composer/v2/bin/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/test/xdebug/docker-compose.yml b/test/xdebug/docker-compose.yml index 307f537..7a27bce 100644 --- a/test/xdebug/docker-compose.yml +++ b/test/xdebug/docker-compose.yml @@ -5,7 +5,7 @@ services: build: ../../ image: spaceonfire/nginx-php-fpm:next ports: - - 8080:80 + - 8080:8080 environment: - SOF_PRESET=default - APPLICATION_ENV=development @@ -13,5 +13,6 @@ services: - XDEBUG_IDEKEY=testkey - PAGER=more - PUID=1000 + - COMPOSER_VERSION=v2 volumes: - ./:/var/www/html:Z