-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile.alpine
92 lines (72 loc) · 3.52 KB
/
Dockerfile.alpine
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
# syntax=docker/dockerfile:1.4
# Arguments with default value (for build).
ARG PLATFORM=linux/amd64
ARG NODE_VERSION=20
# -----------------------------------------------------------------------------
# Base image with pnpm package manager.
# -----------------------------------------------------------------------------
FROM --platform=${PLATFORM} node:${NODE_VERSION}-alpine AS base
ENV PNPM_HOME="/pnpm" PATH="$PNPM_HOME:$PATH" COREPACK_ENABLE_DOWNLOAD_PROMPT=0
RUN corepack enable && corepack prepare pnpm@latest-9 --activate
WORKDIR /srv
# -----------------------------------------------------------------------------
# Install dependencies and some toolchains.
# -----------------------------------------------------------------------------
FROM base AS builder
ENV LEFTHOOK=0 CI=true PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=true
# Copy the source files
COPY --chown=node:node . .
RUN apk update && apk add --no-cache tini jq libc6-compat
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install \
--ignore-scripts && pnpm build
# -----------------------------------------------------------------------------
# Compile the application and install production only dependencies.
# -----------------------------------------------------------------------------
FROM base AS pruner
ENV LEFTHOOK=0 PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=true NODE_ENV=production
# Required source files
COPY --from=builder /srv/package.json /srv/package.json
COPY --from=builder /srv/.npmrc /srv/.npmrc
# Generated files
COPY --from=builder /srv/pnpm-lock.yaml /srv/pnpm-lock.yaml
COPY --from=builder /srv/dist/runner /srv/dist/runner
COPY --from=builder /srv/dist/remix /srv/dist/remix
# Install production dependencies and cleanup node_modules.
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod \
--frozen-lockfile --ignore-scripts && pnpm prune --prod \
--ignore-scripts && pnpm dlx clean-modules clean --yes \
"!**/@libsql/**" && chmod +x /srv/dist/runner/server.js
# -----------------------------------------------------------------------------
# Production image, copy build output files and run the application.
# -----------------------------------------------------------------------------
FROM base AS runner
LABEL org.opencontainers.image.source="https://github.com/riipandi/remix-start"
# ----- Read application environment variables --------------------------------
ARG APP_BASE_URL APP_SECRET_KEY APP_LOG_LEVEL DATABASE_URL \
SMTP_HOST SMTP_PORT SMTP_USERNAME SMTP_PASSWORD SMTP_EMAIL_FROM
ENV APP_BASE_URL=$APP_BASE_URL \
APP_SECRET_KEY=$APP_SECRET_KEY \
APP_LOG_LEVEL=$APP_LOG_LEVEL \
DATABASE_URL=$DATABASE_URL \
SMTP_HOST=$SMTP_HOST \
SMTP_PORT=$SMTP_PORT \
SMTP_USERNAME=$SMTP_USERNAME \
SMTP_PASSWORD=$SMTP_PASSWORD \
SMTP_EMAIL_FROM=$SMTP_EMAIL_FROM
# ----- Read application environment variables --------------------------------
# Don't run production as root.
RUN addgroup --system --gid 1001 nonroot && adduser --system --uid 1001 nonroot
# Copy the build output files from the pruner stage.
COPY --chown=nonroot:nonroot --from=pruner /pnpm /pnpm
COPY --chown=nonroot:nonroot --from=pruner /srv /srv
# Copy some utilities from builder image.
COPY --from=builder /sbin/tini /sbin/tini
# Define the host and port to listen on.
ARG NODE_ENV=production HOST=0.0.0.0 PORT=3000
ENV PNPM_HOME="/pnpm" PATH="$PNPM_HOME:$PATH"
ENV NODE_ENV=$NODE_ENV HOST=$HOST PORT=$PORT
ENV TINI_SUBREAPER=true
USER nonroot:nonroot
EXPOSE $PORT
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["/usr/local/bin/node", "/srv/dist/runner/server.js"]