-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
132 lines (100 loc) · 3.86 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
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
# syntax=docker/dockerfile:1
# ---- Base ----
FROM node:22.13.1-alpine AS base
# Set Working Directory
WORKDIR /home/node/app
# Setup the environment
COPY .yarnrc.yml .
COPY .yarn/releases .yarn/releases
# Node Dependency Management
COPY package.json .
COPY yarn.lock .
# Files required for compilation
COPY next.config.js .
COPY tsconfig.json .
COPY next-swagger-doc.json .
# ---- Dependencies ----
FROM base AS dependencies_development
# install all node_modules, including 'devDependencies'
RUN \
--mount=type=cache,target=/root/.yarn/cache \
yarn workspaces focus
# Copy the prisma schema to generate the client
COPY prisma ./prisma
# Generate the prisma client
RUN yarn prisma generate
FROM base AS dependencies_production
# Install production node_modules, excluding 'devDependencies'
RUN \
--mount=type=cache,target=/root/.yarn/cache \
yarn workspaces focus --production
# Copy the generated prisma client into the production node_modules
COPY --from=dependencies_development /home/node/app/prisma ./prisma
COPY --from=dependencies_development /home/node/app/node_modules/.prisma ./node_modules/.prisma
# ---- Build Setup ----
FROM base AS build
# Copy resources required for the build process.
# Caching depends on previous layers, therefore a changed layer will invalidate all following layers.
# Order the layers from least-to-change to frequent-to-change.
COPY sentry.client.config.ts .
COPY sentry.edge.config.ts .
COPY sentry.server.config.ts .
COPY postcss.config.js .
COPY tailwind.config.js .
COPY public ./public
COPY src ./src
# copy node_modules with all build tools included
COPY --from=dependencies_development /home/node/app/prisma ./prisma
COPY --from=dependencies_development /home/node/app/node_modules ./node_modules
# build the server
ENV NEXT_TELEMETRY_DISABLED=1
RUN yarn build
# # ---- Release ----
# build production ready image
FROM node:22.13.1-alpine AS release
LABEL maintainer="[email protected]"
LABEL org.label-schema.schema-version="1.0"
LABEL org.label-schema.name="OnLaunch"
LABEL org.label-schema.description="OnLaunch is a service allowing app developers to notify app users about updates, warnings and maintenance."
LABEL org.label-schema.url="http://kula.app/onlaunch"
LABEL org.label-schema.vcs-url="https://github.com/kula/OnLaunch"
LABEL org.label-schema.vendor="kula app GmbH"
# Set tini as entrypoint
RUN apk add --no-cache tini
ENTRYPOINT ["/sbin/tini", "--"]
# Change runtime working directory
WORKDIR /home/node/app/
# Setup the environment
COPY .yarnrc.yml .
COPY .yarn/releases .yarn/releases
# Setup custom runtime
COPY --chown=node:node docker/env.sh ./
RUN chmod +x env.sh
# Custom boot script
COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
# copy production node_modules
COPY --from=dependencies_production --chown=node:node /home/node/app/node_modules ./node_modules
COPY --from=dependencies_production /home/node/app/package.json ./package.json
COPY --from=dependencies_production /home/node/app/yarn.lock ./yarn.lock
# copy remaining build output
COPY --from=build --chown=node:node /home/node/app/next.config.js ./next.config.js
COPY --from=build --chown=node:node /home/node/app/prisma ./prisma
COPY --from=build --chown=node:node /home/node/app/public ./public
COPY --from=build --chown=node:node /home/node/app/.next ./.next
# Inject Sentry Source Maps
RUN ./node_modules/.bin/sentry-cli sourcemaps inject .next
# select user
USER node
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV NEXT_SHARP_PATH=/home/node/app/node_modules/sharp
ENV PORT=3000
EXPOSE 3000
# Setup Health Check
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/api/health || exit 1
# Smoke Tests
RUN ./node_modules/.bin/next info
# Set the default command to run the entrypoint script
CMD ["/usr/local/bin/entrypoint.sh"]