-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
63 lines (44 loc) · 2.04 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
#############################################################################################################################
# Stage 0: Install the base dependecies
FROM node:20-alpine@sha256:55004633597a2e059ca930a7cca9785b94125eb9442a1e31a6a4707dacfa348b AS dependencies
# explicit path - Copy the package.json and package-lock.json files into /app.
COPY package*.json /app/
# Use /app as our working directory
WORKDIR /app
# Install node dependencies defined in package-lock.json (For production)
RUN npm ci --production
##############################################################################################################################
# Stage 1: Copy required files and Deploy
FROM node:20-alpine@sha256:55004633597a2e059ca930a7cca9785b94125eb9442a1e31a6a4707dacfa348b AS build
LABEL maintainer="Harshil Patel <hpatel292@myseneca.ca>"
LABEL description="Fragments node.js microservice"
# We default to use port 8080 in our service
# Reduce npm spam when installing within Docker
# https://docs.npmjs.com/cli/v8/using-npm/config#loglevel
# Disable colour when run inside Docker
# https://docs.npmjs.com/cli/v8/using-npm/config#color
#set node environment to production
ENV PORT=8080 \
NPM_CONFIG_LOGLEVEL=warn \
NPM_CONFIG_COLOR=false \
NODE_ENV=production
# Use /app as our working directory
WORKDIR /app
#Copy the generated dependencies (node_modules/)
COPY --from=dependencies /app /app
# Copy src to /app/src/
COPY --chown=node:node ./src ./src
# Copy our HTPASSWD file
COPY ./tests/.htpasswd ./tests/.htpasswd
# Install curl for healthcheck
RUN apk update && apk add --no-cache curl=8.9.0-r0
# Switch user to node
# USER node
# Start the container by running our server
# fix the warning given by Halolint "warning: Use arguments JSON notation for CMD and ENTRYPOINT arguments"
CMD ["node", "src/index.js"]
# We run our service on port 8080
EXPOSE ${PORT}
# Add a healthcheck layer (Querying healthcheck route '/')
HEALTHCHECK --interval=15s --timeout=30s --start-period=10s --retries=3 \
CMD curl --fail localhost:${PORT} || exit 1