Skip to content

optimize docker image layers#4271

Merged
aajtodd merged 1 commit intomainfrom
aajtodd/optimize-dockerfile
Aug 18, 2025
Merged

optimize docker image layers#4271
aajtodd merged 1 commit intomainfrom
aajtodd/optimize-dockerfile

Conversation

@aajtodd
Copy link
Contributor

@aajtodd aajtodd commented Aug 18, 2025

Description

Adding/fixing caching of Gradle wrapper to our build image increased it's size beyond 2GB. We started seeing issues with dry run release and download artifact silently failing. This PR attempts to optimize the image layers to reduce it's overall size and hopefully work past these issues.

Key Optimizations

Multi-stage consolidation:
• Combined all cargo tool installations into a single cargo_tools stage instead of separate stages per tool
• Created dedicated gradle_wrapper stage that reuses install_rust base to avoid duplicating Java installation

Layer reduction:
• Combined RUN commands with cleanup operations (yum clean all && rm -rf /var/cache/yum)
• Added cargo cache cleanup (rm -rf /opt/cargo/registry/src && rm -rf /opt/cargo/git/db) after installations
• Consolidated AWS CLI installation and cleanup in single layer

Gradle wrapper optimization:
• Removed checkout_smithy_rs_tools conditional logic - now always fetches gradle wrapper
• Uses sparse checkout to fetch only required files (gradlew, gradle/wrapper, gradle.properties)

Before and after:

> finch images
REPOSITORY                          TAG                                            IMAGE ID        CREATED         PLATFORM       SIZE       BLOB SIZE
smithy-rs-build-image               latest                                         449b886b6045    2 days ago      linux/arm64    6.663GB    2.223GB
smithy-rs-base-image                local                                          2c1a924209b3    2 days ago      linux/arm64    6.663GB    2.223GB
smithy-rs-base-image                ci-d4053cbdd4e82adff099eb2f4e6cbaae2139d577    2c1a924209b3    2 days ago      linux/arm64    6.663GB    2.223GB
ghcr.io/github/github-mcp-server    latest                                         9cd2504664e1    2 months ago    linux/arm64    46.25MB    13.08MB
todaaron at 842f577d1917 in ~/sandbox/rs/smithy-rs on aajtodd/optimize-dockerfile ✗                                                                                  [91e76ab45]  10:22
> finch images
REPOSITORY                          TAG                                            IMAGE ID        CREATED           PLATFORM       SIZE       BLOB SIZE
smithy-rs-base-image                local                                          811268820b1a    48 seconds ago    linux/arm64    4.57GB     1.564GB
smithy-rs-base-image                ci-ea6828b430e9f84941104db55cb6d58d201ad145    811268820b1a    59 seconds ago    linux/arm64    4.57GB     1.564GB
smithy-rs-build-image               latest                                         b66608bb54c3    3 days ago        linux/arm64    4.571GB    1.564GB
smithy-rs-base-image                ci-d4053cbdd4e82adff099eb2f4e6cbaae2139d577    2c1a924209b3    3 days ago        linux/arm64    6.663GB    2.223GB
ghcr.io/github/github-mcp-server    latest                                         9cd2504664e1    2 months ago      linux/arm64    46.25MB    13.08MB

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@github-actions
Copy link

A new generated diff is ready to view.

  • No codegen difference in the AWS SDK
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

@aajtodd aajtodd marked this pull request as ready for review August 18, 2025 15:49
@aajtodd aajtodd requested review from a team as code owners August 18, 2025 15:49
Copy link
Contributor

@ysaito1001 ysaito1001 left a comment

Choose a reason for hiding this comment

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

Nice!

Looks like it's successfully past where the previous dry-run failed
https://github.com/smithy-lang/smithy-rs/actions/runs/17045658453/job/48325493577#step:5:592

@aajtodd aajtodd merged commit 520d073 into main Aug 18, 2025
45 checks passed
@aajtodd aajtodd deleted the aajtodd/optimize-dockerfile branch August 18, 2025 17:19
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.

2 participants