|
| 1 | +# ---it--- multi-stage build |
| 2 | + |
| 3 | +# ---------------------------------------------------------- |
| 4 | +# Node |
| 5 | +FROM node:14-alpine AS node-stage |
| 6 | +WORKDIR /app |
| 7 | +COPY package* ./ |
| 8 | +RUN npm install |
| 9 | +#RUN npm ci |
| 10 | +#COPY .docker-it/node ./.docker-it/node |
| 11 | +COPY assets ./assets |
| 12 | +#RUN npm run sass |
| 13 | +COPY Gruntfile.js ./ |
| 14 | +RUN npm run build |
| 15 | + |
| 16 | +# ---------------------------------------------------------- |
| 17 | +# PHP |
| 18 | +FROM php:7.3-fpm AS php-stage |
| 19 | + |
| 20 | +ARG BUILD_ENV=production |
| 21 | +ENV BUILD_ENV=$BUILD_ENV |
| 22 | + |
| 23 | +# Install git for composer, locales for intl extension |
| 24 | +RUN apt-get update && \ |
| 25 | + apt-get install -y git locales-all |
| 26 | + |
| 27 | +# Install project's required extensions (https://github.com/mlocati/docker-php-extension-installer) |
| 28 | +ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ |
| 29 | +RUN chmod +x /usr/local/bin/install-php-extensions && \ |
| 30 | + install-php-extensions gd intl mysqli imagick opcache zip redis |
| 31 | + |
| 32 | +RUN if [ "$BUILD_ENV" = "development" ] ; then install-php-extensions xdebug-^2 ; fi |
| 33 | + |
| 34 | +# php.ini development vs production |
| 35 | +RUN mv "$PHP_INI_DIR/php.ini-$BUILD_ENV" "$PHP_INI_DIR/php.ini" |
| 36 | +# + custom php.ini |
| 37 | +COPY .docker-it/php/conf.d/php.ini "$PHP_INI_DIR/conf.d/" |
| 38 | + |
| 39 | +# test ENV |
| 40 | +# https://vsupalov.com/docker-build-pass-environment-variables/ |
| 41 | +RUN if [ "$BUILD_ENV" = "development" ] ; then touch /_is_build_dev.txt ; else touch /_is_build_prod.txt ; fi |
| 42 | +RUN echo "BUILD_ENV is: $BUILD_ENV" >> /_BUILD_ENV.txt |
| 43 | + |
| 44 | +WORKDIR /var/www/html |
| 45 | + |
| 46 | +# Install and run composer |
| 47 | +# (according to composer image doc: "(optimal) create your own build image and install Composer inside it.") |
| 48 | +RUN install-php-extensions @composer-2 |
| 49 | +COPY composer.* ./ |
| 50 | +RUN composer install --no-interaction |
| 51 | + |
| 52 | +# Copy node built artifacts |
| 53 | +COPY --from=node-stage /app/assets ./assets |
| 54 | + |
| 55 | +# Copy source code |
| 56 | +COPY . . |
| 57 | + |
| 58 | +# Set rw permissions for www-data to logs folder |
| 59 | +RUN chown www-data:www-data application/logs |
| 60 | + |
| 61 | +# Set rw permissions for www-data to these mount points |
| 62 | +#RUN mkdir uploads && chown www-data:www-data uploads |
| 63 | +#RUN mkdir cache && chown www-data:www-data cache |
| 64 | + |
| 65 | +# ---------------------------------------------------------- |
| 66 | +# Nginx |
| 67 | +FROM nginx:1.25 AS nginx-stage |
| 68 | +COPY ./.docker-it/nginx/templates /etc/nginx/templates |
| 69 | +COPY --from=php-stage /var/www/html /var/www/html |
0 commit comments