Skip to content

Commit d38a6c5

Browse files
authored
Some updates to attempt to optimize our Dockerfile (#4417)
Successfully built locally, now to see if CI passes ## Motivation and Context <!--- Why is this change required? What problem does it solve? --> <!--- If it fixes an open issue, please link to the issue here --> CI for PRs from forks has been [failing on Acquire Build Image](https://github.com/smithy-lang/smithy-rs/actions/runs/19682977713/job/56381464286?pr=4394) with error: ``` Saving base image for use in later jobs... write /home/runner/work/smithy-rs/smithy-rs/.docker_temp_1730454122: no space left on device ``` The image build would succeed, but the task would fail when saving the built image locally. ## Description <!--- Describe your changes in detail --> Attempted to slim down the Dockerfile, but only managed to knock off ~30MB (out of 1.8GB), so not much luck there. Was able to create more room by adding a new action that does: ``` run: | sudo rm -rf /usr/share/dotnet sudo rm -rf "$AGENT_TOOLSDIRECTORY" ``` and deletes some of the included tools we don't use. In my testing this freed up ~5GB which should be enough to allow builds to succeed. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
1 parent 9b22d8e commit d38a6c5

File tree

6 files changed

+27
-15
lines changed

6 files changed

+27
-15
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
name: 'Free Disk Space'
5+
description: 'Free up disk space on GitHub Actions runners'
6+
runs:
7+
using: 'composite'
8+
steps:
9+
- name: Free up disk space
10+
shell: bash
11+
run: |
12+
sudo rm -rf /usr/share/dotnet
13+
sudo rm -rf "$AGENT_TOOLSDIRECTORY"

.github/workflows/ci-main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
3737
- name: Checkout
3838
uses: actions/checkout@v4
39+
- uses: ./.github/actions/free-disk-space
3940
- name: Acquire credentials
4041
uses: aws-actions/configure-aws-credentials@v4
4142
with:

.github/workflows/ci-pr-forks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jobs:
3434
- uses: actions/checkout@v4
3535
with:
3636
path: smithy-rs
37+
- uses: ./smithy-rs/.github/actions/free-disk-space
3738
- name: Acquire base image
3839
id: acquire
3940
env:

.github/workflows/ci-pr.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ jobs:
6969
- uses: actions/checkout@v4
7070
with:
7171
path: smithy-rs
72+
- uses: ./smithy-rs/.github/actions/free-disk-space
7273
- name: Acquire base image
7374
id: acquire
7475
env:

tools/ci-build/.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
target/
2+
*.md
3+
.github/
4+
design/
5+
examples/

tools/ci-build/Dockerfile

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ RUN cargo install --locked --path tools/ci-build/changelogger && \
120120
cargo install --locked --path tools/ci-build/sdk-versioner && \
121121
chmod g+rw -R /opt/cargo/registry && \
122122
rm -rf /opt/cargo/registry/src && \
123-
rm -rf /opt/cargo/git/db
123+
rm -rf /opt/cargo/git/db && \
124+
rm -rf /root/.cargo/registry/cache
124125

125126
FROM install_rust AS cargo_tools
126127
ARG cargo_deny_version=0.16.4
@@ -149,7 +150,8 @@ RUN cargo install cargo-deny --locked --version ${cargo_deny_version} && \
149150
cargo install mdbook --locked --version ${cargo_mdbook_version} && \
150151
cargo install mdbook-mermaid --locked --version ${cargo_mdbook_mermaid_version} && \
151152
rm -rf /opt/cargo/registry/src && \
152-
rm -rf /opt/cargo/git/db
153+
rm -rf /opt/cargo/git/db && \
154+
rm -rf /root/.cargo/registry/cache
153155

154156
# nodejs needed by internal release process
155157
FROM install_rust AS nodejs
@@ -196,6 +198,7 @@ RUN set -eux; \
196198
bc \
197199
ca-certificates \
198200
clang \
201+
cmake \
199202
gcc \
200203
git \
201204
glibc-langpack-en \
@@ -209,7 +212,6 @@ RUN set -eux; \
209212
python3-devel \
210213
python3-pip \
211214
shadow-utils \
212-
cmake \
213215
tar \
214216
unzip && \
215217
yum clean all && \
@@ -226,19 +228,8 @@ RUN set -eux; \
226228

227229
COPY --chown=build:build --from=local_tools /opt/cargo /opt/cargo
228230
COPY --chown=build:build --from=gradle_wrapper /opt/gradle /home/build/.gradle
229-
COPY --chown=build:build --from=cargo_tools /opt/cargo/bin/cargo-deny /opt/cargo/bin/cargo-deny
230-
COPY --chown=build:build --from=cargo_tools /opt/cargo/bin/cargo-udeps /opt/cargo/bin/cargo-udeps
231-
COPY --chown=build:build --from=cargo_tools /opt/cargo/bin/cargo-hack /opt/cargo/bin/cargo-hack
232-
COPY --chown=build:build --from=cargo_tools /opt/cargo/bin/cargo-minimal-versions /opt/cargo/bin/cargo-minimal-versions
233-
COPY --chown=build:build --from=cargo_tools /opt/cargo/bin/cargo-check-external-types /opt/cargo/bin/cargo-check-external-types
234-
COPY --chown=build:build --from=cargo_tools /opt/cargo/bin/maturin /opt/cargo/bin/maturin
235-
COPY --chown=build:build --from=cargo_tools /opt/cargo/bin/wasm-pack /opt/cargo/bin/wasm-pack
236-
COPY --chown=build:build --from=cargo_tools /opt/cargo/bin/wasmtime /opt/cargo/bin/wasmtime
237-
COPY --chown=build:build --from=cargo_tools /opt/cargo/bin/cargo-component /opt/cargo/bin/cargo-component
231+
COPY --chown=build:build --from=cargo_tools /opt/cargo/bin/ /opt/cargo/bin/
238232
COPY --chown=build:build --from=install_rust /opt/rustup /opt/rustup
239-
COPY --chown=build:build --from=cargo_tools /opt/cargo/bin/cargo-semver-checks /opt/cargo/bin/cargo-semver-checks
240-
COPY --chown=build:build --from=cargo_tools /opt/cargo/bin/mdbook /opt/cargo/bin/mdbook
241-
COPY --chown=build:build --from=cargo_tools /opt/cargo/bin/mdbook-mermaid /opt/cargo/bin/mdbook-mermaid
242233
COPY --chown=build:build --from=nodejs /opt/nodejs /opt/nodejs
243234
COPY --chown=build:build --from=musl_toolchain /usr/local/musl/ /usr/local/musl/
244235
ENV PATH=/opt/nodejs/bin:/opt/cargo/bin:$PATH:/usr/local/musl/bin/ \

0 commit comments

Comments
 (0)