Skip to content

Commit

Permalink
Local HTTP Signatures app docker optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
raducristianpopa committed Aug 29, 2023
1 parent bbbfbaa commit 30cd458
Showing 1 changed file with 45 additions and 11 deletions.
56 changes: 45 additions & 11 deletions localenv/local-http-signatures/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,55 @@
FROM node:18.13.0-slim as builder
FROM node:18-alpine AS base

WORKDIR /workspace
WORKDIR /home/rafiki

RUN apt update
RUN apt install -y curl xz-utils python3 build-essential

# version in curl is not the version used. Dependent on the last command
RUN corepack enable
RUN corepack prepare pnpm@7.25.1 --activate
RUN apk add --no-cache \
python3 \
make \
g++

# pnpm fetch does require only lockfile
COPY pnpm-lock.yaml ./
RUN pnpm fetch

ADD . ./
RUN pnpm install -r --offline
RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store \
pnpm fetch \
| grep -v "cross-device link not permitted\|Falling back to copying packages from store"

FROM base AS prod-deps

COPY package.json pnpm-workspace.yaml .npmrc ./
COPY localenv/local-http-signatures/package.json ./localenv/local-http-signatures/package.json

RUN pnpm clean
RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store \
pnpm install \
--recursive \
--offline \
--frozen-lockfile \
--prod \
| grep -v "cross-device link not permitted\|Falling back to copying packages from store"

FROM base AS builder

COPY package.json pnpm-workspace.yaml .npmrc tsconfig.json tsconfig.build.json ./
COPY openapi ./openapi
COPY localenv/local-http-signatures ./localenv/local-http-signatures

RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store \
pnpm install \
--recursive \
--offline \
--frozen-lockfile
RUN pnpm --filter local-http-signatures build

CMD ["node", "./localenv/local-http-signatures/dist/app.js"]
FROM node:18-alpine AS runner

WORKDIR /home/rafiki

COPY --from=prod-deps /home/rafiki/node_modules ./node_modules
COPY --from=prod-deps /home/rafiki/localenv/local-http-signatures/node_modules ./localenv/local-http-signatures/node_modules
COPY --from=prod-deps /home/rafiki/localenv/local-http-signatures/package.json ./localenv/local-http-signatures/package.json

COPY --from=builder /home/rafiki/localenv/local-http-signatures/dist ./localenv/local-http-signatures/dist

CMD ["node", "/home/rafiki/localenv/local-http-signatures/dist/app.js"]

0 comments on commit 30cd458

Please sign in to comment.