-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathDockerfile
More file actions
152 lines (98 loc) · 4 KB
/
Dockerfile
File metadata and controls
152 lines (98 loc) · 4 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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# syntax=docker/dockerfile:1
# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/go/dockerfile-reference/
ARG NODE_VERSION=24.15.0
ARG ALPINE_VERSION=3.22
ARG PACKAGE
ARG PORT=3000
ARG PNPM_VERSION=9.10.0
################################################################################
# Use node image for base image for all stages.
FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION} AS base
# these are necessary to be able to use them inside of `base`
ARG BASE_IMAGE
ARG PNPM_VERSION
# Instll dependencies we need at the end
RUN apk add ca-certificates curl postgresql17
# Setup RDS CA Certificates
RUN curl -L \
-o /usr/local/share/ca-certificates/rds-global-bundle.pem \
https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem \
&& update-ca-certificates
# Set working directory for all build stages.
WORKDIR /usr/src/app
# Install pnpm.
RUN --mount=type=cache,target=/root/.npm \
npm install -g pnpm@${PNPM_VERSION}
FROM base AS fetch-deps
# Copy pnpm-lock.yaml so that we can use pnpm to install dependencies
COPY pnpm-lock.yaml ./
# Could possibly be sped up using `turbo prune`
# https://turbo.build/repo/docs/guides/tools/docker
RUN pnpm fetch
# Install dependencies we only need to run pnpm install
RUN apk add g++ make py3-pip
################################################################################
# Create a stage for building the application.
FROM fetch-deps AS monorepo
# Copy over the rest of the files
ADD . ./
# Install from the fetched store
RUN pnpm install -r --prefer-offline
RUN pnpm p:build
################################################################################
FROM monorepo AS withpackage
WORKDIR /usr/src/app
ARG PACKAGE
RUN test -n "$PACKAGE" || (echo "PACKAGE not set, required for this target" && false)
ENV DOCKERBUILD=1
ARG CI
ENV CI=$CI
ARG BASE_PATH=""
ENV BASE_PATH=$BASE_PATH
RUN --mount=type=secret,id=SENTRY_AUTH_TOKEN,env=SENTRY_AUTH_TOKEN \
pnpm --filter $PACKAGE build
FROM withpackage AS prepare-jobs
ARG PACKAGE
RUN pnpm --filter $PACKAGE --prod deploy /tmp/app
FROM base AS jobs
ARG PACKAGE
WORKDIR /usr/src/app
COPY --from=prepare-jobs --chown=node:node /tmp/app .
# If the package is site-builder, create necessary directories and set permissions
RUN if [ "$PACKAGE" = "site-builder-2" ]; then \
mkdir -p /usr/src/app/builds /usr/src/app/.astro /usr/src/app/dist && \
chown -R node:node /usr/src/app/builds /usr/src/app/.astro /usr/src/app/dist; \
fi
# very important, otherwise you will see obscure `dispatcher.getOwner` errors
ENV NODE_ENV=production
USER node
CMD ["pnpm", "start"]
################################################################################
# Create a new stage to run the application with minimal runtime dependencies
# where the necessary files are copied from the build stage.
# this is separated by package to make it slightly more clear what happens
# and because you cannot conditionally copy from a different folder
# based on the argument
FROM base AS prod-setup
ARG PORT
USER node
EXPOSE $PORT
ENV NODE_ENV=production
ENV HOSTNAME="0.0.0.0"
### Core
FROM prod-setup AS next-app-core
WORKDIR /usr/src/app
COPY --from=withpackage --chown=node:node /usr/src/app/core/.next/standalone ./
COPY --from=withpackage --chown=node:node /usr/src/app/core/.next/static ./core/.next/static
COPY --from=withpackage --chown=node:node /usr/src/app/core/public ./core/public
# migration sql files, applied automatically during startup instrumentation
COPY --from=withpackage --chown=node:node /usr/src/app/core/prisma/migrations ./core/prisma/migrations
CMD ["node", "--enable-source-maps", "core/server.js"]
### Mock Notify
FROM prod-setup AS next-app-mock-notify
WORKDIR /usr/src/app
COPY --from=withpackage --chown=node:node /usr/src/app/mock-notify/.next/standalone ./
COPY --from=withpackage --chown=node:node /usr/src/app/mock-notify/.next/static ./mock-notify/.next/static
CMD ["node", "mock-notify/server.js"]