Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
env: Changed dev docker file and added proper one for production build.
  • Loading branch information
tarlepp committed Jul 16, 2019
1 parent afe0e63 commit f57fcf2
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Dockerfile
@@ -0,0 +1,34 @@
FROM composer:1.8.6 AS composer
FROM php:7.2.19-fpm

RUN apt-get update && apt-get install -y \
zlib1g-dev libxml2-dev nano vim git unzip jq \
&& rm -rf /var/lib/apt/lists/*

RUN docker-php-ext-install -j$(nproc) bcmath \
&& docker-php-ext-install pdo \
&& docker-php-ext-install pdo_mysql \
&& docker-php-ext-install zip

# copy the Composer PHAR from the Composer image into the PHP image
COPY --from=composer /usr/bin/composer /usr/bin/composer

ENV COMPOSER_ALLOW_SUPERUSER 1
ENV APP_ENV prod

WORKDIR /app

COPY . /app
COPY ./docker/php/php.ini /usr/local/etc/php/php.ini

RUN chmod +x /app/bin/console
RUN chmod +x /app/docker-entrypoint.sh
RUN chmod +x /usr/bin/composer

RUN rm -rf /app/var \
&& mkdir -p /app/var \
&& php -d memory_limit=-1 /usr/bin/composer install --no-dev --optimize-autoloader

EXPOSE 9000

ENTRYPOINT ["/app/docker-entrypoint.sh"]
1 change: 1 addition & 0 deletions Dockerfile_dev
Expand Up @@ -49,6 +49,7 @@ RUN chmod +x /app/bin/console \

# Allow to use more memory + add necessary stuff to bash autocomplete
RUN echo 'memory_limit = 2048M' >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini \
&& echo 'expose_php=off' >> /usr/local/etc/php/conf.d/docker-expose-php.ini \
&& echo 'source /usr/share/bash-completion/bash_completion' >> /etc/bash.bashrc \
&& echo 'eval "$(symfony-autocomplete --shell bash)"' >> /etc/bash.bashrc

Expand Down
45 changes: 45 additions & 0 deletions docker-entrypoint.sh
@@ -0,0 +1,45 @@
#!/bin/bash
set -e

#
# If we're starting web-server we need to do following:
# 1) Ensure that /app/var directory exists
# 2) Generate JWT encryption keys + allow web server to read this file
# 3) Clear and warmup caches on current environments
# 4) Create database if it not exists yet
# 5) Run possible migrations, so that database is always up to date
# 6) Install public assets
# 7) Copy _all_ files to shared folder so that Nginx use those properly
#
# Note that in production environment we cannot use `symfony` binary to wrap
# these commands because for some reason current environment variables from
# docker context won't be passed to php process.
#

if [ "$1" = 'php-fpm' ]; then
# Step 1
mkdir -p /app/var

# Step 2
make generate-jwt-keys
chmod 644 /app/config/jwt/private.pem

# Step 3
./bin/console cache:clear --no-ansi
./bin/console cache:warmup --no-ansi

# Step 4
./bin/console doctrine:database:create --if-not-exists --no-interaction --no-ansi

# Step 5
./bin/console doctrine:migrations:migrate --no-interaction --no-ansi

# Step 6
./bin/console assets:install --symlink --relative --no-interaction --no-ansi --env prod

# Step 7
chmod -R o+s+w /app
cp -bar /app /shared/app
fi

exec "$@"

0 comments on commit f57fcf2

Please sign in to comment.