-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathDockerfile
More file actions
54 lines (51 loc) · 2.42 KB
/
Dockerfile
File metadata and controls
54 lines (51 loc) · 2.42 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
# syntax=docker/dockerfile:1.4
# Installation stage.
FROM node:22-alpine AS base
WORKDIR /workspace
RUN apk add --update --no-cache openssl python3 make g++
# Install pnpm.
ADD package.json .
# TODO: Remove this once it's no longer needed.
# - https://github.com/pnpm/pnpm/issues/9014#issuecomment-2618565344
# - https://github.com/nodejs/corepack/issues/612
RUN npm install --global corepack@latest
RUN corepack enable && corepack prepare --activate
# Skip prisma code generation during install.
ENV PRISMA_SKIP_POSTINSTALL_GENERATE=true
ENV CI=true
# Fetch all node modules purely based on the pnpm lock file.
COPY pnpm-lock.yaml .
RUN --mount=type=cache,id=workspace,target=/root/.local/share/pnpm/store pnpm fetch
# Copy the entire workspace into the scope and perform the actual installation.
COPY . .
RUN --mount=type=cache,id=workspace,target=/root/.local/share/pnpm/store pnpm install
# Build stage for the server.
FROM base AS build
# TODO: Remove this when we switch to an actual database.
ENV DATABASE_URL="file:/data/production.sqlite"
RUN \
# TODO: This initalizes the database. But we should probably remove this later.
# pnpm --filter server prisma migrate reset --force && \
# Build the monorepo packages
pnpm build && \
# Generate the prisma client
pnpm --filter server prisma generate && \
# Build the server.
pnpm --filter server build && \
# Create an isolated deployment for the server.
pnpm --filter server deploy --prod deployment --legacy && \
# Move the runtime build artifacts into a separate directory.
mkdir -p deployment/out && mv deployment/dist deployment/node_modules deployment/package.json deployment/out && \
# Add prisma client in dist
mv deployment/prisma/generated/client/libquery_engine-linux-musl-arm64-openssl-3.0.x.so.node deployment/out/dist/libquery_engine-linux-musl-arm64-openssl-3.0.x.so.node && \
mv deployment/prisma/generated/client/libquery_engine-linux-musl-openssl-3.0.x.so.node deployment/out/dist/libquery_engine-linux-musl-openssl-3.0.x.so.node && \
mv deployment/prisma deployment/out
# Slim runtime image.
FROM node:22-alpine AS server
WORKDIR /app
COPY --from=build /workspace/deployment/out .
# TODO: Remove this when we switch to an actual database.
ENV DATABASE_URL="file:/data/production.sqlite"
EXPOSE 3030
# can't use fly.io release_command because it doesn't mount the volume containing the sqlite db file
CMD ["sh", "-c", "npm run prisma migrate deploy && node dist/index.js"]