-
-
Notifications
You must be signed in to change notification settings - Fork 0
chore: docker examples #1030
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
Merged
Merged
chore: docker examples #1030
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,52 @@ | ||
| # .dockerignore is used to exclude files and directories from being copied into the Docker image during the build process. This helps to reduce the size of the image and improve build times by only including necessary files. | ||
| # keep it at the root of the project to ensure that we don't copy unnecessary files into the Docker image. | ||
|
|
||
| node_modules | ||
| **/.turbo | ||
| # git (disable if needed in the container) | ||
| .git | ||
|
|
||
| # dependencies | ||
| **/node_modules | ||
|
|
||
| # caches | ||
| **/.cache | ||
| **/tsconfig.tsbuildinfo | ||
| **/tsconfig.*.tsbuildinfo | ||
| **/.eslintcache | ||
|
|
||
| # turbo (comment if you want to copy the turbo cache into the image) | ||
| **/.turbo | ||
|
|
||
| # package managers | ||
| **/.yarn/* | ||
| !**/.yarn/patches | ||
| !**/.yarn/releases | ||
| !**/.yarn/plugins | ||
| .pnp.* | ||
|
|
||
| # testing | ||
| **/coverage | ||
| **/.out/ | ||
|
|
||
| # Build directories | ||
| **/apps/*/.next | ||
| **/packages/*/dist | ||
| **/packages/*/docs | ||
| **/.eslintcache | ||
|
|
||
| # Misc | ||
| .DS_Store | ||
| *.pem | ||
|
|
||
| # Debug | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
|
|
||
| # IDE | ||
| .idea/* | ||
| .project | ||
| .classpath | ||
| *.launch | ||
| *.sublime-workspace | ||
| .vscode/ | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
| _release | ||
|
|
||
| # Turbo pruned files | ||
| out | ||
| .turbo-pruned | ||
|
|
||
| # local env files (following nextjs convention) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,51 @@ | ||
| # this file should won't be read unless it exists in the | ||
| # context directory specified in the docker compose file | ||
|
|
||
| node_modules | ||
| #**/.turbo | ||
| #**/.cache | ||
| #**/apps/*/.next | ||
| #**/packages/*/dist | ||
| #**/packages/*/docs | ||
| #**/.eslintcache | ||
| # git (disable if needed in the container) | ||
| .git | ||
|
|
||
| # dependencies | ||
| **/node_modules | ||
|
|
||
| # caches | ||
| **/.cache | ||
| **/tsconfig.tsbuildinfo | ||
| **/tsconfig.*.tsbuildinfo | ||
| **/.eslintcache | ||
|
|
||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # turbo (comment if you want to copy the turbo cache into the image) | ||
| **/.turbo | ||
|
|
||
| # package managers | ||
| **/.yarn/* | ||
| !**/.yarn/patches | ||
| !**/.yarn/releases | ||
| !**/.yarn/plugins | ||
| .pnp.* | ||
|
|
||
| # testing | ||
| **/coverage | ||
| **/.out/ | ||
|
|
||
| # Build directories | ||
| **/apps/*/.next | ||
| **/packages/*/dist | ||
| **/packages/*/docs | ||
|
|
||
| # Misc | ||
| .DS_Store | ||
| *.pem | ||
|
|
||
| # Debug | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
|
|
||
| # IDE | ||
| .idea/* | ||
| .project | ||
| .classpath | ||
| *.launch | ||
| *.sublime-workspace | ||
| .vscode/ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| ARG NODE_VERSION=24.14 | ||
| ARG DISTROLESS_IMAGE=gcr.io/distroless/nodejs24-debian13 | ||
| ARG DEBIAN_VERSION=trixie-slim | ||
| ARG COREPACK_VERSION=0.34.6 | ||
|
|
||
|
|
||
| ############################################################# | ||
| # Stage 1 - App extraction / pruning # | ||
| ############################################################# | ||
|
|
||
| FROM node:${NODE_VERSION}-${DEBIAN_VERSION} AS prepare | ||
|
|
||
| RUN apt-get update \ | ||
| #&& apt-get install build-essential cmake curl unzip ca-certificates git jq --no-install-recommends -y \ | ||
| && apt-get install git jq --no-install-recommends -y \ | ||
| && rm -rf /var/cache/apt/* \ | ||
| ## Corepack won't be bundled in node 25+ | ||
| && npm i -g corepack@${COREPACK_VERSION} && corepack enable | ||
|
|
||
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY --link package.json turbo.jsonc ./ | ||
|
|
||
| # We can't run turbo without yarn install first, let's install locally and make sure | ||
| # both local and docker are aligned on the package.json version. | ||
| RUN TURBO_VERSION=$(cat package.json | jq '.devDependencies["turbo"]' -r) npm i -g turbo@${TURBO_VERSION} | ||
|
|
||
| COPY --link . . | ||
|
|
||
| # https://turbo.build/repo/docs/handbook/deploying-with-docker | ||
| RUN turbo prune --scope=@examples/nextjs-app --docker --out-dir=./.turbo-pruned/nextjs-app/ | ||
|
|
||
| ############################################################# | ||
| # Stage 2 - App installation # | ||
| ############################################################# | ||
|
|
||
| FROM prepare AS builder | ||
|
|
||
| ENV TZ=Etc/UTC | ||
|
|
||
| # Optimize for YARN installation speed | ||
| ENV YARN_ENABLE_GLOBAL_CACHE=false | ||
| ENV YARN_ENABLE_MIRROR=false | ||
| ENV YARN_ENABLE_TELEMETRY=false | ||
| ENV YARN_NODE_LINKER=node-modules | ||
| ENV YARN_NM_MODE=hardlinks-local | ||
| ENV YARN_ENABLE_HARDENED_MODE=0 | ||
| ENV YARN_ENABLE_CONSTRAINTS_CHECKS=false | ||
| # If using different compression level than in local (recommended: prefer to not do this) | ||
| #ENV YARN_COMPRESSION_LEVEL 0 | ||
| #ENV YARN_CHECKSUM_BEHAVIOR ignore | ||
|
|
||
| # Disabling some well-known postinstall scripts | ||
| ENV PRISMA_SKIP_POSTINSTALL_GENERATE=true | ||
| ENV HUSKY=0 | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # First install the dependencies (as they change less often) | ||
| COPY --link .gitignore ./ | ||
| COPY --from=prepare --link /app/.turbo-pruned/nextjs-app/json/ . | ||
| COPY --from=prepare --link /app/.turbo-pruned/nextjs-app/yarn.lock ./yarn.lock | ||
|
|
||
| # Option 1: run install without cache | ||
| #RUN yarn install --inline-builds | ||
|
|
||
| # Option 2: run install with buildx cache mount (buildx) | ||
| RUN --mount=type=cache,target=/root/.yarn3-cache,id=yarn3-cache,sharing=locked \ | ||
| YARN_CACHE_FOLDER=/root/.yarn3-cache \ | ||
| yarn install --inline-builds | ||
|
|
||
| # Build the project | ||
| COPY --link --from=prepare /app/.turbo-pruned/nextjs-app/full/ . | ||
| COPY --link .gitignore turbo.jsonc tsconfig.base.json ./ | ||
|
|
||
| ENV NEXT_BUILD_IGNORE_ESLINT=true | ||
| ENV NEXT_BUILD_IGNORE_TYPECHECK=true | ||
| ENV NEXT_BUILD_OUTPUT=standalone | ||
| ENV NODE_ENV=production | ||
| # ENV NEXT_BUILD_ENV_SENTRY_ENABLED=false | ||
| # ENV NEXT_BUILD_ENV_SENTRY_TRACING=false | ||
|
|
||
| RUN yarn workspace @examples/db-sqlserver prisma-generate | ||
|
|
||
| RUN yarn turbo run build --filter=@examples/nextjs-app | ||
| # Alternative we can also | ||
| #RUN yarn turbo run build --filter=@examples/nextjs-app... | ||
|
|
||
| ############################################################# | ||
| # Stage 3 - App runner # | ||
| ############################################################# | ||
|
|
||
| FROM ${DISTROLESS_IMAGE} AS runner | ||
|
|
||
| ARG NEXTJS_APP_PORT | ||
|
|
||
| # Bort PORT / HOSTNAME envs are respected by nextjs start/dev. | ||
| ENV HOSTNAME=0.0.0.0 | ||
| ENV PORT=${NEXTJS_APP_PORT:-3000} | ||
| ENV TZ=Etc/UTC | ||
| ENV NODE_ENV=production | ||
|
|
||
| #RUN apt-get update \ | ||
| # && apt-get install tzdata --no-install-recommends -y \ | ||
| # && rm -rf /var/cache/apt/* | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| #RUN addgroup --system --gid 1001 nodejs | ||
| #RUN adduser --system --uid 1001 nextjs | ||
|
|
||
| # Set the correct permission for prerender cache | ||
| #RUN mkdir .next | ||
| #RUN chown nextjs:nodejs .next | ||
|
|
||
| # Default distroless user | ||
| USER 65532:65532 | ||
|
|
||
| COPY --from=builder /app/examples/apps/nextjs-app/next.config.mjs \ | ||
| /app/examples/apps/nextjs-app/package.json --chown=65532:65532 \ | ||
| ./ | ||
|
|
||
| # Automatically leverage output traces to reduce image size | ||
| # https://nextjs.org/docs/advanced-features/output-file-tracing | ||
| COPY --from=builder --chown=65532:65532 /app/examples/apps/nextjs-app/.next/standalone ./ | ||
| COPY --from=builder --chown=65532:65532 /app/examples/apps/nextjs-app/.next/static ./examples/apps/nextjs-app/.next/static | ||
| COPY --from=builder --chown=65532:65532 /app/examples/apps/nextjs-app/public ./examples/apps/nextjs-app/public | ||
|
|
||
| EXPOSE ${PORT} | ||
|
|
||
| CMD ["node", "examples/apps/nextjs-app/server.js"] | ||
|
|
17 changes: 17 additions & 0 deletions
17
examples/apps/nextjs-app/docker/docker-compose.distroless.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| name: flowblade-example-nextjs | ||
| services: | ||
| app-distroless: | ||
| build: | ||
| # Start from root of the monorepo | ||
| context: ../../../../ | ||
| dockerfile: ./examples/apps/nextjs-app/docker/Dockerfile.distroless | ||
| restart: no | ||
| networks: | ||
| - flowblade-net | ||
| ports: | ||
| - 3000:3000 | ||
|
|
||
| networks: | ||
| flowblade-net: | ||
| driver: bridge | ||
| enable_ipv6: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.