Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: docker builds optimizations #1795

Merged
merged 31 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
647e974
Auth package dockerfile optimization
raducristianpopa Aug 25, 2023
e4dc1cf
Remove libc6-compat
raducristianpopa Aug 25, 2023
6a5e410
Merge branch 'main' into rp--optimize-docker-builds
raducristianpopa Aug 25, 2023
eb1a2f8
Merge branch 'main' into rp--optimize-docker-builds
raducristianpopa Aug 28, 2023
fb4d02f
Remove test compose file
raducristianpopa Aug 28, 2023
2b264c7
Backend dockerfile optimization
raducristianpopa Aug 28, 2023
bbbfbaa
Frontend and ASE Dockerfile optimizations
raducristianpopa Aug 28, 2023
30cd458
Local HTTP Signatures app docker optimization
raducristianpopa Aug 29, 2023
024c693
[Test] Bump PNPM major version
raducristianpopa Aug 29, 2023
3ea267b
Use offline mode only for the build step
raducristianpopa Aug 29, 2023
6895e39
Test out pnpm v8
raducristianpopa Aug 29, 2023
d3ff7b6
Add --prefer-offline option and revert pnpm to v7
raducristianpopa Aug 29, 2023
321ff2a
Try out cache busting
raducristianpopa Aug 29, 2023
a0d8c84
Remove CACHE_BUST arg
raducristianpopa Aug 29, 2023
439e808
Add `prefer-offline` options to all `prod-deps` stage
raducristianpopa Aug 30, 2023
e6c5fd7
Remove `--prefer-offline` from auth and backend Dockerfile
raducristianpopa Aug 30, 2023
24ae203
Try installing TS globally
raducristianpopa Aug 30, 2023
50a4315
Set PNPM_HOME in all docker files
raducristianpopa Aug 30, 2023
7b39c57
Cache bust
raducristianpopa Aug 30, 2023
c815408
Revert "Cache bust"
raducristianpopa Aug 30, 2023
292d063
Merge branch 'main' into rp--optimize-docker-builds
raducristianpopa Sep 5, 2023
8ed59c2
Fetch `httpbis-digest-headers` from registry
raducristianpopa Sep 5, 2023
e5dd63c
Merge branch 'main' into rp--optimize-docker-builds
raducristianpopa Sep 7, 2023
8627793
Bump `http-signature-utils` version
raducristianpopa Sep 7, 2023
b6577a8
Do not install TS globally when building prod deps
raducristianpopa Sep 7, 2023
ba69900
Make sure that `http-signature-utils` is bumped in every package
raducristianpopa Sep 7, 2023
455b164
Pin alpine version
raducristianpopa Sep 7, 2023
24db14d
Cache bust
raducristianpopa Sep 7, 2023
1bfa0eb
Revert "Cache bust"
raducristianpopa Sep 7, 2023
4a72018
Update pnpm to v8
raducristianpopa Sep 7, 2023
f5a0e05
Merge branch 'main' into rp--optimize-docker-builds
raducristianpopa Sep 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ infrastructure

.github
.husky
Dockerfile
.dockerignore
.eslintignore
.eslintrc.yml
Expand Down
57 changes: 47 additions & 10 deletions localenv/local-http-signatures/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,58 @@
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
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"

# 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=/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=/pnpm/store \
pnpm install \
--recursive \
--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=/pnpm/store \
pnpm install \
--recursive \
--prefer-offline \
--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"]
63 changes: 53 additions & 10 deletions localenv/mock-account-servicing-entity/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,64 @@
FROM node:18.13.0-slim as builder
FROM node:18-alpine AS base
raducristianpopa marked this conversation as resolved.
Show resolved Hide resolved

WORKDIR /workspace
WORKDIR /home/rafiki

RUN apt update
RUN apt install -y curl xz-utils python3 build-essential
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"

# version in curl is not the version used. Dependent on the last command
RUN corepack enable
RUN corepack prepare pnpm@7.25.1 --activate
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason we are still using pnpm@v7 instead of v8?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we forgot to update it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried with pnpm v8?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried with pnpm v8 when I was running into the httpbis-digest-headers issue. It should also work with v8 without any problems. As for the choice to stick with v7, I recall @mkurapov mentioning an edge case or an issue that was preventing us from upgrading to v8, but I'm not entirely sure about this.

RUN apk add --no-cache \
python3 \
make \
g++
Comment on lines +10 to +13
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node-gyp requirements.


# 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=/pnpm/store \
pnpm fetch \
| grep -v "cross-device link not permitted\|Falling back to copying packages from store"

FROM base AS prod-deps

RUN pnpm add -g typescript

COPY package.json pnpm-workspace.yaml .npmrc ./
COPY localenv/mock-account-servicing-entity/package.json ./localenv/mock-account-servicing-entity/package.json

RUN pnpm clean
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm install \
--recursive \
--prefer-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 localenv/mock-account-servicing-entity ./localenv/mock-account-servicing-entity

RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm install \
--recursive \
--offline \
--frozen-lockfile
RUN pnpm --filter mock-account-servicing-entity build

CMD pnpm --filter mock-account-servicing-entity start
FROM node:18-alpine AS runner

WORKDIR /home/rafiki

COPY localenv/cloud-nine-wallet/seed.yml ./localenv/cloud-nine-wallet/seed.yml
COPY localenv/happy-life-bank/seed.yml ./localenv/happy-life-bank/seed.yml

COPY --from=prod-deps /home/rafiki/node_modules ./node_modules
COPY --from=prod-deps /home/rafiki/localenv/mock-account-servicing-entity/node_modules ./localenv/mock-account-servicing-entity/node_modules
COPY --from=prod-deps /home/rafiki/localenv/mock-account-servicing-entity/package.json ./localenv/mock-account-servicing-entity/package.json

COPY --from=builder /home/rafiki/localenv/mock-account-servicing-entity/build ./localenv/mock-account-servicing-entity/build
COPY --from=builder /home/rafiki/localenv/mock-account-servicing-entity/public ./localenv/mock-account-servicing-entity/public

WORKDIR /home/rafiki/localenv/mock-account-servicing-entity
CMD ["sh", "./node_modules/.bin/remix-serve", "build"]
68 changes: 58 additions & 10 deletions packages/auth/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,69 @@
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
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"

# 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=/pnpm/store \
pnpm fetch \
| grep -v "cross-device link not permitted\|Falling back to copying packages from store"

FROM base AS prod-deps

RUN pnpm add -g typescript

COPY package.json pnpm-workspace.yaml .npmrc ./
COPY packages/auth/package.json ./packages/auth/package.json
COPY packages/token-introspection/package.json ./packages/token-introspection/package.json

RUN pnpm clean
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm install \
--recursive \
--prefer-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 packages/auth ./packages/auth
COPY packages/token-introspection ./packages/token-introspection

RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm install \
--recursive \
--offline \
--frozen-lockfile
RUN pnpm --filter auth build

CMD ["node", "./packages/auth/dist/index.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/packages/auth/node_modules ./packages/auth/node_modules
COPY --from=prod-deps /home/rafiki/packages/auth/package.json ./packages/auth/package.json
COPY --from=prod-deps /home/rafiki/packages/token-introspection/node_modules ./packages/token-introspection/node_modules
COPY --from=prod-deps /home/rafiki/packages/token-introspection/package.json ./packages/token-introspection/package.json

COPY --from=builder /home/rafiki/openapi ./openapi
COPY --from=builder /home/rafiki/packages/auth/migrations/ ./packages/auth/migrations
COPY --from=builder /home/rafiki/packages/token-introspection/src/openapi/token-introspection.yaml ./packages/token-introspection/src/openapi/token-introspection.yaml
COPY --from=builder /home/rafiki/packages/auth/dist ./packages/auth/dist
COPY --from=builder /home/rafiki/packages/token-introspection/dist ./packages/token-introspection/dist


CMD ["node", "/home/rafiki/packages/auth/dist/index.js"]
68 changes: 58 additions & 10 deletions packages/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,69 @@
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
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"

# 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=/pnpm/store \
pnpm fetch \
| grep -v "cross-device link not permitted\|Falling back to copying packages from store"

FROM base AS prod-deps

RUN pnpm add -g typescript

COPY package.json pnpm-workspace.yaml .npmrc ./
COPY packages/backend/package.json ./packages/backend/package.json
COPY packages/token-introspection/package.json ./packages/token-introspection/package.json

RUN pnpm clean
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm install \
--recursive \
--prefer-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 packages/backend ./packages/backend
COPY packages/token-introspection ./packages/token-introspection

RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm install \
--recursive \
--offline \
--frozen-lockfile
RUN pnpm --filter backend build

CMD ["node", "./packages/backend/dist/index.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/packages/backend/node_modules ./packages/backend/node_modules
COPY --from=prod-deps /home/rafiki/packages/backend/package.json ./packages/backend/package.json
COPY --from=prod-deps /home/rafiki/packages/token-introspection/node_modules ./packages/token-introspection/node_modules
COPY --from=prod-deps /home/rafiki/packages/token-introspection/package.json ./packages/token-introspection/package.json

COPY --from=builder /home/rafiki/openapi ./openapi
COPY --from=builder /home/rafiki/packages/backend/migrations/ ./packages/backend/migrations
COPY --from=builder /home/rafiki/packages/token-introspection/src/openapi/token-introspection.yaml ./packages/token-introspection/src/openapi/token-introspection.yaml
COPY --from=builder /home/rafiki/packages/backend/dist ./packages/backend/dist
COPY --from=builder /home/rafiki/packages/token-introspection/dist ./packages/token-introspection/dist


CMD ["node", "/home/rafiki/packages/backend/dist/index.js"]
58 changes: 48 additions & 10 deletions packages/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,59 @@
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
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"

# 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=/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 packages/frontend/package.json ./packages/frontend/package.json

RUN pnpm clean
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm install \
--recursive \
--prefer-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 packages/frontend ./packages/frontend

RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm install \
--recursive \
--offline \
--frozen-lockfile
RUN pnpm --filter frontend build

CMD pnpm --filter frontend start
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/packages/frontend/node_modules ./packages/frontend/node_modules
COPY --from=prod-deps /home/rafiki/packages/frontend/package.json ./packages/frontend/package.json

COPY --from=builder /home/rafiki/packages/frontend/build ./packages/frontend/build
COPY --from=builder /home/rafiki/packages/frontend/public ./packages/frontend/public

WORKDIR /home/rafiki/packages/frontend
CMD ["sh", "./node_modules/.bin/remix-serve", "build"]