From a4fd3dbeb6ec3cb15882ea11630d7d4f282b5eb6 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Tue, 31 Jan 2023 16:50:28 +0100 Subject: [PATCH 01/11] Upgrade chill_base_php image to PHP8: install deps and php extension --- Dockerfile | 138 ++++++++++++++++++++++++++++------------------------- 1 file changed, 74 insertions(+), 64 deletions(-) diff --git a/Dockerfile b/Dockerfile index 20e0c53..4f1e9c3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM php:7.4-fpm-buster AS chill_base_php +FROM php:8.2-fpm-alpine AS chill_base_php82 ENV POSTGRES_VERSION 14 @@ -6,73 +6,83 @@ ENV POSTGRES_VERSION 14 ARG UID=1000 ARG GID=1000 -RUN apt update && apt -y --no-install-recommends install wget gnupg \ - && wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \ - && echo "deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main" > /etc/apt/sources.list.d/pgdg.list \ - && apt update && apt -y --no-install-recommends install \ - libicu-dev \ - g++ \ - postgresql-server-dev-$POSTGRES_VERSION \ - libzip-dev libzip4 unzip \ - libfreetype6-dev \ - libonig-dev `# install oniguruma, required for mbstring` \ - libpng-dev \ - libjpeg62-turbo-dev \ - git \ - && docker-php-ext-configure gd --with-freetype --with-jpeg \ - && docker-php-ext-install -j$(nproc) gd \ - && docker-php-ext-install intl pdo_pgsql mbstring zip bcmath sockets exif \ - && pecl install redis \ - && docker-php-ext-enable redis \ - && apt remove -y wget libicu-dev g++ gnupg libzip-dev \ - && apt autoremove -y \ - && apt purge -y +# install php extensions and deps +RUN apk update && apk add --no-cache \ + wget gnupg \ + libpq-dev \ + icu-dev \ + oniguruma-dev \ + libzip-dev \ + linux-headers \ + gcc g++ make autoconf \ + bash git \ + && docker-php-ext-install pdo_pgsql intl mbstring zip bcmath exif sockets \ + && git clone https://github.com/nikic/php-ast.git \ + && cd php-ast \ + && phpize \ + && ./configure \ + && make install \ + && echo 'extension=ast.so' > /usr/local/etc/php/php.ini \ + && cd .. && rm -rf php-ast \ + && pecl install redis \ + && docker-php-ext-enable redis \ + && apk add libpng-dev libjpeg-turbo-dev freetype-dev \ + && docker-php-ext-configure gd --with-freetype --with-jpeg \ + && docker-php-ext-install -j$(nproc) gd \ + && apk del wget gnupg g++ icu-dev libzip-dev -RUN { \ - echo ""; \ - echo "memory_limit = 512M"; \ - echo ""; \ - } >> /usr/local/etc/php/conf.d/memory_limit.ini +RUN apk del oniguruma-dev linux-headers gcc make autoconf -RUN { \ - echo ""; \ - echo "[Date]"; \ - echo "date.timezone = Europe/Brussels"; \ - echo ""; \ - } >> /usr/local/etc/php/conf.d/date.ini +# "ERROR: Package cache is not enabled." \ +# https://github.com/gliderlabs/docker-alpine/issues/224 +#RUN apk cache clean -COPY --from=composer:2 /usr/bin/composer /usr/bin/composer -ENV COMPOSER_ALLOW_SUPERUSER=1 -ENV COMPOSER_MEMORY_LIMIT=-1 -WORKDIR /var/www/app - -CMD ["php-fpm"] - -FROM chill_base_php AS chill_php - -# copy directories - -COPY ./bin /var/www/app/bin/. -COPY ./composer.* /var/www/app/ -COPY ./config /var/www/app/config/. -COPY ./migrations /var/www/app/migrations/. -COPY ./public /var/www/app/public/. -COPY ./src /var/www/app/src/. -COPY ./templates /var/www/app/templates/. -COPY ./translations /var/www/app/translations/. -COPY ./vendor /var/www/app/vendor/. - -COPY ./.env /var/www/app/.env - -# import the manifest.json file -COPY ./public/build/manifest.json /var/www/app/public/build/manifest.json - -ADD ./entrypoint.sh /. - -RUN chmod +x /entrypoint.sh - -ENTRYPOINT ["/entrypoint.sh"] +#RUN { \ +# echo ""; \ +# echo "memory_limit = 512M"; \ +# echo ""; \ +# } >> /usr/local/etc/php/conf.d/memory_limit.ini +# +#RUN { \ +# echo ""; \ +# echo "[Date]"; \ +# echo "date.timezone = Europe/Brussels"; \ +# echo ""; \ +# } >> /usr/local/etc/php/conf.d/date.ini +# +#COPY --from=composer:2 /usr/bin/composer /usr/bin/composer +#ENV COMPOSER_ALLOW_SUPERUSER=1 +#ENV COMPOSER_MEMORY_LIMIT=-1 +# +#WORKDIR /var/www/app +# +#CMD ["php-fpm"] +# +#FROM chill_base_php82 AS chill_php82 +# +## copy directories +# +#COPY ./bin /var/www/app/bin/. +#COPY ./composer.* /var/www/app/ +#COPY ./config /var/www/app/config/. +#COPY ./migrations /var/www/app/migrations/. +#COPY ./public /var/www/app/public/. +#COPY ./src /var/www/app/src/. +#COPY ./templates /var/www/app/templates/. +#COPY ./translations /var/www/app/translations/. +#COPY ./vendor /var/www/app/vendor/. +# +#COPY ./.env /var/www/app/.env +# +## import the manifest.json file +#COPY ./public/build/manifest.json /var/www/app/public/build/manifest.json +# +#ADD ./entrypoint.sh /. +# +#RUN chmod +x /entrypoint.sh +# +#ENTRYPOINT ["/entrypoint.sh"] ENV PHP_FPM_USER=www-data \ PHP_FPM_GROUP=www-data \ From 23c438f0d7016d17c1319c625cdfe1e528dc6f36 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 1 Feb 2023 11:36:45 +0100 Subject: [PATCH 02/11] add postgresql-client --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 4f1e9c3..ccd2941 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,6 +31,8 @@ RUN apk update && apk add --no-cache \ && docker-php-ext-install -j$(nproc) gd \ && apk del wget gnupg g++ icu-dev libzip-dev +RUN apk add postgresql${POSTGRES_VERSION}-client + RUN apk del oniguruma-dev linux-headers gcc make autoconf # "ERROR: Package cache is not enabled." \ From 39b9e839c26650599627447b7eb42abe9b4b1142 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 1 Feb 2023 10:24:52 +0100 Subject: [PATCH 03/11] remove gd deps --- Dockerfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index ccd2941..3716eb6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,9 +26,6 @@ RUN apk update && apk add --no-cache \ && cd .. && rm -rf php-ast \ && pecl install redis \ && docker-php-ext-enable redis \ - && apk add libpng-dev libjpeg-turbo-dev freetype-dev \ - && docker-php-ext-configure gd --with-freetype --with-jpeg \ - && docker-php-ext-install -j$(nproc) gd \ && apk del wget gnupg g++ icu-dev libzip-dev RUN apk add postgresql${POSTGRES_VERSION}-client From 1a1188c612141e8556d5ed457d24da5cb3a19e8b Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 1 Feb 2023 11:51:27 +0100 Subject: [PATCH 04/11] merge deps RUN blocks to optimize --- Dockerfile | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3716eb6..be6c54c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,11 +26,8 @@ RUN apk update && apk add --no-cache \ && cd .. && rm -rf php-ast \ && pecl install redis \ && docker-php-ext-enable redis \ - && apk del wget gnupg g++ icu-dev libzip-dev - -RUN apk add postgresql${POSTGRES_VERSION}-client - -RUN apk del oniguruma-dev linux-headers gcc make autoconf + && apk add postgresql${POSTGRES_VERSION}-client \ + && apk del wget gnupg libpq-dev icu-dev oniguruma-dev libzip-dev linux-headers gcc g++ make autoconf # "ERROR: Package cache is not enabled." \ # https://github.com/gliderlabs/docker-alpine/issues/224 From b63a4f2a5f3f531238902863325cea374fdaba6b Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 1 Feb 2023 11:38:00 +0100 Subject: [PATCH 05/11] finish image --- Dockerfile | 91 ++++++++++++++++++++++++++---------------------------- 1 file changed, 43 insertions(+), 48 deletions(-) diff --git a/Dockerfile b/Dockerfile index be6c54c..1e2bb7b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,56 +29,51 @@ RUN apk update && apk add --no-cache \ && apk add postgresql${POSTGRES_VERSION}-client \ && apk del wget gnupg libpq-dev icu-dev oniguruma-dev libzip-dev linux-headers gcc g++ make autoconf -# "ERROR: Package cache is not enabled." \ -# https://github.com/gliderlabs/docker-alpine/issues/224 -#RUN apk cache clean +RUN { \ + echo ""; \ + echo "memory_limit = 512M"; \ + echo ""; \ + } >> /usr/local/etc/php/conf.d/memory_limit.ini +RUN { \ + echo ""; \ + echo "[Date]"; \ + echo "date.timezone = Europe/Brussels"; \ + echo ""; \ + } >> /usr/local/etc/php/conf.d/date.ini -#RUN { \ -# echo ""; \ -# echo "memory_limit = 512M"; \ -# echo ""; \ -# } >> /usr/local/etc/php/conf.d/memory_limit.ini -# -#RUN { \ -# echo ""; \ -# echo "[Date]"; \ -# echo "date.timezone = Europe/Brussels"; \ -# echo ""; \ -# } >> /usr/local/etc/php/conf.d/date.ini -# -#COPY --from=composer:2 /usr/bin/composer /usr/bin/composer -#ENV COMPOSER_ALLOW_SUPERUSER=1 -#ENV COMPOSER_MEMORY_LIMIT=-1 -# -#WORKDIR /var/www/app -# -#CMD ["php-fpm"] -# -#FROM chill_base_php82 AS chill_php82 -# -## copy directories -# -#COPY ./bin /var/www/app/bin/. -#COPY ./composer.* /var/www/app/ -#COPY ./config /var/www/app/config/. -#COPY ./migrations /var/www/app/migrations/. -#COPY ./public /var/www/app/public/. -#COPY ./src /var/www/app/src/. -#COPY ./templates /var/www/app/templates/. -#COPY ./translations /var/www/app/translations/. -#COPY ./vendor /var/www/app/vendor/. -# -#COPY ./.env /var/www/app/.env -# -## import the manifest.json file -#COPY ./public/build/manifest.json /var/www/app/public/build/manifest.json -# -#ADD ./entrypoint.sh /. -# -#RUN chmod +x /entrypoint.sh -# -#ENTRYPOINT ["/entrypoint.sh"] +COPY --from=composer:2 /usr/bin/composer /usr/bin/composer +ENV COMPOSER_ALLOW_SUPERUSER=1 +ENV COMPOSER_MEMORY_LIMIT=-1 + +WORKDIR /var/www/app + +CMD ["php-fpm"] + +FROM chill_base_php82 AS chill_php82 + +# copy directories + +COPY ./bin /var/www/app/bin/. +COPY ./composer.* /var/www/app/ +COPY ./config /var/www/app/config/. +COPY ./migrations /var/www/app/migrations/. +COPY ./public /var/www/app/public/. +COPY ./src /var/www/app/src/. +COPY ./templates /var/www/app/templates/. +COPY ./translations /var/www/app/translations/. +COPY ./vendor /var/www/app/vendor/. + +COPY ./.env /var/www/app/.env + +# import the manifest.json file +COPY ./public/build/manifest.json /var/www/app/public/build/manifest.json + +ADD ./entrypoint.sh /. + +RUN chmod +x /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] ENV PHP_FPM_USER=www-data \ PHP_FPM_GROUP=www-data \ From d38e9a5c0a52aaa415b1b146e5f87e589ce6a72c Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 1 Feb 2023 11:38:14 +0100 Subject: [PATCH 06/11] add shell preference --- Dockerfile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Dockerfile b/Dockerfile index 1e2bb7b..915cdc1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,6 +46,12 @@ COPY --from=composer:2 /usr/bin/composer /usr/bin/composer ENV COMPOSER_ALLOW_SUPERUSER=1 ENV COMPOSER_MEMORY_LIMIT=-1 +# shell bash preference +RUN sed -i " \ + s|root:x:0:0:root:/root:/bin/ash|root:x:0:0:root:/root:/bin/bash|g; \ + s|postgres:x:70:70:PostgreSQL user:/var/lib/postgresql:/bin/sh|postgres:x:70:70:PostgreSQL user:/var/lib/postgresql:/bin/bash|g" \ + /etc/passwd + WORKDIR /var/www/app CMD ["php-fpm"] From e9c478c0621ddfa63df3a2c0214a5f43c78fa719 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 1 Feb 2023 14:27:57 +0100 Subject: [PATCH 07/11] adapt Makefile and rename chill_php occurences by chill_php82 --- Makefile | 8 ++++---- docker-compose.dev.yml | 2 +- docker-compose.prod.yml | 2 +- docker-compose.yml | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 422cfe2..29b2764 100644 --- a/Makefile +++ b/Makefile @@ -2,12 +2,12 @@ THIS_FILE := $(lastword $(MAKEFILE_LIST)) PWD:=$(shell echo ${PWD}) UID:=$(shell id -u) GID:=$(shell id -g) -BASE_TAG=chill_base_php +BASE_TAG=chill_base_php82 DOCKERNODE_CMD=docker run --rm --user ${UID}:${GID} -v ${PWD}:/app --workdir /app -e YARN_CACHE_FOLDER=/app/.yarncache node:16 DOCKER_COMPOSE_PHP_EXEC_CMD=docker-compose run --rm --user $(UID):$(GID) -e CLEAR_CACHE=false -e COMPOSER_HOME=/var/www/app/.composer --entrypoint /usr/bin/env php DOCKER_PHP_EXEC_CMD_BASE=docker run --rm --user $(UID):$(GID) -v ${PWD}:/var/www/app -e CLEAR_CACHE=false -e COMPOSER_HOME=/var/www/app/.composer --entrypoint /usr/bin/env $(BASE_TAG) -PHP_BASE_IMAGE=php:7.4-fpm-buster -PHP_BASE_IMAGE_CHILL=chill_base_php +PHP_BASE_IMAGE=php:8.2-fpm-alpine +PHP_BASE_IMAGE_CHILL=chill_php82 NGINX_BASE_IMAGE=nginx CALVER=$(shell date "+v%Y%m%d%H%M")-${CALVERSION} ifneq (,$(wildcard ./.env)) @@ -39,7 +39,7 @@ build-assets: $(DOCKERNODE_CMD) yarn run encore production init: - docker build --target chill_base_php -t $(BASE_TAG) . + docker build --target $(PHP_BASE_IMAGE_CHILL) -t $(BASE_TAG) . $(DOCKER_PHP_EXEC_CMD_BASE) composer update --no-scripts --no-interaction @$(MAKE) -f $(THIS_FILE) build-assets @$(MAKE) -f $(THIS_FILE) post-install diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index d5376c8..f14b376 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -8,7 +8,7 @@ services: args: UID: ${PHP_FPM_USER:-1000} # uncomment and set your own image if needed - image: ${IMAGE_PHP-chill_php}:${VERSION:-latest} + image: ${IMAGE_PHP-chill_php82}:${VERSION:-latest} volumes: - .:/var/www/app environment: diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 063ddf1..f94950b 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -10,7 +10,7 @@ services: args: UID: ${PHP_FPM_USER:-1000} # uncomment and set your own image if needed - image: ${IMAGE_PHP-chill_php}:${VERSION:-latest} + image: ${IMAGE_PHP-chill_php82}:${VERSION:-latest} # # normally, you should not mount any volume and use your own image # diff --git a/docker-compose.yml b/docker-compose.yml index d4b8052..4f92940 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,7 @@ services: args: UID: ${PHP_FPM_USER:-1000} # uncomment and set your own image if needed - image: ${IMAGE_PHP:-chill_php}:${VERSION:-latest} + image: ${IMAGE_PHP:-chill_php82}:${VERSION:-latest} volumes: - .:/var/www/app environment: From fcd00855f9c21d4da5dbab185eaac2f986425239 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 1 Feb 2023 15:38:57 +0100 Subject: [PATCH 08/11] improve DockerFile deps to avoid errors with chill --- Dockerfile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 915cdc1..316573e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,9 +10,9 @@ ARG GID=1000 RUN apk update && apk add --no-cache \ wget gnupg \ libpq-dev \ - icu-dev \ + icu-dev icu-libs icu-data-full \ oniguruma-dev \ - libzip-dev \ + libzip libzip-dev \ linux-headers \ gcc g++ make autoconf \ bash git \ @@ -27,7 +27,7 @@ RUN apk update && apk add --no-cache \ && pecl install redis \ && docker-php-ext-enable redis \ && apk add postgresql${POSTGRES_VERSION}-client \ - && apk del wget gnupg libpq-dev icu-dev oniguruma-dev libzip-dev linux-headers gcc g++ make autoconf + && apk del --purge wget gnupg libpq-dev icu-dev oniguruma-dev libzip-dev linux-headers gcc g++ make autoconf RUN { \ echo ""; \ @@ -52,6 +52,9 @@ RUN sed -i " \ s|postgres:x:70:70:PostgreSQL user:/var/lib/postgresql:/bin/sh|postgres:x:70:70:PostgreSQL user:/var/lib/postgresql:/bin/bash|g" \ /etc/passwd +# chmod on redis.so +RUN chmod 755 -R /usr/local/lib/php/extensions/ + WORKDIR /var/www/app CMD ["php-fpm"] From 2af27e8b42e7052a35fffea3e695e082452705dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 3 Feb 2023 22:43:37 +0100 Subject: [PATCH 09/11] Feature: add php-cs-fixer to the base image Php-cs-fixer have conflicts with the symfony and doctrine version in use for us. I propose to add it to the image until php-cs-fixer becomes compatible again with our dependencies. This commit also add the environment variable PHP_CS_FIXER_IGNORE_ENV to make it works with php 8.2 (currently, it does not work with php > 8.1) --- Dockerfile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Dockerfile b/Dockerfile index 316573e..9e2c02e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,6 +42,13 @@ RUN { \ echo ""; \ } >> /usr/local/etc/php/conf.d/date.ini +# temporary fix, while php-cs-fixer has conflict dependencies +# with chill +RUN curl -o /usr/local/bin/php-cs-fixer https://cs.symfony.com/download/php-cs-fixer-v3.phar \ + && chmod +x /usr/local/bin/php-cs-fixer +# to make php-cs-fixer works with php 8.2 +ENV PHP_CS_FIXER_IGNORE_ENV=1 + COPY --from=composer:2 /usr/bin/composer /usr/bin/composer ENV COMPOSER_ALLOW_SUPERUSER=1 ENV COMPOSER_MEMORY_LIMIT=-1 From 2f18130e72fec818fa017ea043574053c13d4dbe Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 6 Feb 2023 09:54:51 +0100 Subject: [PATCH 10/11] Revert "remove gd deps" This reverts commit eb059453282539b899b3dbdce72cb970d5c28bff. --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index 9e2c02e..399348b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,6 +26,9 @@ RUN apk update && apk add --no-cache \ && cd .. && rm -rf php-ast \ && pecl install redis \ && docker-php-ext-enable redis \ + && apk add libpng-dev libjpeg-turbo-dev freetype-dev \ + && docker-php-ext-configure gd --with-freetype --with-jpeg \ + && docker-php-ext-install -j$(nproc) gd \ && apk add postgresql${POSTGRES_VERSION}-client \ && apk del --purge wget gnupg libpq-dev icu-dev oniguruma-dev libzip-dev linux-headers gcc g++ make autoconf From 78a98bff40b318c736b4b6c9b9ddf9ff6401fd3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 17 Feb 2023 13:26:14 +0100 Subject: [PATCH 11/11] Feature: publish base image --- .drone.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/.drone.yml b/.drone.yml index a3bf9ec..ec09a72 100644 --- a/.drone.yml +++ b/.drone.yml @@ -79,3 +79,36 @@ steps: Dockerfile: docker/nginx/Dockerfile depends_on: - build-assets + +--- + +kind: pipeline +type: docker +name: build-base-image-php82 + +trigger: + event: + - cron + - push + cron: + - base-image-php82 + +steps: + - name: build-base-image + image: plugins/docker + settings: + username: + from_secret: docker_username_gitea + password: + from_secret: docker_password_gitea + registry: gitea.champs-libres.be/chill-project/chill-skeleton-basic + repo: gitea.champs-libres.be/chill-project/chill-skeleton-basic/base-image + tag: php82 + target: chill_base_php82 + pull_image: true + +--- +kind: signature +hmac: 212da184e3fedeb03530cc66dbf9c8974e461e214dda5a698b11012e66e4531a + +...