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

a dockerfile & docker-compose #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
101 changes: 101 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
ARG PHP_VERSION=7.3

FROM php:${PHP_VERSION}-cli-alpine AS php

ARG GID=1000
ARG UID=1000
ARG APP_ENV=dev

# Prevent Symfony Flex from generating a project ID at build time
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No flex in this project, luckily :)

ARG SYMFONY_SKIP_REGISTRATION=1

ENV APP_ENV=${APP_ENV}
ENV APP_PATH=/var/www/app

RUN apk add --no-cache \
acl \
file \
gettext \
sqlite \
sqlite-dev \
unzip \
git \
bash \
;

ARG APCU_VERSION=5.1.12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be dropped

RUN set -eux; \
apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
icu-dev \
libzip-dev \
zlib-dev \
;

RUN docker-php-ext-configure zip --with-libzip; \
docker-php-ext-install -j$(nproc) \
intl \
pdo_sqlite \
zip \
; \
pecl install \
apcu-${APCU_VERSION} \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be dropped

; \
pecl clear-cache;
RUN docker-php-ext-enable \
apcu \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be dropped

opcache \
pdo_sqlite \
; \
\
runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhhh, what the heck is going on here? (generally unfamiliar with all this)

| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)"; \
apk add --no-cache --virtual .api-phpexts-rundeps $runDeps; \
\
apk del .build-deps


COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY docker/php.ini /usr/local/etc/php/php.ini

# Install Composer globally
ENV COMPOSER_ALLOW_SUPERUSER 1

RUN set -eux; \
composer global require "symfony/flex" --prefer-dist --no-progress --no-suggest --classmap-authoritative;
ENV PATH="${PATH}:/root/.composer/vendor/bin:./vendor/bin"

WORKDIR ${APP_PATH}

COPY composer.json composer.lock ./
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This project has no deployment/build target: having just the volume mounted, and composer install performed inside the container (with the mounted volume) would be preferable

# prevent the reinstallation of vendors at every changes in the source code
RUN set -eux; \
composer install --prefer-dist --no-autoloader --no-scripts --no-progress --no-suggest; \
composer clear-cache

COPY . ./
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to above: container should be configured for dev purposes only: all blocks performing ADD or COPY should probably be removed


RUN set -eux; \
mkdir -p var/cache var/log; \
composer dump-autoload --classmap-authoritative; \
composer run-script post-install-cmd;

RUN egrep -i ":$GID:" /etc/passwd &>/dev/null || addgroup -S --gid "$GID" appgroup
RUN egrep -i ":$UID:" /etc/passwd &>/dev/null || adduser -S appuser -G appgroup \
--uid "$UID" \
--disabled-password

RUN chown -R $UID:$GID ${APP_PATH}; \
chown -R $UID:$GID ${APP_PATH}/var; \
chmod +x bin/console; sync

#VOLUME ${APP_PATH}
USER $UID:$GID

EXPOSE 8080
CMD ["/var/www/app/run.sh"]

13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: "3.4"
services:
php:
#image: php:sflive
build:
context: .
ports:
- "7811:8080"
dns:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably to be dropped - host DNS resolution should suffice

- 10.240.0.100
- 10.240.0.200
volumes:
- ./:/var/www/app:rw,cached
14 changes: 14 additions & 0 deletions docker/php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[core]
date.timezone = UTC
session.auto_start = Off
short_open_tag = Off
realpath_cache_size = 4096K
realpath_cache_ttl = 600

[opcache]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opcache not really needed in the scope of this project

opcache.enable_file_override = On
opcache.interned_strings_buffer = 16
opcache.max_accelerated_files = 20000
opcache.memory_consumption = 256
#opcache.revalidate_freq = 2
opcache.validate_timestamps = On
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

php -S localhost:8080 -t public
php -S 0.0.0.0:8080 -t public