Skip to content

Commit

Permalink
Merge pull request #6 from stumpylog/main
Browse files Browse the repository at this point in the history
Feature: Use multi-stage building for Docker image
  • Loading branch information
BaldissaraMatheus authored Mar 12, 2023
2 parents a3b2ca9 + d8b5e97 commit 5654800
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,44 @@
FROM nginx:alpine
FROM node:18-alpine3.17 as build-stage

RUN set -eux \
&& mkdir -p /app \
&& mkdir -p /stylesheets \
&& mkdir -p /api \
&& mkdir -p /api/files

COPY frontend/ /app

WORKDIR /app
RUN set -eux \
&& npm ci \
&& npm run build

COPY backend/ /api/

WORKDIR /api
RUN set -eux \
&& npm ci

FROM nginx:alpine as final
ARG PUID=1000
ARG PGID=1000
ARG TITLE=""
ARG BASE_PATH=""
ENV VITE_TITLE $TITLE
ENV BASE_PATH $BASE_PATH
USER root
RUN mkdir -p /app
RUN mkdir -p /stylesheets
RUN mkdir -p /api
RUN mkdir -p /api/files
RUN apk add --update nodejs npm
COPY frontend/ /app/
RUN cd /app ; npm ci ; npm run build
RUN cp -R /app/dist/. /usr/share/nginx/html/
COPY backend/ /api/
RUN cd /api ; npm ci

RUN set -eux \
&& apk add --no-cache nodejs npm

COPY --from=build-stage --chown=$PUID:$PGID /app/dist/. /usr/share/nginx/html/
COPY --from=build-stage --chown=$PUID:$PGID /api/ /api/

COPY nginx.conf /etc/nginx/conf.d/
RUN [ $BASE_PATH != "" ] && { sed -i "s~BASE_PROXY~location BASE_PATH/ { proxy_pass http://localhost:8080/ }~g" /etc/nginx/conf.d/*.conf; } || { sed -i "s~BASE_PROXY~ ~g" /etc/nginx/conf.d/*.conf; }
RUN sed -i "s~BASE_PATH~${BASE_PATH}~g" /etc/nginx/conf.d/*.conf
RUN chown -R $PUID:$PGID /app/dist/stylesheets
RUN chown -R $PUID:$PGID /app/dist/stylesheets/color-themes
RUN chown -R $PUID:$PGID /api/files
VOLUME /api/files

VOLUME /api/files
VOLUME /usr/share/nginx/html/stylesheets/
WORKDIR /api
EXPOSE 8080
Expand Down

0 comments on commit 5654800

Please sign in to comment.