Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor docker setup #339

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 20 additions & 62 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,68 +1,26 @@
ARG PHP_VERSION
FROM php:${PHP_VERSION}-cli
FROM php:${PHP_VERSION}-fpm-alpine

RUN docker-php-ext-install pdo
RUN docker-php-ext-install pdo_mysql
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 mbstring PHP extension
#
RUN set -eux; \
apt-get update; \
apt-get install -y --no-upgrade --no-install-recommends \
libonig-dev \
; \
\
apt-get clean; \
rm -rf /var/lib/apt/lists/*; \
\
docker-php-ext-install mbstring
# Install PHP extensions
RUN RUN set -eux; \
install-php-extensions \
apcu \
memcache \
pdo \
pdo_mysql \
zip \
;

# Install APCu PHP extension
#
ARG APCU_VERSION
RUN set -eux; \
\
test x"" = x"${APCU_VERSION}" || { \
pecl install apcu-${APCU_VERSION}; \
docker-php-ext-enable apcu; \
\
rm -r /tmp/pear; \
}
COPY --link --chmod=0644 php-config/*.ini /usr/local/etc/php/conf.d/

# Install memcache PHP extension
#
ARG MEMCACHE_VERSION
RUN set -eux; \
buildDeps=' \
libzip-dev \
'; \
apt-get update; \
apt-get install -y --no-upgrade --no-install-recommends \
$buildDeps \
; \
\
pecl install memcache-${MEMCACHE_VERSION}; \
docker-php-ext-enable memcache; \
\
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=true \
$buildDeps \
; \
apt-get clean; \
rm -rf /var/lib/apt/lists/*; \
rm -r /tmp/pear
RUN RUN set -eux; \
apk add file --no-cache;

# For consistent mime type file guesser
RUN set -eux; \
distFilePath=`which file`; \
\
mv ${distFilePath} ${distFilePath}.dist; \
{ \
echo '#! /bin/sh -eu'; \
echo ''; \
echo "${distFilePath}"'.dist "$@" | sed -e s,application/x-pie-executable,application/x-executable,g'; \
} | tee ${distFilePath}; \
\
chmod +x ${distFilePath}; \
\
file /bin/ls --mime | grep application/x-executable; \
:;
# Configure Composer folders
RUN RUN set -eux; \
mkdir /var/composer; \
chmod a+rwX /var/composer;
5 changes: 5 additions & 0 deletions .docker/php-config/10-symfony.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
display_error = on
error_reporting = E_ALL
memory_limit = 512M
short_open_tag = off
date.timezone = "UTC"
1 change: 1 addition & 0 deletions .docker/php-config/11-mysql-socket.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
; pdo_mysql.default_socket = /var/run/mysqld/mysql.sock'
4 changes: 3 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
.gitattributes export-ignore
.github/ export-ignore
.gitignore export-ignore
compose.yaml export-ignore
compose.override.yaml export-ignore
.php-cs-fixer.dist.php export-ignore
docker-compose.yml export-ignore
Justfile export-ignore
phpstan.neon export-ignore
phpunit.xml export-ignore
tests/ export-ignore
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.cache/

compose.override.yaml

/test/functional/fixtures/cache
/test/functional/fixtures/log
/lib/plugins/sfDoctrinePlugin/test/functional/fixtures/lib/*/doctrine/base/
Expand Down
60 changes: 60 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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

# Show the given PHP extensions's configuration from the running PHP container
php-ext-config extname:
{{ dockerExec }} php --ri {{ extname }}

# 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"
22 changes: 22 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
services:

php:
environment:
COMPOSER_HOME: "/var/composer"
COMPOSER_CACHE_DIR: "/var/composer/cache"
build:
context: .docker/
volumes:
- ".:/var/www/html:rw,z"
- "mysql_socket:/var/run/mysqld/mysqld.sock:rw"

# memcached:
# image: memcached:1.6.13-alpine3.15
mysql:
image: mysql:8.3
profiles:
- full
volumes:
- "mysql_socket:/var/run/mysqld/mysqld.sock:rw"
volumes:
mysql_socket:
92 changes: 0 additions & 92 deletions docker-compose.yml

This file was deleted.

2 changes: 1 addition & 1 deletion test/unit/validator/sfValidatorFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function getMimeTypesFromCategory($category)
$v = new testValidatorFile();
$t->is($v->guessFromFileBinary($tmpDir.'/test.txt'), 'text/plain', '->guessFromFileBinary() guesses the type of a given file');
$t->is($v->guessFromFileBinary($tmpDir.'/foo.txt'), null, '->guessFromFileBinary() returns null if the file type is not guessable');
$t->like($v->guessFromFileBinary('/bin/ls'), (PHP_OS != 'Darwin') ? '/^application\/x-(pie-executable|executable|sharedlib)$/' : '/^application/octet-stream$/', '->guessFromFileBinary() returns correct type if file is guessable');
$t->is($v->guessFromFileBinary(PHP_BINARY), 'application/x-pie-executable', '->guessFromFileBinary() returns correct type if file is guessable');
$t->is($v->guessFromFileBinary('-test'), null, '->guessFromFileBinary() returns null if file path has leading dash');

// ->getMimeType()
Expand Down