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

feat: docker monorepo build #1219

Merged
merged 18 commits into from
Sep 5, 2023
Merged

feat: docker monorepo build #1219

merged 18 commits into from
Sep 5, 2023

Conversation

ludns
Copy link
Member

@ludns ludns commented Jul 31, 2023

No description provided.

@changeset-bot
Copy link

changeset-bot bot commented Jul 31, 2023

🦋 Changeset detected

Latest commit: 5f12991

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 27 packages
Name Type
@latticexyz/services Patch
@latticexyz/cli Patch
@latticexyz/block-logs-stream Patch
@latticexyz/common Patch
@latticexyz/config Patch
create-mud Patch
@latticexyz/dev-tools Patch
@latticexyz/ecs-browser Patch
@latticexyz/gas-report Patch
@latticexyz/network Patch
@latticexyz/noise Patch
@latticexyz/phaserx Patch
@latticexyz/protocol-parser Patch
@latticexyz/react Patch
@latticexyz/recs Patch
@latticexyz/schema-type Patch
@latticexyz/solecs Patch
solhint-config-mud Patch
solhint-plugin-mud Patch
@latticexyz/std-client Patch
@latticexyz/std-contracts Patch
@latticexyz/store-cache Patch
@latticexyz/store-indexer Patch
@latticexyz/store-sync Patch
@latticexyz/store Patch
@latticexyz/utils Patch
@latticexyz/world Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ludns ludns marked this pull request as ready for review August 1, 2023 19:40
@ludns ludns requested a review from a user August 1, 2023 19:40
@ludns ludns requested review from alvrs and holic as code owners August 1, 2023 19:40
@ludns ludns changed the title feat: WIP docker monorepo build feat: docker monorepo build Aug 1, 2023
RUN pnpm run -r build

FROM builder AS store-indexer
WORKDIR /app/packages/store-indexer
Copy link
Member

Choose a reason for hiding this comment

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

since this dockerfile is specific to store-indexer, should we put this in packages/store-indexer/bin? or does that make the rest of the infra complicated?

Copy link
Member Author

Choose a reason for hiding this comment

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

we are having one top level docker file that builds the entire monorepo, then takes specific artifacts and put them in different images. This dockerfile actually describes two images right now: a global builder, and a specific store-indexer. Over time we will add more of them, one for each TS service that requires a Docker image.
having one per package is actually worse, given we would need to build the entire monorepo for each of them (instead of looping through all targets -- currently only store-indexer, and building + tagging them individually which will leverage the cache of the build stage).

Dockerfile Outdated
WORKDIR /app/packages/store-indexer
EXPOSE 3001
ENV DEBUG=*
ENV NODE_ENV=production
Copy link
Member

Choose a reason for hiding this comment

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

you should now be able to add RPC_HTTP_URL and RPC_WS_URL here

Copy link
Contributor

@roninjin10 roninjin10 left a comment

Choose a reason for hiding this comment

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

additional nit: should add a docker-compose file. Some of my comments you should definitely do is why I'm requesting changes

.dockerignore Show resolved Hide resolved
.dockerignore Outdated Show resolved Hide resolved
@@ -0,0 +1,39 @@
FROM docker.io/library/debian:bullseye-slim as base
Copy link
Contributor

@roninjin10 roninjin10 Aug 2, 2023

Choose a reason for hiding this comment

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

nit: Could use the official nodejs bulssey-slim image with the exact version of node specified in engines Easier to deal with node versioning and deletes some of the apt-gets

Dockerfile Outdated Show resolved Hide resolved
# pnpm
RUN npm install pnpm --global

FROM base AS builder
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: not a big deal but unnecessary to start a new image here

RUN npm install pnpm --global

FROM base AS builder
COPY . /app
Copy link
Contributor

Choose a reason for hiding this comment

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

This is going to be needlessly slow with bad caching. Everytime any file changes you will need to rebuild node modules.

What you should do is instead COPY pnpm-lock.yaml and then run pnpm fetch. This installs node modules with only the pnpm lockfile so if that didn't change it gets cached.

See pnpm fetch documentation about docker for more info https://pnpm.io/cli/fetch

Comment on lines +29 to +30
ENV PATH="${PATH}:/usr/local/go/bin"
ENV PATH="${PATH}:/root/.foundry/bin"
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see adding foundry to path here


ENV PATH="${PATH}:/usr/local/go/bin"
ENV PATH="${PATH}:/root/.foundry/bin"
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
Copy link
Contributor

Choose a reason for hiding this comment

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

should use pnpm fetch followed by pnpm install --offline see comment above

RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
RUN pnpm run -r build

FROM builder AS store-indexer
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice good use of multistage build

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually looking at this now you could likely Copy in just the buld artifacts and then run pnpm i --production to not install dev deps and have a smaller image. This is a nit though if the image is not too large don't need to optimize now

Copy link
Contributor

Choose a reason for hiding this comment

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

If you want to make it super tiny you would use a smaller image than bullseye slim. You don't need very much to run just a node process usually requires more extra tooling to build an app than to run an app.

As an example I build with bullseye-slim. but then run the application with the much tinier gcr.io/distroless/nodejs18 as example-server-runner image here https://github.com/roninjin10/stax/blob/main/Dockerfile#L242

I use distroless specifically because it's debian based

Dockerfile Outdated
EXPOSE 3001
ENV DEBUG=*
ENV NODE_ENV=production
CMD [ "pnpm", "start:testnet" ]
Copy link
Contributor

Choose a reason for hiding this comment

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

You might need to set HOST to 0.0.0.0 ymmv

Dockerfile Outdated Show resolved Hide resolved
holic
holic previously approved these changes Sep 5, 2023
Copy link
Member

@holic holic left a comment

Choose a reason for hiding this comment

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

going to save the other dockerfile optimizations for a later pass once we get this wired into CI

@holic holic merged commit 80a2641 into main Sep 5, 2023
@holic holic deleted the ludens/docker-monorepo-build branch September 5, 2023 09:26
@github-actions github-actions bot mentioned this pull request Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants