Skip to content

Instantly share code, notes, and snippets.

@zaverden
Created May 23, 2022 10:27
Show Gist options
  • Save zaverden/c9f1d26fba0114153fc48b1233ad8c30 to your computer and use it in GitHub Desktop.
Save zaverden/c9f1d26fba0114153fc48b1233ad8c30 to your computer and use it in GitHub Desktop.
# lint project
docker buildx build --target lint .
# build app image
docker buildx build --target app .
# build storybook image
docker buildx build --target storybook .
user nginx;
worker_processes ${WORKER_PROCESSES};
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
client_max_body_size 1024m;
keepalive_timeout 65;
server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
root /app;
index index.html;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
user nginx;
worker_processes ${WORKER_PROCESSES};
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
client_max_body_size 1024m;
keepalive_timeout 65;
server {
listen 80;
listen [::]:80;
server_name localhost;
location /_/plugins {
alias /app/plugins;
}
location / {
root /app/shell;
index index.html;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
###########################################################
FROM node:16.14.2-alpine as packages
WORKDIR /app
COPY package.json package-lock.json ./
# https://docs.npmjs.com/cli/v8/commands/npm-ci
RUN npm clean-install
###########################################################
FROM packages as packages-and-sources
COPY ./*.* ./
COPY ./apps ./apps
COPY ./libs ./libs
COPY ./shared-files ./shared-files
###########################################################
FROM packages-and-sources as lint
RUN --mount=type=cache,target=/app/node_modules/.cache,id=%project%-node_modules-cache \
node_modules/.bin/nx run-many --target=lint --all
###########################################################
FROM packages-and-sources as storybook-dist
COPY ./.storybook ./.storybook
RUN --mount=type=cache,target=/app/node_modules/.cache,id=%project%-node_modules-cache \
node_modules/.bin/nx run storybook:build-storybook:ci
###########################################################
FROM nginx:1.21-alpine as storybook
WORKDIR /app
COPY --from=storybook-dist /app/dist/storybook/storybook ./
COPY tools/jenkins/build/nginx-storybook.conf /etc/nginx/templates/nginx.conf.template
ENV \
NGINX_ENVSUBST_OUTPUT_DIR=/etc/nginx \
WORKER_PROCESSES=auto
###########################################################
FROM packages-and-sources as dist
RUN --mount=type=cache,target=/app/node_modules/.cache,id=%project%-node_modules-cache \
node_modules/.bin/nx run-many --target=build --all
###########################################################
FROM nginx:1.21-alpine as app
WORKDIR /app
COPY --from=dist /app/dist/apps/shell ./shell
COPY --from=dist /app/dist/apps/plugins ./plugins
COPY tools/jenkins/build/nginx.conf /etc/nginx/templates/nginx.conf.template
ENV \
NGINX_ENVSUBST_OUTPUT_DIR=/etc/nginx \
WORKER_PROCESSES=auto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment