generated from CodrJS/ts-microservice-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
54 lines (44 loc) · 1.1 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
### Install the dependencies
FROM node:16-alpine as deps
RUN apk add --no-cache libc6-compat
WORKDIR /usr/src
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
### Build the code
FROM deps AS builder
WORKDIR /usr/src
COPY . .
RUN yarn build
### Run the code
FROM node:16-alpine
WORKDIR /usr/src
# Set up env vars
ARG VERSION
ARG RELEASE_TIME
ARG GIT_REF
ARG GIT_COMMIT_SHA
ARG GIT_COMMIT_TIME
ARG GIT_REPO
ARG GIT_WORKFLOW_SHA
ENV NODE_ENV="production"
ENV VERSION=${VERSION}
ENV RELEASE_TIME=${RELEASE_TIME}
ENV GIT_REF=${GIT_REF}
ENV GIT_COMMIT_SHA=${GIT_COMMIT_SHA}
ENV GIT_COMMIT_TIME=${GIT_COMMIT_TIME}
ENV GIT_REPO=${GIT_REPO}
ENV GIT_WORKFLOW_SHA=${GIT_WORKFLOW_SHA}
# Set up user and group
RUN addgroup -g 1001 -S nodejs
RUN adduser -S service -u 1001
# update owner
RUN chown -R service:nodejs ./
# copy files
COPY --chown=service:nodejs --from=builder /usr/src/dist ./dist
COPY --from=builder /usr/src/node_modules ./node_modules
COPY --from=builder /usr/src/package.json ./package.json
# use user and create logs dir
USER service
RUN mkdir /usr/src/logs
EXPOSE 8000
CMD ["yarn", "start"]