-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathDockerfile.build
93 lines (62 loc) · 2.07 KB
/
Dockerfile.build
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# syntax=docker/dockerfile:1
# BASED ON https://turbo.build/repo/docs/guides/tools/docker
# AND https://github.com/ThaddeusJiang/turborepo-starter/blob/main/apps/api/Dockerfile
# Use Node 20 base
FROM node:20-alpine AS alpine
# What is the @faims3/... name of the package to build
ARG PACKAGE_NAME
ENV PACKAGE_NAME=${PACKAGE_NAME}
# What directory relative to the monorepo will the node build folder containing
# index.js be built to. For example API -> api/build/src
ARG NODE_RUN_DIR
ENV NODE_RUN_DIR=${NODE_RUN_DIR}
# install some dependencies
RUN apk update && apk add --no-cache libc6-compat
# create this layer to use to avoid repeatedly installing
FROM alpine AS base
# PRUNE TO GET DEPENDENCIES [pruner]
# ===================================
# Use turbo to prune package dependencies
FROM base AS pruner
# work in /app folder
WORKDIR /app
# install turbo global
RUN npm install turbo@^2.0.11 -g
# copy everything into pruner
COPY . .
# prune using turbo for only faims3 and it's dependencies. This produces an
# /app/out folder which has /full (all needed deps) or /json (package*.json
# only)
RUN turbo prune ${PACKAGE_NAME} --docker
# INSTALL PACKAGES [builder]
# ============================
# add lockfiles dependencies
FROM base AS builder
WORKDIR /app
# Install dependencies
COPY .gitignore .gitignore
COPY --from=pruner /app/out/json/ .
# install turbo global
RUN npm install turbo@^2.0.11 -g
RUN npm install
# Build the project
COPY --from=pruner /app/out/full/ .
COPY --from=pruner /app/out/json/ json
# build packages using turbo
RUN turbo run build --filter=${PACKAGE_NAME}
# Package all necessary files to run app into pruner out
COPY bundle.sh .
RUN sh bundle.sh json . out && cp -R json/* /app/out/
# PRODUCTION RUNNER [runner]
# ==========================
FROM alpine AS runner
WORKDIR /app
# Don't run production as root
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 faims
USER faims
# Copy all files which are required to run the app
COPY --from=builder /app/out .
# Run the node app
WORKDIR /app/${NODE_RUN_DIR}
CMD ["node", "index.js"]