Skip to content
Unverified Commit 520d073c authored by Aaron Todd's avatar Aaron Todd Committed by GitHub
Browse files

optimize docker image layers (#4271)

## Description
[Adding/fixing caching of Gradle
wrapper](https://github.com/smithy-lang/smithy-rs/pull/4270) to our
build image increased it's size beyond 2GB. We started seeing issues
with dry run release and download artifact [silently
failing](https://github.com/actions/download-artifact/issues/396). 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 ✗                                                                                  [91e76ab4]  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._
parent 91e76ab4
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment