-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
97 lines (63 loc) · 2.32 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# syntax=docker/dockerfile:1
# Tell the BuildKit image builder in Docker to use Dockerfile frontend for support of new features
FROM node:20.8.0-bullseye-slim AS development
# Set working directory
WORKDIR /app
# Copy package.json and package-lock.json to container
COPY package.json /app/package.json
COPY package-lock.json /app/package-lock.json
# Same as npm install
RUN npm ci && npm cache clean --force
# Copy the source code directories and .nginx/nginx.conf to main container's directory
COPY src /app/src
COPY public /app/public
COPY .nginx/nginx.conf /app/.nginx/nginx.conf
# Set environment variables inside the container
ENV CI=true
ENV PORT=3000
CMD [ "npm", "start" ]
FROM development AS build
RUN npm run build
FROM development as dev-envs
ENV PATH /app/node_modules/.bin:$PATH
ENV NODE_ENV=development
RUN apt-get update && apt-get install -y --no-install-recommends git=1:2.30.2-1+deb11u2
RUN useradd -s /bin/bash -m vscode && \
groupadd docker && \
usermod -aG docker vscode
# Install Docker tools (cli, buildx, compose)
COPY --from=gloursdocker/docker / /
RUN npm install && npm cache clean --force
RUN npm install -g [email protected]
CMD [ "nodemon", "--inspect=0.0.0.0:9229"]
### Stage for unit tests
FROM development AS unit-test
## Update apt-get and add npm
RUN apt-get update; \
apt-get install -y --no-install-recommends npm=7.5.2+ds-2;
## Copy the /app dir from builder stage in order to be able to do the unit tests
COPY --from=build /app /test-app
## Nginx unprivileged debian image
FROM nginxinc/nginx-unprivileged:1.25
## Switch to root user for setup
USER root
## Setup package(s)
RUN apt-get update; \
apt-get install -y --no-install-recommends iputils-ping=3:20221126-1
# Copy config nginx
COPY --from=build /app/.nginx/nginx.conf /etc/nginx/nginx.conf
# Copy mime.types from nginx image
COPY --from=nginx:alpine /etc/nginx/mime.types /etc/nginx/mime.types
WORKDIR /usr/share/nginx/html
# Remove default nginx static assets
RUN rm -rf ./*
# Copy static assets from builder stage
COPY --from=build /app/build .
## Expose port 8080
EXPOSE 8080
## Switch to non-root user
USER nginx
## Healthchecks
# TODO Later, when you move from the self-signed certificates delete "-k" flag
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD curl -k -f https://localhost:8080 || exit 1