From a9461898391c33b5f27c7c7b7fdec18f6109ca89 Mon Sep 17 00:00:00 2001 From: Sanjay Vasandani Date: Fri, 23 Feb 2024 10:36:58 -0800 Subject: [PATCH] Fix push-images workflow failing due to low disk space. (#1497) --- .github/actions/mount-scratch-disk/action.yml | 37 +++++++++++++++++++ .github/workflows/build-test.yml | 16 +++----- .github/workflows/push-images.yml | 13 ++++++- 3 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 .github/actions/mount-scratch-disk/action.yml diff --git a/.github/actions/mount-scratch-disk/action.yml b/.github/actions/mount-scratch-disk/action.yml new file mode 100644 index 00000000000..977d3d01949 --- /dev/null +++ b/.github/actions/mount-scratch-disk/action.yml @@ -0,0 +1,37 @@ +# Copyright 2024 The Cross-Media Measurement Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Mount scratch disk +description: > + Create a bind mount for scratch disk space. + + Note that this is a hack to utilize the currently largely unused space at + /mnt. This is relying on undocumented behavior that may change. +inputs: + mount-path: + description: Path to mount scratch disk + required: true +runs: + using: composite + steps: + - shell: bash + env: + MOUNT_PATH: ${{ inputs.mount-path }} + run: | + dir_name="$(printf '%s' "$MOUNT_PATH" | sha256sum | cut -d ' ' -f 1)" + source_path="/mnt/${dir_name}" + mkdir -p "$MOUNT_PATH" + sudo mkdir -p "${source_path}" + sudo chown 'runner:runner' "${source_path}" + sudo mount --bind "${source_path}" "$MOUNT_PATH" diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 664d927c5a3..14c67a79d17 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -89,18 +89,12 @@ jobs: repo_cache_path="$(bazelisk info repository_cache)" echo "repo-cache-path=${repo_cache_path}" >> $GITHUB_OUTPUT - # This is a hack to utilize the undocumented relatively large empty - # scratch disk mounted at /mnt. It's currently needed to work around - # bazel-contrib/rules_oci#439 as that's what is pushing our usage over the - # limit. The alternative is to use a runner with more disk space. + # Hack to work around disk space consumed by bazel-contrib/rules_oci#439. + # The alternative is to use a runner with more disk space. - name: Mount scratch disk - env: - BAZEL_CACHE_PATH: ${{ steps.get-cache-params.outputs.cache-path }} - run: | - mkdir -p "$BAZEL_CACHE_PATH" - sudo mkdir -p /mnt/bazel-cache - sudo chown 'runner:runner' /mnt/bazel-cache - sudo mount --bind /mnt/bazel-cache "$BAZEL_CACHE_PATH" + uses: ./.github/actions/mount-scratch-disk + with: + mount-path: ${{ steps.get-cache-params.outputs.cache-path }} - name: Restore repository cache uses: actions/cache/restore@v4 diff --git a/.github/workflows/push-images.yml b/.github/workflows/push-images.yml index 3fff003bd79..a7ca9c1854c 100644 --- a/.github/workflows/push-images.yml +++ b/.github/workflows/push-images.yml @@ -29,10 +29,11 @@ jobs: image-tag: ${{ steps.get-image-tag.outputs.image-tag }} permissions: id-token: write + packages: write env: CONTAINER_REGISTRY: ghcr.io steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: ./.github/actions/free-disk-space @@ -72,6 +73,16 @@ jobs: repo_cache_path="$(bazelisk info repository_cache)" echo "repo-cache-path=${repo_cache_path}" >> $GITHUB_OUTPUT + cache_path="$(bazelisk info output_base)" + echo "cache-path=${cache_path}" >> $GITHUB_OUTPUT + + # Hack to work around disk space consumed by bazel-contrib/rules_oci#439. + # The alternative is to use a runner with more disk space. + - name: Mount scratch disk + uses: ./.github/actions/mount-scratch-disk + with: + mount-path: ${{ steps.get-cache-params.outputs.cache-path }} + - name: Restore repository cache uses: actions/cache/restore@v4 with: