Untitled

mail@pastecode.io avatar
unknown
dockerfile
2 years ago
3.0 kB
3
Indexable
Never
############
# Frontend #
############
FROM node:16.15.0-alpine3.15 as frontend

RUN apk add --update git vim

WORKDIR /app

COPY artisan package.json webpack.mix.js yarn.lock ./

RUN yarn install

COPY resources ./resources
COPY public ./public

ARG MIX_PUSHER_APP_KEY
RUN MIX_PUSHER_APP_KEY=$MIX_PUSHER_APP_KEY yarn production

#################
# Reverse-proxy #
#################
FROM nginx:1.21.6-alpine AS nginx

WORKDIR /var/www/html

COPY ./docker/nginx/vhost.conf /etc/nginx/conf.d/default.conf
COPY --from=frontend /app/public /var/www/html/

ARG GIT_COMMIT=unspecified
LABEL git_commit=$GIT_COMMIT

#
# PHP Dependencies
#
FROM lorisleiva/laravel-docker:7.4 as vendor

WORKDIR /app

COPY composer.json composer.lock ./

RUN composer install \
  --prefer-dist \
  # Disable ANSI output
  --no-ansi \
  # Do not ask any interactive question
  --no-interaction \
  # Removes the progress display that can mess with some terminals or scripts which don't handle backspace characters.
  --no-progress \
  # Skips execution of scripts defined in composer.json. 
  --no-scripts \
  # Convert PSR-0/4 autoloading to classmap to get a faster autoloader. This is recommended especially for production, but can take a bit of time to run so it is currently not done by default.
  # --optimize-autoloader \
  --no-autoloader \
  # Skip installing packages listed in require-dev. The autoloader generation skips the autoload-dev rules.
  # --no-dev \
  #ignore errors coming from composer.lock, cause no php or extensions installed on composer
  --ignore-platform-req=ext-mongodb --ignore-platform-req=ext-gd --ignore-platform-req=ext-exif 

COPY . .

RUN composer dump-autoload

###############
# Application #
###############
FROM php:7.4-fpm as application

WORKDIR /var/www/html

# Install PHP dependencies
#zlib-dev git vim $PHPIZE_DEPS 
RUN apt-get update -y && apt-get install -y \
  libxml2-dev \
  zlib1g-dev \
  libpng-dev \
  libzip-dev 

RUN docker-php-ext-install \
    pdo \
    pdo_mysql \
    opcache \
    tokenizer \
    xml \
    ctype \
    json \
    bcmath \
    pcntl \
    exif \
    gd \
    zip \
  # install
  && pecl install \
    apcu \
    mongodb \
    redis \
  # activate
  && docker-php-ext-enable \
    apcu \
    mongodb \
    redis

# Copy Frontend build
COPY --from=frontend /app/public/js/ ./public/js/
COPY --from=frontend /app/public/css/ ./public/css/
COPY --from=frontend /app/public/mix-manifest.json ./public/mix-manifest.json

# Copy Composer dependencies
COPY --from=vendor /app/vendor/ ./vendor/
COPY . .

# # If you need to update the autoloader because of new classes in a classmap package for example,
# # you can use dump-autoload to do that without having to go through an install or update.
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
RUN composer dump-autoload --optimize

RUN php artisan route:cache && php artisan event:cache && php artisan api:cache && php artisan view:cache

ARG GIT_COMMIT=unspecified
LABEL git_commit=$GIT_COMMIT