From 7d15bb21cd66f81fd346541016124c777b549a63 Mon Sep 17 00:00:00 2001 From: Piotr Dobrowolski Date: Fri, 8 Jan 2021 00:20:27 +0100 Subject: [PATCH] Cleanup Dockerfiles, fix front Docker image build --- back/Dockerfile | 6 +++--- front/Dockerfile | 44 +++++++++++++++++++++++++++++++----------- front/nginx-vhost.conf | 14 ++++++++++++++ pusher/Dockerfile | 6 +++--- 4 files changed, 53 insertions(+), 17 deletions(-) create mode 100644 front/nginx-vhost.conf diff --git a/back/Dockerfile b/back/Dockerfile index e95145cd..57840bbb 100644 --- a/back/Dockerfile +++ b/back/Dockerfile @@ -1,11 +1,11 @@ # protobuf build -FROM node:14.15.4-buster-slim@sha256:cbae886186467bbfd274b82a234a1cdfbbd31201c2a6ee63a6893eefcf3c6e76 as builder +FROM node:14-buster-slim as builder WORKDIR /usr/src COPY messages . RUN yarn install && yarn proto # typescript build -FROM node:14.15.4-buster-slim@sha256:cbae886186467bbfd274b82a234a1cdfbbd31201c2a6ee63a6893eefcf3c6e76 as builder2 +FROM node:14-buster-slim as builder2 WORKDIR /usr/src COPY back/yarn.lock back/package.json ./ RUN yarn install @@ -15,7 +15,7 @@ ENV NODE_ENV=production RUN yarn run tsc # final production image -FROM node:14.15.4-buster-slim@sha256:cbae886186467bbfd274b82a234a1cdfbbd31201c2a6ee63a6893eefcf3c6e76 +FROM node:14-buster-slim WORKDIR /usr/src COPY back/yarn.lock back/package.json ./ COPY --from=builder2 /usr/src/dist /usr/src/dist diff --git a/front/Dockerfile b/front/Dockerfile index b0d17877..cd02471e 100644 --- a/front/Dockerfile +++ b/front/Dockerfile @@ -1,16 +1,38 @@ -FROM thecodingmachine/workadventure-back-base:latest as builder -WORKDIR /var/www/messages -COPY --chown=docker:docker messages . +# protobuf build +FROM node:14-buster-slim as builder +WORKDIR /usr/src +COPY messages . RUN yarn install && yarn proto -# we are rebuilding on each deploy to cope with the API_URL environment URL -FROM thecodingmachine/nodejs:14-apache - -COPY --chown=docker:docker front . -COPY --from=builder --chown=docker:docker /var/www/messages/generated /var/www/html/src/Messages/generated +# webpack build +FROM node:14-buster-slim as builder2 +WORKDIR /usr/src +COPY front/yarn.lock front/package.json ./ RUN yarn install +COPY front . +COPY --from=builder /usr/src/generated src/Messages/generated ENV NODE_ENV=production -ENV STARTUP_COMMAND_0="./templater.sh" -ENV STARTUP_COMMAND_1="yarn run build" -ENV APACHE_DOCUMENT_ROOT=dist/ + +ARG ADMIN_URL=admin.$BASE_DOMAIN +ARG API_URL=pusher.$BASE_DOMAIN +ARG BASE_DOMAIN=workadventure.localhost +ARG JITSI_PRIVATE_MODE +ARG JITSI_URL +ARG START_ROOM_URL +ARG STUN_SERVER +ARG TURN_PASSWORD +ARG TURN_SERVER +ARG TURN_USER +ARG UPLOADER_URL=uploader.$BASE_DOMAIN + +RUN ./templater.sh +RUN API_URL=$API_URL UPLOADER_URL=$UPLOADER_URL ADMIN_URL=$ADMIN_URL START_ROOM_URL=$START_ROOM_URL \ + JITSI_URL=$JITSI_URL JITSI_PRIVATE_MODE=$JITSI_PRIVATE_MODE \ + STUN_SERVER=$STUN_SERVER TURN_SERVER=$TURN_SERVER TURN_USER=$TURN_USER TURN_PASSWORD=$TURN_PASSWORD \ + yarn run build + +# final production image +FROM nginx:mainline-alpine +COPY front/nginx-vhost.conf /etc/nginx/conf.d/default.conf +COPY --from=builder2 /usr/src/dist /usr/share/nginx/html diff --git a/front/nginx-vhost.conf b/front/nginx-vhost.conf new file mode 100644 index 00000000..81e10f4a --- /dev/null +++ b/front/nginx-vhost.conf @@ -0,0 +1,14 @@ +server { + listen 8000; + listen [::]:8000; + server_name localhost; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + } + + location ~ ^/[@_]/ { + try_files $uri $uri/ /index.html; + } +} diff --git a/pusher/Dockerfile b/pusher/Dockerfile index 4aec9748..bee98bfb 100644 --- a/pusher/Dockerfile +++ b/pusher/Dockerfile @@ -1,11 +1,11 @@ # protobuf build -FROM node:14.15.4-buster-slim@sha256:cbae886186467bbfd274b82a234a1cdfbbd31201c2a6ee63a6893eefcf3c6e76 as builder +FROM node:14-buster-slim as builder WORKDIR /usr/src COPY messages . RUN yarn install && yarn proto # typescript build -FROM node:14.15.4-buster-slim@sha256:cbae886186467bbfd274b82a234a1cdfbbd31201c2a6ee63a6893eefcf3c6e76 as builder2 +FROM node:14-buster-slim as builder2 WORKDIR /usr/src COPY pusher/yarn.lock pusher/package.json ./ RUN yarn install @@ -15,7 +15,7 @@ ENV NODE_ENV=production RUN yarn run tsc # final production image -FROM node:14.15.4-buster-slim@sha256:cbae886186467bbfd274b82a234a1cdfbbd31201c2a6ee63a6893eefcf3c6e76 +FROM node:14-buster-slim WORKDIR /usr/src COPY pusher/yarn.lock pusher/package.json ./ COPY --from=builder2 /usr/src/dist /usr/src/dist