Skip to content

Commit

Permalink
Refactor(docker): initial refactor of Docker setup
Browse files Browse the repository at this point in the history
  • Loading branch information
thePanz committed Mar 13, 2024
1 parent 146806f commit 7e35185
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 3 additions & 0 deletions .docker/php-config/10-symfony.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
display_error = On
error_reporting = E_ALL
memory_limit = 512M
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
compose.override.yaml

/test/functional/fixtures/cache
/test/functional/fixtures/log
/lib/plugins/sfDoctrinePlugin/test/functional/fixtures/lib/*/doctrine/base/
Expand Down
56 changes: 56 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions compose.override.example.yaml
Original file line number Diff line number Diff line change
@@ -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"
13 changes: 13 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7e35185

Please sign in to comment.