Skip to content

Commit 6345814

Browse files
committed
fix: docker builds
1 parent 5ec1797 commit 6345814

File tree

3 files changed

+100
-13
lines changed

3 files changed

+100
-13
lines changed

.github/workflows/push-auth-server-api-container.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ jobs:
6565
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
6666
with:
6767
context: .
68-
file: Dockerfile
69-
target: auth-server-api
68+
file: packages/auth-server-api/Dockerfile
7069
push: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) || github.event_name == 'workflow_dispatch' }}
7170
tags: |
7271
matterlabs/sso-auth-server-api:${{ steps.docker_tag.outputs.tag }}

Dockerfile

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ FROM base AS build
88
COPY . /usr/src/app
99
WORKDIR /usr/src/app
1010
RUN pnpm install --prod=false --frozen-lockfile
11-
RUN pnpm --filter='!./packages/sdk-platforms/*' --filter='!./packages/sdk-4337' -r run build
11+
RUN pnpm --filter='!./packages/sdk-platforms/*' --filter='!./packages/sdk-4337' --filter='!./packages/auth-server-api' -r run build
1212
RUN pnpm deploy --filter=oidc-server --prod /prod/oidc-server
13-
RUN pnpm deploy --filter=auth-server-api --prod /prod/auth-server-api
1413

1514
FROM base AS oidc-server
1615
COPY --from=build /prod/oidc-server /prod/oidc-server
@@ -22,12 +21,4 @@ EXPOSE 3003 9090
2221
CMD [ "node", "dist/salt-service.js" ]
2322

2423
FROM oidc-server AS key-registry
25-
CMD [ "node", "dist/update-keys-service.js" ]
26-
27-
FROM base AS auth-server-api
28-
COPY --from=build /prod/auth-server-api /prod/auth-server-api
29-
WORKDIR /prod/auth-server-api
30-
COPY --from=build /usr/src/app/packages/auth-server-api/dist ./dist
31-
ENV PORT=3003
32-
EXPOSE 3003
33-
CMD [ "node", "dist/index.js" ]
24+
CMD [ "node", "dist/update-keys-service.js" ]
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Stage 1: Build dependencies (Rust + Foundry)
2+
FROM rust:1.83-bookworm AS rust-builder
3+
4+
# Install build dependencies
5+
RUN apt-get update && apt-get install -y \
6+
curl \
7+
git \
8+
build-essential \
9+
pkg-config \
10+
libssl-dev \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
# Add wasm32 target
14+
RUN rustup target add wasm32-unknown-unknown
15+
16+
# Install wasm-pack
17+
RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
18+
19+
# Install Foundry (forge, cast, anvil)
20+
RUN curl -L https://foundry.paradigm.xyz | bash
21+
ENV PATH="/root/.foundry/bin:${PATH}"
22+
RUN foundryup
23+
24+
# Stage 2: Build Node.js dependencies and contracts
25+
FROM node:22-bookworm-slim AS builder
26+
27+
# Copy Foundry and Rust tools from previous stage
28+
COPY --from=rust-builder /usr/local/cargo /usr/local/cargo
29+
COPY --from=rust-builder /usr/local/rustup /usr/local/rustup
30+
COPY --from=rust-builder /root/.foundry /root/.foundry
31+
ENV PATH="/root/.foundry/bin:/usr/local/cargo/bin:${PATH}"
32+
ENV RUSTUP_HOME=/usr/local/rustup
33+
ENV CARGO_HOME=/usr/local/cargo
34+
35+
# Enable pnpm
36+
ENV PNPM_HOME="/pnpm"
37+
ENV PATH="$PNPM_HOME:$PATH"
38+
RUN corepack enable pnpm
39+
40+
# Install build dependencies for native modules
41+
RUN apt-get update && apt-get install -y \
42+
git \
43+
python3 \
44+
make \
45+
g++ \
46+
&& rm -rf /var/lib/apt/lists/*
47+
48+
# Set working directory
49+
WORKDIR /usr/src/app
50+
51+
# Copy the entire monorepo
52+
COPY . .
53+
54+
# Install all dependencies
55+
RUN pnpm install -r --frozen-lockfile
56+
57+
# Build ERC-4337 contracts with Foundry
58+
WORKDIR /usr/src/app/packages/erc4337-contracts
59+
RUN forge soldeer install
60+
RUN forge build
61+
62+
# Build ERC-4337 related packages
63+
WORKDIR /usr/src/app
64+
RUN pnpm nx build web-sdk
65+
RUN pnpm nx build sdk-4337
66+
67+
# Build auth-server-api
68+
RUN pnpm nx build auth-server-api
69+
70+
# Deploy only production dependencies for auth-server-api
71+
RUN pnpm deploy --filter=auth-server-api --prod /prod/auth-server-api
72+
73+
# Stage 3: Production runtime
74+
# Using distroless for minimal attack surface
75+
FROM gcr.io/distroless/nodejs22-debian12:nonroot AS production
76+
77+
# Copy the deployed auth-server-api with its dependencies
78+
COPY --from=builder --chown=nonroot:nonroot /prod/auth-server-api /prod/auth-server-api
79+
80+
# Copy the built dist folder
81+
COPY --from=builder --chown=nonroot:nonroot /usr/src/app/packages/auth-server-api/dist /prod/auth-server-api/dist
82+
83+
WORKDIR /prod/auth-server-api
84+
85+
# Environment variables
86+
ENV PORT=3004
87+
ENV NODE_ENV=production
88+
89+
# Healthcheck
90+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
91+
CMD ["node", "-e", "require('http').get('http://localhost:3004/api/health', (r) => process.exit(r.statusCode === 200 ? 0 : 1))"]
92+
93+
# Expose port
94+
EXPOSE 3004
95+
96+
# Start the server with WASM support
97+
ENTRYPOINT ["node", "--experimental-wasm-modules", "dist/index.js"]

0 commit comments

Comments
 (0)