Skip to content

Commit 2d63673

Browse files
authored
fix(coprocessor): use npm ci for deterministic builds (#1870)
* fix(docker): use npm ci for deterministic builds Replace `npm install` with `npm ci` in Dockerfiles to ensure reproducible builds from the lockfile. `npm install` can modify package-lock.json and produce non-deterministic results. * trigger CI * revert: npm ci breaks in isolated Docker builds The Dockerfiles build contracts in isolation without access to the monorepo root package-lock.json. npm ci requires the lockfile to be present, but only host-contracts/ or gateway-contracts/ directories are copied into the build context. npm install is the correct choice here since it resolves dependencies from package.json without requiring a lockfile. * fix(docker): use npm ci with root lockfile for deterministic builds Copy root package.json and package-lock.json into Docker build context to enable npm ci for workspace members (host-contracts). Changes: - host-listener/Dockerfile: Copy root lockfile, use npm ci --workspace - Dockerfile.workspace: Copy root lockfile for host-contracts workspace, use npm ci directly for gateway-contracts (has own lockfile) This ensures reproducible builds from the lockfile while respecting the monorepo workspace structure. * chore: remove redundant comments * fix(docker): run npm ci from workspace root npm workspace commands must be executed from the directory containing the root package.json with the workspaces field, not from inside the workspace directory.
1 parent 7fb1bd7 commit 2d63673

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

coprocessor/fhevm-engine/Dockerfile.workspace

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,16 @@ FROM ghcr.io/zama-ai/fhevm/gci/nodejs:22.14.0-alpine3.21 AS contract_builder
3434
USER root
3535
WORKDIR /app
3636

37+
# Copy root lockfile for workspace resolution
38+
COPY package.json package-lock.json ./
39+
3740
# Copy host-contracts for host-listener
3841
COPY host-contracts ./host-contracts
3942

4043
# Compile host-contracts
41-
WORKDIR /app/host-contracts
42-
RUN cp .env.example .env && \
43-
npm install && \
44+
RUN cp host-contracts/.env.example host-contracts/.env && \
45+
npm ci --workspace=host-contracts --include-workspace-root=false && \
46+
cd host-contracts && \
4447
HARDHAT_NETWORK=hardhat npm run deploy:emptyProxies && \
4548
npx hardhat compile
4649

@@ -50,7 +53,7 @@ COPY gateway-contracts ./gateway-contracts
5053

5154
# Compile gateway-contracts
5255
WORKDIR /app/gateway-contracts
53-
RUN npm install && \
56+
RUN npm ci && \
5457
DOTENV_CONFIG_PATH=.env.example npx hardhat task:deployAllGatewayContracts
5558

5659
# =============================================================================

coprocessor/fhevm-engine/host-listener/Dockerfile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@ USER root
55

66
WORKDIR /app
77

8+
# Copy root lockfile for workspace resolution
9+
COPY package.json package-lock.json ./
10+
811
COPY host-contracts ./host-contracts
912

1013
# Compiled host-contracts for listeners
11-
WORKDIR /app/host-contracts
12-
RUN cp .env.example .env
13-
RUN npm install && HARDHAT_NETWORK=hardhat npm run deploy:emptyProxies && npx hardhat compile
14+
RUN cp host-contracts/.env.example host-contracts/.env && \
15+
npm ci --workspace=host-contracts --include-workspace-root=false && \
16+
cd host-contracts && \
17+
HARDHAT_NETWORK=hardhat npm run deploy:emptyProxies && \
18+
npx hardhat compile
1419

1520
# Stage 1: Build Host Listener
1621
FROM ghcr.io/zama-ai/fhevm/gci/rust-glibc:1.91.0 AS builder

0 commit comments

Comments
 (0)