-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
52 lines (40 loc) · 1.61 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
#Stage 0: install base dependencies
# Use node version 16.15.1
FROM node:16.15.1-alpine3.16@sha256:c785e617c8d7015190c0d41af52cc69be8a16e3d9eb7cb21f0bb58bcfca14d6b AS dependencies
LABEL maintainer="Justin Kim <jkim452@myseneca.ca>"
LABEL description="Fragments node.js microservice"
# We default to use port 8080 in our service
ENV PORT=8080
# define environment as production
ENV NODE_ENV production
# Reduce npm spam when installing within Docker
# https://docs.npmjs.com/cli/v8/using-npm/config#loglevel
ENV NPM_CONFIG_LOGLEVEL=warn
# Disable colour when run inside Docker
# https://docs.npmjs.com/cli/v8/using-npm/config#color
ENV NPM_CONFIG_COLOR=false
# Use /app as our working directory
WORKDIR /app
# Copy the package.json and package-lock.json files into /app
COPY --chown=node:node package*.json /app/
# Install node dependencies defined in package-lock.json
RUN npm ci --only=production
USER node
# Copy src to /app/src/
COPY --chown=node:node ./src ./src
# Copy our HTPASSWD file
COPY ./tests/.htpasswd ./tests/.htpasswd
#################################################################################
#Stage 1: build application
FROM node:16.15.1-alpine3.16@sha256:c785e617c8d7015190c0d41af52cc69be8a16e3d9eb7cb21f0bb58bcfca14d6b AS build
# Use /app as our working directory
WORKDIR /app
USER node
# copy the generated dependencies (node_modules/)
COPY --chown=node:node --from=dependencies /app /app
COPY --chown=node:node . .
CMD ["npm", "start"]
USER node
# We run our service on port 8080
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=30s --start-period=10s --retries=3 CMD [ curl --fail localhost:8080 || exit 1]