Optimize Docker image build - #279
Open
ChaoticSciuridae wants to merge 1 commit into
Open
ChaoticSciuridae wants to merge 1 commit into
ChaoticSciuridae wants to merge 1 commit into
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 converts
dockerfile.unifiedto a multi-stage build while trying to change as little as possible about the existing runtime behavior.I'm not a Docker expert but I noticed the image was much larger than any of my other services because the existing build installed build/dev dependencies into the same image that ultimately became the runtime image.
The main goal here was simply: reduce the image size as much as practical with the smallest possible change.
So with the help of AI to bridge my knowledge gaps --
Results
Built on the same machine:
The builder now handles the dependencies and files needed to build the Next.js application, while the final runtime stage only receives what it needs to run.
I intentionally avoided trying to redesign the container, split PostgreSQL/Redis into separate services, change the startup process, or otherwise expand the scope of this PR.
Testing
I built and ran the resulting image locally.
So far:
The application appears to behave normally in my testing.
Again, Docker image optimization isn't really my area of expertise, so feedback is very welcome if there is a better way to handle any of the stage boundaries or runtime dependencies.