Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
65 lines (51 loc) · 2.39 KB
/
Copy pathDockerfile
File metadata and controls
65 lines (51 loc) · 2.39 KB
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
# Initialize builder layer
FROM node:lts-alpine AS builder
ENV NODE_ENV=production
# Prevent npx get-pnpm EBADDEVENGINES failure from
# devEngines.packageManager in /app/package.json
WORKDIR /
# Install necessary tools
RUN apk add --no-cache libc6-compat yq build-base g++ cairo-dev jpeg-dev pango-dev giflib-dev --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community
# Install pnpm on Alpine Linux using get-pnpm
# https://github.com/pnpm/pnpm/issues/784#issuecomment-1518582235
COPY package.json /app/
ENV PNPM_HOME=/pnpm
ENV PATH="$PNPM_HOME/bin:$PATH"
RUN ENV="$HOME/.shrc" SHELL=/bin/sh npx --yes get-pnpm \
"$(node --input-type=module --eval \
'console.log((await import("/app/package.json", { with: { type: "json" } })).default.devEngines.packageManager.version)')"
WORKDIR /app
# Copy the content of the project to the machine
COPY . .
RUN yq --inplace --output-format=json '(.dependencies = .dependencies * (.devDependencies | to_entries | map(select(.key | test("^(typescript|@types/*|eslint-config-upleveled)$"))) | from_entries)) | (.devDependencies = {})' package.json
RUN pnpm install
RUN pnpm build
# Initialize runner layer
FROM node:lts-alpine AS runner
ENV NODE_ENV=production
# Prevent npx get-pnpm EBADDEVENGINES failure from
# devEngines.packageManager in /app/package.json
WORKDIR /
# Install necessary tools
RUN apk add bash postgresql cairo pango jpeg musl giflib pixman pangomm libjpeg-turbo freetype
# Install pnpm on Alpine Linux using get-pnpm
# https://github.com/pnpm/pnpm/issues/784#issuecomment-1518582235
COPY --from=builder /app/package.json /app/
ENV PNPM_HOME=/pnpm
ENV PATH="$PNPM_HOME/bin:$PATH"
RUN ENV="$HOME/.shrc" SHELL=/bin/sh npx --yes get-pnpm \
"$(node --input-type=module --eval \
'console.log((await import("/app/package.json", { with: { type: "json" } })).default.devEngines.packageManager.version)')"
WORKDIR /app
# Copy built app
COPY --from=builder /app/.next ./.next
# Copy only necessary files to run the app (minimize production app size, improve performance)
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/migrations ./migrations
COPY --from=builder /app/public ./public
COPY --from=builder /app/.env.production ./
COPY --from=builder /app/next.config.ts ./
# Copy start script and make it executable
COPY --from=builder /app/scripts ./scripts
RUN chmod +x /app/scripts/fly-io-start.sh
CMD ["./scripts/fly-io-start.sh"]