Skip to content

Commit 764ce52

Browse files
committed
build inside container on first start
1 parent 5b1ea3c commit 764ce52

2 files changed

Lines changed: 19 additions & 36 deletions

File tree

Dockerfile

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ ARG PNPM_VERSION=10.33.2
44
ARG ALPINE_VERSION=3.23
55
ARG PNPM_URL="https://github.com/pnpm/pnpm/releases/download/v${PNPM_VERSION}/pnpm-linuxstatic-x64"
66

7-
# --- Build stage ---
8-
FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION} AS build
7+
FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION}
98

109
ARG PNPM_URL
1110
ARG GIT_BRANCH
1211
ARG GIT_COMMIT_SHA
1312

1413
WORKDIR /app
1514
ENV DOCKER=true
15+
ENV NODE_ENV=production
1616
ENV GIT_BRANCH=${GIT_BRANCH}
1717
ENV GIT_COMMIT_SHA=${GIT_COMMIT_SHA}
1818

@@ -25,44 +25,16 @@ COPY pnpm-lock.yaml .
2525
COPY pnpm-workspace.yaml .
2626
COPY patches/ patches/
2727

28-
# Install deps
29-
RUN pnpm install --frozen-lockfile --strict-peer-dependencies
28+
# Install all deps (incl. dev) — needed because the build runs at container start.
29+
# --prod=false forces dev deps even though NODE_ENV=production is set above.
30+
RUN pnpm install --frozen-lockfile --strict-peer-dependencies --prod=false
3031

3132
# Copy full source after dependencies are cached
3233
COPY . .
3334

34-
# Build the app (output to /app/build)
35-
RUN pnpm run build
36-
37-
38-
# --- Runtime stage ---
39-
FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION} AS runtime
35+
# Make entrypoint executable (in case the host bit was lost)
36+
RUN chmod +x /app/docker-entrypoint.sh
4037

41-
ARG PNPM_URL
42-
ARG GIT_BRANCH
43-
ARG GIT_COMMIT_SHA
44-
45-
WORKDIR /app
46-
ENV DOCKER=true
47-
ENV NODE_ENV=production
48-
ENV GIT_BRANCH=${GIT_BRANCH}
49-
ENV GIT_COMMIT_SHA=${GIT_COMMIT_SHA}
50-
51-
# Install pnpm again for runtime dependency resolution
52-
RUN wget -qO /bin/pnpm "${PNPM_URL}" && chmod +x /bin/pnpm
53-
54-
# App will run on port 3000
5538
EXPOSE 3000
5639

57-
# Copy only required runtime files and build output
58-
COPY --from=build /app/package.json .
59-
COPY --from=build /app/pnpm-lock.yaml .
60-
COPY --from=build /app/pnpm-workspace.yaml .
61-
COPY --from=build /app/patches/ patches/
62-
COPY --from=build /app/build build/
63-
64-
# Install only production dependencies
65-
RUN pnpm install --frozen-lockfile --strict-peer-dependencies
66-
67-
# Start the app
68-
CMD ["node","build/index.js"]
40+
ENTRYPOINT ["/app/docker-entrypoint.sh"]

docker-entrypoint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
if [ ! -f /app/build/index.js ]; then
5+
echo "[entrypoint] No build found, running pnpm build with current env..."
6+
pnpm run build
7+
else
8+
echo "[entrypoint] Existing build found, skipping rebuild."
9+
fi
10+
11+
exec node build/index.js

0 commit comments

Comments
 (0)