refactor: docker image for less final size (#315) #385
+223
−71
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.
This pull request introduces a comprehensive overhaul of the Docker build and deployment process for the web application, resolving issue #315 , focusing on improved Dockerfile layering, distroless production images, runtime environment variable injection, and robust database migration handling. It also enhances the
.dockerignorefor more efficient builds and updates thedocker-compose.ymlto support the new workflow. Additionally, there are minor improvements to authentication environment variable handling and Next.js configuration.Docker build and deployment improvements:
apps/web/Dockerfileto use a multi-stage build, including Alpine-based build stages, a dedicated migration stage, and a final distroless production image for enhanced security and smaller image size. Added a custombootstrap.cjsscript to inject runtime environment variables and start the Next.js server.docker-compose.yml, ensuring that database migrations run as a one-off container before starting the web app, and that the web app waits for migration completion.Build efficiency and configuration:
.dockerignoreto exclude unnecessary files and directories, reducing Docker build context size and improving build times.apps/web/next.config.jsto exclude dev-only dependencies from the standalone output, reducing production image size.next.config.jsfor consistency.Authentication and environment handling:
packages/auth/src/auth.tsby filtering out empty values from the environment variable.Final breakdown of build images:
ghcr.io/kanbn/kan(official)ghcr.io/kanbn/kan(distroless)ghcr.io/kanbn/kan-migrate(alpine)