-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
42 lines (31 loc) · 980 Bytes
/
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
### Dependency Cacher
### -------------------------
FROM endeveit/docker-jq:latest as deps
# To prevent cache invalidation from changes in fields other than dependencies
# https://stackoverflow.com/a/59606373
COPY package.json /tmp
RUN jq '{ dependencies, devDependencies, resolutions }' < /tmp/package.json > /tmp/deps.json
### Fat Build
### -------------------------
FROM node:16.14.2 as builder
WORKDIR /usr/link-shortener
# Cache dependencies
COPY --from=deps /tmp/deps.json ./package.json
COPY yarn.lock ./
RUN yarn install
# Copy and build application codebase
COPY . .
RUN yarn build
### Slim Deploy
### -------------------------
FROM node:16.14.2
WORKDIR /usr/link-shortener
# Install and cache production dependencies
COPY --from=deps /tmp/deps.json ./package.json
COPY yarn.lock ./
RUN yarn install --production
# Copy only the built source
COPY --from=builder /usr/link-shortener/dist ./dist
COPY package.json ./
EXPOSE 8080
CMD ["node", "./dist/server.js"]