Replies: 2 comments
-
|
Here's a modified Dockerfile, with comments. I worked backwards to make this after I got my own Dockerfile working, so it matched the original from the blog post (in terms of paths and such), Might have goofed in the process of doing that, hopefully not. FROM node:18.2.0-alpine3.15 as base
RUN apk update && apk add git
RUN npm i -g turbo
FROM base as pruner
# +++ The "installer" layer COPYs from "pruner" using absolute path "/app/...", so presumably we
# need to set that as the WORKDIR here when we copy those files into the pruner layer
WORKDIR /app
# (...Was the intent to have the .git artifacts in a directory above /app?)
COPY .git ./.git
COPY . .
# +++ adding --docker to "turbo prune", since the next layer copies
# from ../out/json. If I'm understanding the docs correctly,
# ../json is only generated if the --docker flag is present
RUN turbo prune --scope=frontend --docker
# +++ Derive FROM "base" layer and COPY files from "pruner" layer.
# Since the full source is copied into the pruner layer in the above block (COPY . .),
# doing "FROM pruner..." for the installer layer would mean a rebuild
# (and re-run of yarn install) on any file change....I think
FROM base AS installer
# +++ COPY commands below are using a mix of absolute a relative paths, so we need to set WORKDIR here
WORKDIR /app
# +++ trailing slashes on dest affect COPY behavior, not needed on source paths
COPY --from=pruner /app/out/json .
COPY --from=pruner /app/out/yarn.lock ./yarn.lock
# +++ buildkit caching of yarn install command
RUN --mount=type=cache, sharing=locked, target=/usr/local/share/.cache/yarn/v6, id=yarncache yarn install
FROM installer as builder
WORKDIR /app
# +++ Changed "COPY --from=pruner .git ./.git" to "COPY --from=pruner /app/.git ./.git",
# given the changes to "pruner" layer above. Again, feels like I might be missing
# something regarding the intended location for the .git artifacts
COPY --from=pruner /app/.git ./.git
# +++ Copying the root dir of 'installer' to root dir of 'builder' is redundant since the builder is already derived FROM installer, I think?
# COPY --from=installer /app .
# +++ Was "COPY --from=builder", which throws an error (circular). Assuming it was meant to copy from "pruner"
COPY --from=pruner /app/out/full .
# +++ Use "filter" argument instead of scope and include dependencies.
RUN turbo run build --filter=frontend...
# Start the app
FROM builder as runner
EXPOSE 3000
# +++ Unless there's some reason I'm unaware of, I feel like this should be CMD instead of RUN,
# since "yarn start" probably isn't adding anything to the "runner" layer that we'd want to commit...right?
CMD ["yarn", "--cwd", "packages/frontend", "start"]Without comments: ## BASE ##
FROM node:18.2.0-alpine3.15 as base
RUN apk update && apk add git
RUN npm i -g turbo
## PRUNER ##
FROM base as pruner
WORKDIR /app
COPY .git ./.git
COPY . .
RUN turbo prune --scope=frontend --docker
## INSTALLER ##
FROM base AS installer
WORKDIR /app
COPY --from=pruner /app/out/json .
COPY --from=pruner /app/out/yarn.lock ./yarn.lock
RUN --mount=type=cache, sharing=locked, target=/usr/local/share/.cache/yarn/v6, id=yarncache yarn install
## BUILDER ##
FROM installer as builder
WORKDIR /app
COPY --from=pruner /app/.git ./.git
COPY --from=pruner /app/out/full .
RUN turbo run build --filter=frontend...
## RUNNER ##
FROM builder as runner
EXPOSE 3000
CMD ["yarn", "--cwd", "packages/frontend", "start"] |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
And what is gained in bringing along |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Was reading through the 0.4.0 readme on workspace pruning and came across something that confused me. I'm wondering if it's just a typo. They demonstrate a multistage, multi-inheritance build process, but it looks like preceding stages reference descendant stages. I'm wondering if that's actually allowable in docker, or if it's just a typo. If it is possible, what are the consequences, what is the mental model for how this works?
Beta Was this translation helpful? Give feedback.
All reactions