diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..f579acb1 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +**/node_modules/** +**/Dockerfile diff --git a/back/Dockerfile b/back/Dockerfile index 5ec83a8f..e95145cd 100644 --- a/back/Dockerfile +++ b/back/Dockerfile @@ -1,16 +1,26 @@ -FROM thecodingmachine/workadventure-back-base:latest as builder -WORKDIR /var/www/messages -COPY --chown=docker:docker messages . +# protobuf build +FROM node:14.15.4-buster-slim@sha256:cbae886186467bbfd274b82a234a1cdfbbd31201c2a6ee63a6893eefcf3c6e76 as builder +WORKDIR /usr/src +COPY messages . RUN yarn install && yarn proto -FROM thecodingmachine/nodejs:12 - -COPY --chown=docker:docker back . -COPY --from=builder --chown=docker:docker /var/www/messages/generated /usr/src/app/src/Messages/generated +# typescript build +FROM node:14.15.4-buster-slim@sha256:cbae886186467bbfd274b82a234a1cdfbbd31201c2a6ee63a6893eefcf3c6e76 as builder2 +WORKDIR /usr/src +COPY back/yarn.lock back/package.json ./ RUN yarn install - +COPY back . +COPY --from=builder /usr/src/generated src/Messages/generated ENV NODE_ENV=production RUN yarn run tsc -CMD ["yarn", "run", "runprod"] +# final production image +FROM node:14.15.4-buster-slim@sha256:cbae886186467bbfd274b82a234a1cdfbbd31201c2a6ee63a6893eefcf3c6e76 +WORKDIR /usr/src +COPY back/yarn.lock back/package.json ./ +COPY --from=builder2 /usr/src/dist /usr/src/dist +ENV NODE_ENV=production +RUN yarn install --production +USER node +CMD ["yarn", "run", "runprod"] diff --git a/docker-compose.prod.yaml b/docker-compose.prod.yaml new file mode 100644 index 00000000..1837d06b --- /dev/null +++ b/docker-compose.prod.yaml @@ -0,0 +1,62 @@ +version: "3" +services: + reverse-proxy: + image: traefik:v2.3.7 + command: + - --providers.docker + - --entryPoints.web.address=:80 + - --entryPoints.websecure.address=:443 + ports: + - "80:80" + - "443:443" + depends_on: + - back + - front + volumes: + - /var/run/docker.sock:/var/run/docker.sock + + front: + build: + context: . + dockerfile: front/Dockerfile + args: + BASE_DOMAIN: ${BASE_DOMAIN:-workadventure.localhost} + labels: + - "traefik.http.routers.front.rule=Host(`play.${BASE_DOMAIN:-workadventure.localhost}`)" + - "traefik.http.routers.front.entryPoints=web" + - "traefik.http.services.front.loadbalancer.server.port=8000" + - "traefik.http.routers.front-ssl.rule=Host(`play.${BASE_DOMAIN:-workadventure.localhost}`)" + - "traefik.http.routers.front-ssl.entryPoints=websecure" + - "traefik.http.routers.front-ssl.tls=true" + - "traefik.http.routers.front-ssl.service=front" + + back: + build: + context: . + dockerfile: back/Dockerfile + environment: + SECRET_KEY: yourSecretKey + SECRET_JITSI_KEY: "$SECRET_JITSI_KEY" + ADMIN_API_TOKEN: "$ADMIN_API_TOKEN" + JITSI_URL: $JITSI_URL + JITSI_ISS: $JITSI_ISS + + pusher: + build: + context: . + dockerfile: pusher/Dockerfile + environment: + SECRET_KEY: yourSecretKey + SECRET_JITSI_KEY: "$SECRET_JITSI_KEY" + ADMIN_API_TOKEN: "$ADMIN_API_TOKEN" + API_URL: back:50051 + JITSI_URL: $JITSI_URL + JITSI_ISS: $JITSI_ISS + labels: + - "traefik.http.routers.pusher.rule=Host(`pusher.${BASE_DOMAIN:-workadventure.localhost}`)" + - "traefik.http.routers.pusher.entryPoints=web" + - "traefik.http.services.pusher.loadbalancer.server.port=8080" + - "traefik.http.routers.pusher-ssl.rule=Host(`pusher.${BASE_DOMAIN:-workadventure.localhost}`)" + - "traefik.http.routers.pusher-ssl.entryPoints=websecure" + - "traefik.http.routers.pusher-ssl.tls=true" + - "traefik.http.routers.pusher-ssl.service=pusher" diff --git a/front/Dockerfile b/front/Dockerfile index 6c79ad6e..ab44ea45 100644 --- a/front/Dockerfile +++ b/front/Dockerfile @@ -1,15 +1,28 @@ -FROM thecodingmachine/workadventure-back-base:latest as builder -WORKDIR /var/www/messages -COPY --chown=docker:docker messages . +# protobuf build +FROM node:14.15.4-buster-slim@sha256:cbae886186467bbfd274b82a234a1cdfbbd31201c2a6ee63a6893eefcf3c6e76 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.15.4-buster-slim@sha256:cbae886186467bbfd274b82a234a1cdfbbd31201c2a6ee63a6893eefcf3c6e76 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_1="yarn run build" -ENV APACHE_DOCUMENT_ROOT=dist/ + +ARG BASE_DOMAIN=workadventure.localhost +ARG API_URL=pusher.$BASE_DOMAIN +ARG UPLOADER_URL=uploader.$BASE_DOMAIN +ARG ADMIN_URL=admin.$BASE_DOMAIN + +RUN API_URL=$API_URL UPLOADER_URL=$UPLOADER_URL ADMIN_URL=$ADMIN_URL \ + yarn run build + +# final production image +FROM nginx:1.19.6-alpine@sha256:01747306a7247dbe928db991eab42e4002118bf636dd85b4ffea05dd907e5b66 +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/maps/.dockerignore b/maps/.dockerignore new file mode 100644 index 00000000..64d1025d --- /dev/null +++ b/maps/.dockerignore @@ -0,0 +1,4 @@ +/node_modules/ +/dist/bundle.js +/yarn-error.log +/Dockerfile diff --git a/messages/.dockerignore b/messages/.dockerignore new file mode 100644 index 00000000..64d1025d --- /dev/null +++ b/messages/.dockerignore @@ -0,0 +1,4 @@ +/node_modules/ +/dist/bundle.js +/yarn-error.log +/Dockerfile diff --git a/pusher/Dockerfile b/pusher/Dockerfile index 42de3883..4aec9748 100644 --- a/pusher/Dockerfile +++ b/pusher/Dockerfile @@ -1,15 +1,26 @@ -FROM thecodingmachine/workadventure-back-base:latest as builder -WORKDIR /var/www/messages -COPY --chown=docker:docker messages . +# protobuf build +FROM node:14.15.4-buster-slim@sha256:cbae886186467bbfd274b82a234a1cdfbbd31201c2a6ee63a6893eefcf3c6e76 as builder +WORKDIR /usr/src +COPY messages . RUN yarn install && yarn proto -FROM thecodingmachine/nodejs:12 - -COPY --chown=docker:docker pusher . -COPY --from=builder --chown=docker:docker /var/www/messages/generated /usr/src/app/src/Messages/generated +# typescript build +FROM node:14.15.4-buster-slim@sha256:cbae886186467bbfd274b82a234a1cdfbbd31201c2a6ee63a6893eefcf3c6e76 as builder2 +WORKDIR /usr/src +COPY pusher/yarn.lock pusher/package.json ./ RUN yarn install - +COPY pusher . +COPY --from=builder /usr/src/generated src/Messages/generated ENV NODE_ENV=production RUN yarn run tsc +# final production image +FROM node:14.15.4-buster-slim@sha256:cbae886186467bbfd274b82a234a1cdfbbd31201c2a6ee63a6893eefcf3c6e76 +WORKDIR /usr/src +COPY pusher/yarn.lock pusher/package.json ./ +COPY --from=builder2 /usr/src/dist /usr/src/dist +ENV NODE_ENV=production +RUN yarn install --production + +USER node CMD ["yarn", "run", "runprod"] diff --git a/pusher/Dockerfile.prod b/pusher/Dockerfile.prod new file mode 100644 index 00000000..772532f0 --- /dev/null +++ b/pusher/Dockerfile.prod @@ -0,0 +1,17 @@ +FROM node:12.19.0-slim + +RUN mkdir -p /home/node/app && chown -R node:node /home/node/app +WORKDIR /home/node/app + +USER node +ENV NODE_ENV=production +ENV DEBUG=* + +COPY --chown=node:node package.json yarn.lock ./ + +RUN yarn install --prod --frozen-lockfile + +COPY --chown=node:node ./dist/ ./dist/ + +EXPOSE 8080 +CMD ["yarn", "run", "runprod"] diff --git a/uploader/Dockerfile b/uploader/Dockerfile index 3c471f6c..e4366308 100644 --- a/uploader/Dockerfile +++ b/uploader/Dockerfile @@ -1,9 +1,19 @@ -FROM thecodingmachine/nodejs:12 - -COPY --chown=docker:docker uploader . +# typescript build +FROM node:14.15.4-buster-slim@sha256:cbae886186467bbfd274b82a234a1cdfbbd31201c2a6ee63a6893eefcf3c6e76 as builder2 +WORKDIR /usr/src +COPY uploader/yarn.lock uploader/package.json ./ RUN yarn install - +COPY uploader . ENV NODE_ENV=production RUN yarn run tsc +# final production image +FROM node:14.15.4-buster-slim@sha256:cbae886186467bbfd274b82a234a1cdfbbd31201c2a6ee63a6893eefcf3c6e76 +WORKDIR /usr/src +COPY uploader/yarn.lock uploader/package.json ./ +COPY --from=builder2 /usr/src/dist /usr/src/dist +ENV NODE_ENV=production +RUN yarn install --production + +USER node CMD ["yarn", "run", "runprod"] diff --git a/website/.dockerignore b/website/.dockerignore new file mode 100644 index 00000000..576c21a2 --- /dev/null +++ b/website/.dockerignore @@ -0,0 +1,5 @@ +/dist/ +/node_modules/ +/dist/bundle.js +/yarn-error.log +/Dockerfile