Skip to content
Snippets Groups Projects
Commit 70e955ce authored by Dobromir Palushev's avatar Dobromir Palushev
Browse files

added a Dockerfile for the app

* app's frontend and backend are combined and served together from Node.js
parent 2bd9699b
No related branches found
No related tags found
No related merge requests found
client/node_modules
server/node_modules
.dockerignore
Dockerfile
ARG NODEJS_VERSION='16.17.0'
# ------------------------------------------------------------------
# Base container to be used in the next stages
FROM node:$NODEJS_VERSION-alpine AS base
ENV \
PORT=3002 \
# For local dev - mongodb://host.docker.internal:27017/todo-app
MONGODB_URL=<should-be-dynamically-set> \
JWT_SECRET=<should-be-dynamically-set>
# ------------------------------------------------------------------
# Test stage
FROM base AS test
# client tests
WORKDIR /client
COPY ./client .
RUN npm ci --no-audit --no-fund
RUN npm run test
# server tests
WORKDIR /server
COPY ./server/src ./src/
COPY ./server/package*.json .
RUN npm ci --no-audit --no-fund
# MONGODB_URL and JWT_SECRET are available as env variables
RUN npm run test
# ------------------------------------------------------------------
# Build stage
FROM base AS build
ARG APP_BUILD_PATH=/build
# server build
WORKDIR $APP_BUILD_PATH
COPY ./server/src .
COPY ./server/package*.json .
RUN \
npm ci --prod --no-audit --no-fund \
&& rm -rf ./package*
# client build
WORKDIR /client
COPY ./client .
RUN \
npm i --no-audit --no-fund \
&& \
BUILD_PATH=..$APP_BUILD_PATH/public \
npm run build
WORKDIR $APP_BUILD_PATH
# MONGODB_URL and JWT_SECRET should be available as env variables
CMD ["node", "./index.js"]
EXPOSE $PORT
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment