From 7e35185370740d21d9a35ad92b9b6b0ccff9b7b2 Mon Sep 17 00:00:00 2001 From: thePanz Date: Wed, 13 Mar 2024 21:09:55 +0100 Subject: [PATCH] Refactor(docker): initial refactor of Docker setup --- .docker/Dockerfile | 26 ++++++++++++++ .docker/php-config/10-symfony.ini | 3 ++ .gitignore | 2 ++ Justfile | 56 +++++++++++++++++++++++++++++++ compose.override.example.yaml | 9 +++++ compose.yaml | 13 +++++++ 6 files changed, 109 insertions(+) create mode 100644 .docker/Dockerfile create mode 100644 .docker/php-config/10-symfony.ini create mode 100644 Justfile create mode 100644 compose.override.example.yaml create mode 100644 compose.yaml diff --git a/.docker/Dockerfile b/.docker/Dockerfile new file mode 100644 index 000000000..19fdf67d8 --- /dev/null +++ b/.docker/Dockerfile @@ -0,0 +1,26 @@ +ARG PHP_VERSION +FROM php:${PHP_VERSION}-fpm-alpine + +COPY --from=composer:latest --link /usr/bin/composer /usr/local/bin/composer +COPY --from=phario/phive:0.15.2 --link /usr/local/bin/phive /usr/local/bin/phive +ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ + +# Install PHP extensions +RUN RUN set -eux; \ + install-php-extensions \ + apcu \ + memcache \ + pdo \ + pdo_mysql \ + zip \ + ; + +COPY --link php-config/*.ini /usr/local/etc/php/conf.d/ + +RUN RUN set -eux; \ + apk add file --no-cache; + +# Configure Composer folders +RUN RUN set -eux; \ + mkdir - /var/composer; \ + chmod a+rwX /var/composer; diff --git a/.docker/php-config/10-symfony.ini b/.docker/php-config/10-symfony.ini new file mode 100644 index 000000000..41da21032 --- /dev/null +++ b/.docker/php-config/10-symfony.ini @@ -0,0 +1,3 @@ +display_error = On +error_reporting = E_ALL +memory_limit = 512M diff --git a/.gitignore b/.gitignore index 3c17d4767..bb1a36d51 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +compose.override.yaml + /test/functional/fixtures/cache /test/functional/fixtures/log /lib/plugins/sfDoctrinePlugin/test/functional/fixtures/lib/*/doctrine/base/ diff --git a/Justfile b/Justfile new file mode 100644 index 000000000..f5fcf1003 --- /dev/null +++ b/Justfile @@ -0,0 +1,56 @@ +dockerCompose := "docker compose" +dockerExec := dockerCompose + " exec php" +defaultPhp := "7.4" + +default: + @just --list --justfile {{ justfile() }} + +# Build the docker image with the given PHP version +build version=defaultPhp *options="": + {{ dockerCompose }} build --build-arg=PHP_VERSION={{ version }} {{ options }} + +# Build the docker image (and pull new images) with the given PHP version +build-pull version=defaultPhp: (build version "--pull") + +# Build the docker image (and pull new images, with no docker cache) with the given PHP version +rebuild version=defaultPhp: (build version "--pull" "--no-cache") + +# Start the docker containers in detached mode (no logs) and waits for the dependencies to be up and running. +up: + {{ dockerCompose }} up --detach --wait + +# Start the docker containers and keep the daemon attached +up-foreground: + {{ dockerCompose }} up + +# Stop the running containers +down: + {{ dockerCompose }} down --remove-orphans + +# Display and follow the containers logs +logs: + {{ dockerCompose }} logs --follow + +# Get a terminal within the running PHP container +shell: + {{ dockerExec }} ash + +cs-check: (run-cs-fix "--dry-run") +cs-fix: run-cs-fix +[private] +run-cs-fix *options: + {{ dockerExec }} tools/php-cs-fixer.phar fix --verbose {{ options }} + +# Run the legacy Symfony1 tests on the currently running docker instance +tests-legacy: + {{ dockerExec }} php data/bin/symfony symfony:test --trace + +# Setup and initialize the project (docker image must be running) +setup: + git submodule update --checkout --recursive --force + {{ dockerExec }} composer update --optimize-autoloader + +# Cleanup the local code from vendor and composer.lock file +cleanup: + rm -fr vendor/ + rm -fr composer.lock diff --git a/compose.override.example.yaml b/compose.override.example.yaml new file mode 100644 index 000000000..52f5bb11e --- /dev/null +++ b/compose.override.example.yaml @@ -0,0 +1,9 @@ +services: + php: + # Use the following user withing the image, this should help with file permissions + user: 1000:1000 + volumes: + # Mount additional volumes from the host system to share Composer cache and authentication + - "${COMPOSER_CACHE_DIR:-${HOME}/.cache/composer}:/var/composer/cache:z" + - "${COMPOSER_HOME:-${HOME}/.composer}/auth.json:/var/composer/auth.json:ro,z" + - "${COMPOSER_HOME:-${HOME}/.composer}/config.json:/var/composer/config.json:ro,z" diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 000000000..84a2849b6 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,13 @@ +services: + + php: + environment: + COMPOSER_HOME: "/var/composer" + COMPOSER_CACHE_DIR: "/var/composer/cache" + build: + context: .docker/ + volumes: + - ".:/var/www/html:rw,z" + +# memcached: +# image: memcached:1.6.13-alpine3.15