Skip to content

Commit 2b325f3

Browse files
authored
feat: optimize Dockerfile (#47)
* define base image arg * create base stage with common content * chmod executable entrypoint file this avoids re-copying the same file as is being modified in the docker layer * cache npm downloaded packages avoids re-downloading deps if cache content is available
1 parent 4d3c164 commit 2b325f3

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

docker/Dockerfile

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
# Dockerfile for Open Archiver
22

3-
# 1. Build Stage: Install all dependencies and build the project
4-
FROM node:22-alpine AS build
3+
ARG BASE_IMAGE=node:22-alpine
4+
5+
# 0. Base Stage: Define all common dependencies and setup
6+
FROM ${BASE_IMAGE} AS base
57
WORKDIR /app
68

79
# Install pnpm
8-
RUN npm install -g pnpm
10+
RUN --mount=type=cache,target=/root/.npm \
11+
npm install -g pnpm
912

1013
# Copy manifests and lockfile
1114
COPY package.json pnpm-workspace.yaml pnpm-lock.yaml* ./
1215
COPY packages/backend/package.json ./packages/backend/
1316
COPY packages/frontend/package.json ./packages/frontend/
1417
COPY packages/types/package.json ./packages/types/
18+
19+
# 1. Build Stage: Install all dependencies and build the project
20+
FROM base AS build
1521
COPY packages/frontend/svelte.config.js ./packages/frontend/
1622

1723
# Install all dependencies. Use --shamefully-hoist to create a flat node_modules structure
18-
RUN pnpm install --shamefully-hoist --frozen-lockfile --prod=false
24+
ENV PNPM_HOME="/pnpm"
25+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
26+
pnpm install --shamefully-hoist --frozen-lockfile --prod=false
1927

2028
# Copy the rest of the source code
2129
COPY . .
@@ -24,17 +32,7 @@ COPY . .
2432
RUN pnpm build
2533

2634
# 2. Production Stage: Install only production dependencies and copy built artifacts
27-
FROM node:22-alpine AS production
28-
WORKDIR /app
29-
30-
# Install pnpm
31-
RUN npm install -g pnpm
32-
33-
# Copy manifests and lockfile
34-
COPY package.json pnpm-workspace.yaml pnpm-lock.yaml* ./
35-
COPY packages/backend/package.json ./packages/backend/
36-
COPY packages/frontend/package.json ./packages/frontend/
37-
COPY packages/types/package.json ./packages/types/
35+
FROM base AS production
3836

3937
# Install production dependencies
4038
# RUN pnpm install --shamefully-hoist --frozen-lockfile --prod=true
@@ -48,7 +46,6 @@ COPY --from=build /app/packages/backend/src/database/migrations ./packages/backe
4846

4947
# Copy the entrypoint script and make it executable
5048
COPY docker/docker-entrypoint.sh /usr/local/bin/
51-
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
5249

5350
# Expose the port the app runs on
5451
EXPOSE 4000

docker/docker-entrypoint.sh

100644100755
File mode changed.

0 commit comments

Comments
 (0)