-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
65 lines (47 loc) · 1.85 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
# Stage 01: install dependencies
################################
FROM node:18.14.2-alpine3.16@sha256:72c0b366821377f04d816cd0287360e372cc55782d045e557e2640cb8040d3ea AS dependencies
# define node env to install prod dependencies only
ENV NODE_ENV=production
# define work directory for our app
WORKDIR /fragments
# copy our package*.json dependencies
COPY package.json package-lock.json /fragments/
# 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
# install app dependencies
RUN npm ci
# Stage 02: setup our app
#########################
FROM node:18.14.2-alpine3.16@sha256:72c0b366821377f04d816cd0287360e372cc55782d045e557e2640cb8040d3ea AS setup
# define work directory for our app
WORKDIR /fragments
# copy the generated node_modules folder from our dependencies layer
COPY --from=dependencies /fragments /fragments
# copy our source code
COPY ./src/ /fragments/src/
COPY ./tests/.htpasswd ./tests/.htpasswd
# Stage 03: run our app
#########################
FROM node:18.14.2-alpine3.16@sha256:72c0b366821377f04d816cd0287360e372cc55782d045e557e2640cb8040d3ea AS run
# set image metadata
LABEL maintainer="Humam Bahoo <[email protected]>"
LABEL description="Fragments node.js microservice"
# define work directory for our app
WORKDIR /fragments
# copy everything from our setup layer
COPY --from=setup /fragments /fragments
# install curl for our Healthcheck
RUN apk --no-cache --update add curl=8.0.1-r0
# define our env variables
ENV PORT=8080
# run our app and expose port 8080
CMD [ "node" ,"src/index.js"]
EXPOSE 8080
# define our healthcheck
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl --fail localhost:8080 || exit 1