# # Multi-Stage Docker build: # Laravel 5.8 + PHP73 + Postgres || MySQL # # @link https://laravel.com/docs/5.8 # @link https://hub.docker.com/_/php # @link https://hub.docker.com/_/mysql # @link https://hub.docker.com/_/postgres # # # Stage 1 - Prep App's PHP Dependencies # FROM composer:1.8 as vendor COPY database/ database/ COPY composer.json composer.json COPY composer.lock composer.lock RUN composer install \ --ignore-platform-reqs \ --no-interaction \ --no-plugins \ --no-scripts \ --prefer-dist \ --quiet # end Stage 1 # # # Stage 2 - Prep App's Frontend CSS & JS # FROM node:10.15-jessie as frontend RUN mkdir -p /app/public COPY package.json webpack.mix.js yarn.lock /app/ COPY resources/assets/ /app/resources/assets/ COPY resources/js/ /app/resources/js/ COPY resources/sass/ /app/resources/sass/ WORKDIR /app RUN yarn install --silent \ && yarn production # end Stage 2 # # # Stage 3 - Build Final App # FROM php:7.3-fpm-alpine3.8 # write version information into container ARG SOURCE_COMMIT LABEL SOURCE_COMMIT="${SOURCE_COMMIT}" ENV SOURCE_COMMIT="${SOURCE_COMMIT}" ARG SOURCE_TAG LABEL SOURCE_TAG="${SOURCE_TAG}" ENV SOURCE_TAG="${SOURCE_TAG}" # add cli tools RUN apk update \ && apk upgrade \ && apk add bash \ && apk add nano \ && apk add nginx \ && apk add npm # silently install 'docker-php-ext-install' extensions RUN set -x # Database option: postgres RUN apk add --no-cache postgresql-dev RUN docker-php-ext-install pdo_pgsql bcmath > /dev/null # Database option: mysql # RUN docker-php-ext-install pdo_mysql bcmath > /dev/null # copy app source folder (less .dockerignore exclusions) COPY . /srv/app # add app dependencies from multi-stage builds COPY --from=vendor /app/vendor/ /srv/app/vendor/ COPY --from=frontend /app/public/js/ /srv/app/public/js/ COPY --from=frontend /app/public/css/ /srv/app/public/css/ COPY --from=frontend /app/public/fonts/ /srv/app/public/fonts/ COPY --from=frontend /app/public/mix-manifest.json /srv/app/public/mix-manifest.json # misc... WORKDIR /srv/app # nginx - nginx app permissions RUN mkdir -p /run/nginx RUN chown -R www-data:www-data * # nging - nginx permissions for laravel storage & cache RUN adduser nginx www-data \ && chgrp -R www-data storage bootstrap/cache \ && chmod -R 775 storage bootstrap/cache # nginx - config file COPY ./docker/nginx/default.conf /etc/nginx/conf.d/default.conf # cleanup apk RUN rm -rf /var/cache/apk/* # cleanup docker RUN rm -rf /srv/app/docker # bash alias for 'php artisan' RUN touch ~/.bashrc \ && echo 'source ~/.bash_profile' >> ~/.bashrc \ && echo 'alias art="php artisan"' >> ~/.bash_profile \ && echo 'alias watch="npm run watch &"' >> ~/.bash_profile ENV LOG_CHANNEL=stderr # docker entrypoint COPY ./docker/php73/entrypoint.sh /entrypoint.sh CMD ["/entrypoint.sh"] # end Stage 3 #