From e2e0eb848914041b0e6b0eceb24843129311536a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Birm=C3=A9?= Date: Tue, 26 Mar 2024 13:21:46 +0100 Subject: [PATCH] chore: base for running app as container --- .dockerignore | 4 ++++ Dockerfile | 31 +++++++++++++++++++++++++++++++ nginx/nginx.conf | 8 ++++++++ 3 files changed, 43 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 nginx/nginx.conf diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..0ab4cb4b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +node_modules +.git +**/__mocks__ +**/*.test.ts diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..5db2e931 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +FROM node:18-alpine AS base + +# Install dependencies only when needed +FROM base AS deps +# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. +# RUN apk add --no-cache libc6-compat g++ cmake tar make +WORKDIR /app + +# Install dependencies based on the preferred package manager +COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ +RUN yarn + +# Rebuild the source code only when needed +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . + +RUN yarn build + +# Production image, copy all the files and run next +FROM nginx:1.19.0 AS runner +WORKDIR /usr/share/nginx/html/app +RUN rm -rf ./* + +ENV NODE_ENV production + +COPY ./nginx/nginx.conf /etc/nginx/conf.d/default.conf +COPY --from=builder /app/dist . + +ENTRYPOINT [ "nginx", "-g", "daemon off;" ] \ No newline at end of file diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 00000000..01f7f797 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,8 @@ +server { + listen 8080; + server_name frontend; + location / { + root /usr/share/nginx/html/app; + index index.html; + } +}