Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/build_image_cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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: Image Cache

# Security: write privileges are safe since this is triggered only by
# `push` and `workflow_dispatch` (implying user has write access).
on:
# Run jobs when a commit is merged
push:
branches:
- 'trunk'
- 'branch-*'
paths:
- 'dev-support/docker/**'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cool. Makes sense to rebuild when anything in here changes. In the future we might just publish an image and use it directly instead of always doing a cached build? We can iterate on it though. 👍

Copy link
Copy Markdown
Member Author

@pan3793 pan3793 Apr 24, 2026

Choose a reason for hiding this comment

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

I think the cache is better.

  1. in most cases, no docker file change, cache hit and it works well
  2. if trunk merges a PR that has docker files change, it will take ~15min to refresh the cache, a new push happens in the forked PR will miss cache and do a refresh build
  3. if a PR itself contains docker files change, it must do a fresh build

workflow_dispatch:
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

both push and workflow_dispatch indicate the person has write permission on the repo, so it's safe.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agreed. It is a "trusted" action. (We still are careful to use best practices below, and our CodeQL scanning helps enforce that in the future.)


jobs:
build-image-cache-ubuntu_24:
permissions:
packages: write
name: Run
uses: ./.github/workflows/tmpl_build_image_cache.yml
with:
os: ubuntu_24
build-image-cache-debian_13:
permissions:
packages: write
name: Run
uses: ./.github/workflows/tmpl_build_image_cache.yml
with:
os: debian_13
build-image-cache-rockylinux_8:
permissions:
packages: write
name: Run
uses: ./.github/workflows/tmpl_build_image_cache.yml
with:
os: rockylinux_8
1 change: 1 addition & 0 deletions .github/workflows/tmpl_build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ jobs:
file: ./dev-support/docker/Dockerfile_${{ inputs.os }}
push: true
tags: ${{ needs.precondition.outputs.build_image_url }}-base
cache-from: type=registry,ref=ghcr.io/apache/hadoop/gha-build-${{ inputs.os }}-image-cache:${{ inputs.branch }}
- name: User-specific Dockerfile
run: |
USER_ID=$(id -u "${USER}")
Expand Down
62 changes: 62 additions & 0 deletions .github/workflows/tmpl_build_image_cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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: Build Image Cache

on:
workflow_call:
inputs:
os:
required: false
type: string
description: Operating system to create build image cache for.
default: ubuntu_24

# Default to minimal permissions for workflow.
permissions:
packages: read

jobs:
main:
name: build-image-cache-${{ inputs.os }}-${{ github.ref_name }}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

github.ref_name is the branch name for push event

if: github.repository == 'apache/hadoop'
runs-on: ubuntu-24.04
permissions:
packages: write
steps:
- name: Checkout Hadoop repository
uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
- name: Login to DockerHub
uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4.0.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build image cache for ${{ inputs.os }}-${{ github.ref_name }}
id: docker_build
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7.0.0
with:
context: ./dev-support/docker/
file: ./dev-support/docker/Dockerfile_${{ inputs.os }}
push: true
tags: ghcr.io/apache/hadoop/gha-build-${{ inputs.os }}-image-cache:${{ github.ref_name }}-static
cache-from: type=registry,ref=ghcr.io/apache/hadoop/gha-build-${{ inputs.os }}-image-cache:${{ github.ref_name }}
cache-to: type=registry,ref=ghcr.io/apache/hadoop/gha-build-${{ inputs.os }}-image-cache:${{ github.ref_name }},mode=max
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just getting familiar with this and reading docs. Is this based on the Spark CI workflows?

type=registry (docs)

registry: embeds the build cache into a separate image, and pushes to a dedicated location separate from the main output.

cache-to: exports the cache to a particular backend (registry) after a build. cache-from specifies how to import at start of a build. IIUC the local BuildKit cache is always enabled, but has no persistence between runs, so only helps with multiple builds within the same workflow.

The locations passed in (ref=) act as the key for the cache lookup, and we separate these by OS and branch name.

mode=max means to export all intermediate layers of the image build, whereas mode=min only exports those which end up in the image. This looks good to me. 👍

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Is this based on the Spark CI workflows?

I basically replicate it from Spark.

https://github.com/apache/spark/blob/branch-4.1/.github/workflows/build_infra_images_cache.yml

- name: Image digest for ${{ inputs.os }}-${{ github.ref_name }}
run: echo ${{ steps.docker_build.outputs.digest }}
Loading