Skip to content

Commit 29aa0b9

Browse files
committed
chore(docker): fix & rewrite Node Dockerfiles
The new versions of these are designed to properly take advantage of pnpm and to also minimize output size. The builder image no longer is built on layers starting with just the package.json files. The reason for this is that with pnpm's content-addressed store and the docker buildkit cache mounts, rebuilding the layers adds only trivial overhead if dependencies haven't changed, and removing the Docker layering to attempt to cache images with just node modules reduces complexity significantly. The runner image is now based on alpine and is drastically smaller. We use `pnpm export` (or, in the case of nextjs, we use standalone builds) to populate the runner images with only the necessary packages and dependencies to further reduce image sizes.
1 parent f587b86 commit 29aa0b9

File tree

17 files changed

+321
-126
lines changed

17 files changed

+321
-126
lines changed

.github/workflows/push-price-pusher-image.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ jobs:
3939
- uses: aws-actions/amazon-ecr-login@v1
4040
id: ecr_login
4141
- run: |
42-
DOCKER_BUILDKIT=1 docker build -t lerna -f Dockerfile.lerna .
42+
DOCKER_BUILDKIT=1 docker build -t builder -f Dockerfile.builder .
43+
DOCKER_BUILDKIT=1 docker build -t runner -f Dockerfile.runner .
4344
DOCKER_BUILDKIT=1 docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f apps/price_pusher/Dockerfile .
4445
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
4546
env:

.github/workflows/push-xc-admin-image.yml renamed to .github/workflows/push-xc-admin-crank-executor-image.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ jobs:
2929
password: ${{ secrets.GITHUB_TOKEN }}
3030
- name: Build docker image
3131
run: |
32-
DOCKER_BUILDKIT=1 docker build -t lerna -f Dockerfile.lerna .
33-
DOCKER_BUILDKIT=1 docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} -f governance/xc_admin/Dockerfile .
32+
DOCKER_BUILDKIT=1 docker build -t builder -f Dockerfile.builder .
33+
DOCKER_BUILDKIT=1 docker build -t runner -f Dockerfile.runner .
34+
DOCKER_BUILDKIT=1 docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} -f governance/xc_admin/packages/crank_executor/Dockerfile .
3435
- name: Push docker image
3536
run: |
3637
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}

.github/workflows/push-xc-admin-frontend-image.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ jobs:
2828
password: ${{ secrets.GITHUB_TOKEN }}
2929
- name: Build docker image
3030
run: |
31-
DOCKER_BUILDKIT=1 docker build -t lerna -f Dockerfile.lerna .
31+
DOCKER_BUILDKIT=1 docker build -t builder -f Dockerfile.builder .
32+
DOCKER_BUILDKIT=1 docker build -t runner -f Dockerfile.runner .
3233
DOCKER_BUILDKIT=1 docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} \
3334
--build-arg NEXT_PUBLIC_RPC_POOL_TOKEN=${{ secrets.NEXT_PUBLIC_RPC_POOL_TOKEN }} \
3435
-f governance/xc_admin/packages/xc_admin_frontend/Dockerfile .

Dockerfile.builder

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM node:18.20-slim@sha256:1da7652745e9ba5de396e436aa086588ea50d532540fa3147fbc1957c43a46ab as builder
2+
WORKDIR /usr/src/pyth
3+
ENV PNPM_HOME="/pnpm"
4+
ENV PATH="$PNPM_HOME:$PATH"
5+
RUN corepack enable
6+
COPY ./ .
7+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile

Dockerfile.lerna

Lines changed: 0 additions & 38 deletions
This file was deleted.

Dockerfile.runner

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM node:18.20-alpine@sha256:6937be95129321422103452e2883021cc4a96b63c32d7947187fcb25df84fc3f as runner
2+
WORKDIR /srv
3+
ENV NODE_ENV production
4+
RUN addgroup --system --gid 1001 pyth && adduser --system --uid 1001 pyth -g pyth && chown pyth:pyth .
5+
USER pyth

apps/price_pusher/Dockerfile

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
1-
# Defined in Dockerfile.lerna
2-
FROM lerna:latest
3-
4-
USER root
5-
6-
WORKDIR /home/node/
7-
USER 1000
8-
9-
# local dependencies
10-
COPY --chown=1000:1000 target_chains/ethereum/sdk/solidity target_chains/ethereum/sdk/solidity
11-
COPY --chown=1000:1000 target_chains/sui/sdk/js target_chains/sui/sdk/js
12-
COPY --chown=1000:1000 price_service/client/js price_service/client/js
13-
COPY --chown=1000:1000 price_service/sdk/js price_service/sdk/js
14-
COPY --chown=1000:1000 target_chains/solana/sdk/js target_chains/solana/sdk/js
15-
16-
COPY --chown=1000:1000 apps/price_pusher apps/price_pusher
17-
1+
# Defined in Dockerfile.builder
2+
FROM builder AS price-pusher-builder
3+
RUN apt-get update && apt-get install -y git
184
RUN pnpm exec lerna run build --scope="@pythnetwork/price-pusher" --include-dependencies
5+
RUN pnpm deploy --filter @pythnetwork/price-pusher --prod /srv/price-pusher
196

20-
WORKDIR /home/node/apps/price_pusher
217

22-
ENTRYPOINT [ "pnpm", "run", "start" ]
8+
# Defined in Dockerfile.runner
9+
FROM runner as price-pusher
10+
COPY --from=price-pusher-builder --chown=pyth:pyth /srv/price-pusher ./
11+
CMD [ "node", "lib/index.js" ]

apps/price_pusher/docker-compose.beta.sample.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
services:
22
price-pusher:
3-
# Use this to build the price pusher from source. A dependency of the pusher docker
4-
# image is the pyth-crosschain monorepo lerna docker image. Build lerna image
5-
# using the following command from the repo root:
6-
# `docker buildx build -f Dockerfile.lerna -t lerna .`
3+
# Use this to build the price pusher from source. The pusher docker image
4+
# depends on the pyth-crosschain monorepo builder and runner docker
5+
# images. Build the images using the following commands from the repo root:
6+
# `docker buildx build -f Dockerfile.builder -t builder .`
7+
# `docker buildx build -f Dockerfile.runner -t runner .`
78
#
89
# Please note that the docker build from source only works in x86_64 platforms
910
# and doesn't work on arm platforms (like Apple M1/M2).

apps/price_pusher/docker-compose.stable.sample.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
services:
22
price-pusher:
3-
# Use this to build the price pusher from source. A dependency of the pusher docker
4-
# image is the pyth-crosschain monorepo lerna docker image. Build lerna image
5-
# using the following command from the repo root:
6-
# `docker buildx build -f Dockerfile.lerna -t lerna .`
3+
# Use this to build the price pusher from source. The pusher docker image
4+
# depends on the pyth-crosschain monorepo builder and runner docker
5+
# images. Build the images using the following commands from the repo root:
6+
# `docker buildx build -f Dockerfile.builder -t builder .`
7+
# `docker buildx build -f Dockerfile.runner -t runner .`
78
#
89
# Please note that the docker build from source only works in x86_64 platforms
910
# and doesn't work on arm platforms (like Apple M1/M2).

governance/xc_admin/Dockerfile

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)