-
-
Save malutanpetronel/9fce4fcde2c249efa20bae66222b4676 to your computer and use it in GitHub Desktop.
Example symfony and encore dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################### | |
# Generated on phpdocker.io # | |
############################################################################### | |
version: "3.4" | |
services: | |
redis: | |
image: redis:5-alpine | |
mailhog: | |
image: mailhog/mailhog:latest | |
ports: | |
- "12001:8025" | |
postgres: | |
image: postgres:9.6-alpine | |
working_dir: /application | |
volumes: | |
- .:/application | |
environment: | |
- POSTGRES_USER=user | |
- POSTGRES_PASSWORD=passwd | |
- POSTGRES_DB=dbname | |
webserver: | |
image: pagespeed/nginx-pagespeed:stable | |
working_dir: /application | |
volumes: | |
- .:/application | |
- ./infrastructure/nginx/nginx.conf:/etc/nginx/conf.d/default.conf | |
- ./infrastructure/local/:/etc/ssl/local/ | |
ports: | |
- "12000:443" | |
php-fpm: | |
build: | |
dockerfile: Dockerfile | |
target: backend-dev | |
context: . | |
working_dir: /application | |
volumes: | |
- .:/application | |
- ./infrastructure/php-fpm/php-ini-overrides.ini:/etc/php/7.3/fpm/conf.d/99-overrides.ini | |
frontend-builder: | |
image: node:10-alpine | |
working_dir: /application | |
volumes: | |
- .:/application | |
command: ['bin/frontend-builder.sh'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########### | |
# Backend # | |
########### | |
# Dev env base container | |
FROM phpdockerio/php73-fpm:latest AS backend-dev | |
WORKDIR "/application" | |
# Fix debconf warnings upon build | |
ARG DEBIAN_FRONTEND=noninteractive | |
# Install selected extensions and other stuff | |
RUN apt-get update \ | |
&& apt-get -y --no-install-recommends install \ | |
php7.3-pgsql \ | |
php-redis \ | |
jpegoptim \ | |
pngquant \ | |
gifsicle \ | |
php-imagick \ | |
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /var/log/* /var/cache/* /usr/share/doc/* | |
# Deployment container | |
FROM backend-dev AS backend-deployment | |
ENV APP_ENV=prod | |
ENV APP_SECRET="" | |
ENV DB_HOST="postgres" | |
ENV DB_NAME="foo" | |
ENV DB_USER="user" | |
ENV DB_PASSWORD="passwd" | |
ENV REDIS_HOST="redis" | |
ENV MAILER_TRANSPORT="" | |
ENV MAILER_HOST="" | |
ENV MAILER_PORT="" | |
ENV MAILER_USER="" | |
ENV MAILER_PASSWORD="" | |
ENV CONTACT_EMAIL_TO="" | |
ENV CONTACT_EMAIL_FROM="" | |
ENV CONTACT_EMAIL_SUBJECT="" | |
ENV GCLOUD_BUCKET="" | |
ENV GOOGLE_ANALYTICS="" | |
COPY bin/console /application/bin/ | |
COPY composer.* /application/ | |
RUN composer install --no-dev --no-scripts; \ | |
composer clear-cache | |
COPY infrastructure/php-fpm/php-ini-overrides.ini /etc/php/7.3/fpm/conf.d/z-overrides.ini | |
COPY infrastructure/php-fpm/opcache-prod.ini /etc/php/7.3/fpm/conf.d/z-opcache.ini | |
COPY infrastructure/php-fpm/php-fpm-pool-prod.conf /etc/php/7.3/fpm/pool.d/z-optimised.conf | |
COPY config ./config | |
COPY public/index.php ./public/ | |
COPY src ./src | |
COPY templates ./templates | |
COPY translations ./translations | |
RUN composer dump-autoload --optimize --classmap-authoritative; \ | |
bin/console cache:warmup; \ | |
chown www-data:www-data /tmp/site-cache /tmp/site-logs -Rf | |
############ | |
# Frontend # | |
############ | |
# Symfony bundle assets installer (needed to grab any bundle static assets later) | |
FROM backend-deployment AS backend-bundle-installer | |
RUN bin/console assets:install | |
# Frontend code builder | |
FROM node:10-alpine AS frontend-build | |
WORKDIR /application | |
COPY package.json yarn.lock ./ | |
RUN yarn install | |
COPY assets ./assets | |
COPY webpack* ./ | |
COPY public ./public | |
RUN mkdir -p ./build/public/assets; \ | |
yarn run encore production | |
## Actual deployable image | |
FROM pagespeed/nginx-pagespeed:stable AS frontend-deployment | |
WORKDIR /application | |
RUN mkdir ./public; \ | |
touch ./public/index.php | |
COPY infrastructure/nginx/nginx.conf /etc/nginx/conf.d/default.conf | |
# NGINX config: update php-fpm hostname to localhost (same pod in k8s), activate pagespeed config, deactivate SSL as termination is done elsewhere | |
RUN sed -i "s/php-fpm/localhost/g" /etc/nginx/conf.d/default.conf; \ | |
sed -i "s/# %DEPLOYMENT //g" /etc/nginx/conf.d/default.conf; \ | |
sed -i "s/listen 443/#listen 443/g" /etc/nginx/conf.d/default.conf; \ | |
sed -i "s/ssl_/#ssl_/g" /etc/nginx/conf.d/default.conf | |
COPY --from=backend-bundle-installer /application/public/bundles ./public/bundles | |
COPY --from=frontend-build /application/build/public/assets ./public/assets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ifndef BUILD_TAG | |
BUILD_TAG:=$(shell date +'%Y-%m-%d-%H-%M-%S')-$(shell git rev-parse --short HEAD) | |
endif | |
echo-build-tag: | |
echo $(BUILD_TAG) | |
start: | |
docker-compose up -d | |
stop: | |
docker-compose kill | |
build-images: | |
docker build --pull --target=backend-deployment -t site-php-fpm . | |
docker build --pull --target=frontend-deployment -t site-nginx . | |
tag-images: | |
docker tag site-nginx eu.gcr.io/xxxx/site-nginx:$(BUILD_TAG) | |
docker tag site-php-fpm eu.gcr.io/xxxx/site-php-fpm:$(BUILD_TAG) | |
push-images: | |
docker push eu.gcr.io/xxxx/site-nginx:$(BUILD_TAG) | |
docker push eu.gcr.io/xxxx/site-php-fpm:$(BUILD_TAG) | |
build-and-push: build-images tag-images push-images |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment