Skip to content

Instantly share code, notes, and snippets.

@ebuildy
Created October 26, 2024 20:38
Show Gist options
  • Save ebuildy/0e93130ada2f0342982a720c06cbc704 to your computer and use it in GitHub Desktop.
Save ebuildy/0e93130ada2f0342982a720c06cbc704 to your computer and use it in GitHub Desktop.
Multi stage build
FROM dunglas/frankenphp:1-php8.3 AS php-base
RUN install-php-extensions .....
RUN useradd -D www-data
USER www-data
FROM php-base AS php-builder
COPY --from=composer:2.8.1 /usr/bin/composer /usr/bin/composer
WORKDIR /build
COPY composer.json ./
COPY composer.lock ./
RUN composer install --no-dev --no-interaction --optimize-autoloader --ignore-platform-reqs --no-scripts
COPY --chown=www-data:www-data . ./
RUN set -eux; \
ls -alh . ; \
composer dump-autoload --classmap-authoritative --no-dev; \
composer dump-env prod; \
COMPOSER_MEMORY_LIMIT=2G composer run-script --no-dev post-install-cmd; \
chmod +x bin/console; sync;
FROM node:20-alpine AS builder-node
WORKDIR /build
COPY package.json ./
COPY yarn.lock ./
RUN yarn install
COPY --from=php-builder /build .
RUN yarn build:prod
FROM php-base AS runner
WORKDIR /app
COPY --from=builder-php /build /app
COPY --from=builder-node /build/public /app/public
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment