Skip to content

Instantly share code, notes, and snippets.

@dkarlovi
Created December 7, 2021 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkarlovi/9c77b451019ce4a431e5bc1e8b3c2f9a to your computer and use it in GitHub Desktop.
Save dkarlovi/9c77b451019ce4a431e5bc1e8b3c2f9a to your computer and use it in GitHub Desktop.
Symfony + Encore in one Dockerfile
# syntax=docker/dockerfile:1.2
ARG BASE_DOCKER_IMAGE
ARG NODE_DOCKER_IMAGE
FROM ${NODE_DOCKER_IMAGE} AS node-builder
WORKDIR /app
COPY assets /app/assets
COPY package.json tsconfig.json webpack.config.js yarn.lock /app/
RUN --mount=type=cache,target=/yarn yarn install --frozen-lockfile --cache-dir=/yarn
RUN --mount=type=cache,target=/yarn yarn encore production
FROM ${BASE_DOCKER_IMAGE} AS runtime
WORKDIR /app
RUN adduser -u 82 -H -D -S -G www-data www-data && \
echo "http://nl.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \
apk add --update --no-cache \
'php8>=8.0.10' \
php8-ctype \
php8-curl \
php8-dom \
php8-fpm \
php8-iconv \
php8-intl \
php8-json \
php8-mbstring \
php8-opcache \
php8-pdo_pgsql \
php8-pecl-apcu \
php8-redis \
php8-session \
php8-simplexml \
php8-tokenizer \
php8-xml \
tini && \
ln -s /usr/bin/php8 /usr/bin/php
COPY ./.infra/docker/app/php-fpm.conf /etc/php8/php-fpm.d/www.conf
COPY ./.infra/docker/app/php.ini /etc/php8/conf.d/zzz_php.ini
FROM runtime AS installer
WORKDIR /app
RUN apk add --update --no-cache \
php8-cli \
php8-curl \
php8-openssl \
php8-phar \
php8-zip
COPY --from=composer/composer:2.1.6 /usr/bin/composer /usr/bin/composer
COPY composer.* /app/
RUN --mount=type=cache,target=/composer COMPOSER_HOME=/composer composer install --no-dev --no-interaction --no-scripts --no-suggest --prefer-dist
COPY . /app/
COPY --from=node-builder /app/public/assets/entrypoints.json /app/public/assets/manifest.json /app/public/assets/
RUN --mount=type=cache,target=/composer COMPOSER_HOME=/composer composer dump-autoload --classmap-authoritative
RUN APP_ENV=prod bin/console cache:warmup --no-interaction -vvv
FROM nginx:1.21.1-alpine AS web
WORKDIR /app
COPY public /app/public
COPY --from=node-builder /app/public/assets /app/public/assets
COPY ./.infra/docker/web/conf.d/* /etc/nginx/conf.d/
FROM runtime AS app
EXPOSE 9000
WORKDIR /app
COPY --from=installer /app/vendor /app/vendor
COPY --from=installer /app/public /app/public
COPY --from=installer /app/src /app/src
COPY --from=installer /app/templates /app/templates
COPY --from=installer /app/config /app/config
COPY --from=installer /app/migrations /app/migrations
COPY --from=installer /app/bin /app/bin
COPY --from=installer /app/var /app/var
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["/usr/sbin/php-fpm8", "--nodaemonize"]
FROM app AS app-debug
RUN apk add --update --no-cache \
php8-pecl-xdebug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment