8000 feat: Add workflow to build multiarch images by mathbunnyru · Pull Request #2307 · XRPLF/clio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: Add workflow to build multiarch images #2307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions .github/actions/build_docker_image/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ inputs:
description: The directory containing the Dockerfile
required: true
tags:
description: Comma separated tags to apply to the image
description: Newline separated tags to apply to the image
required: true
platforms:
description: Platforms to build the image for (e.g. linux/amd64,linux/arm64)
required: true
build_args:
description: List of build-time variables
description: Newline separated list of build-time variables
required: false

dockerhub_repo:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build_clio_docker_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
tags:
required: true
type: string
description: Comma separated tags for docker image
description: Newline separated tags for docker image
artifact_name:
type: string
description: Name of Github artifact to put into docker image
Expand All @@ -24,7 +24,7 @@ on:
tags:
required: true
type: string
description: Comma separated tags for docker image
description: Newline separated tags for docker image
clio_server_binary_url:
required: true
type: string
Expand Down
132 changes: 132 additions & 0 deletions .github/workflows/multiarch_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: Multi-architecture Docker Image Builder

on:
workflow_call:
inputs:
image_name:
description: "Base name of the image"
required: true
type: string
directory:
description: "Directory containing the Dockerfile"
required: true
type: string
tags:
description: "Newline separated tags to apply to the image"
required: true
type: string
build_args:
description: "Additional build arguments for Docker"
required: false
type: string
default: ""

env:
GHCR_REPO: ghcr.io/${{ github.repository_owner }}

jobs:
build:
name: Build and push ${{ inputs.image_name }} image (${{ matrix.arch }})
runs-on: ${{ matrix.runs-on }}
strategy:
matrix:
include:
- arch: amd64
runs-on: heavy
platform: linux/amd64
- arch: arm64
runs-on: heavy-arm64
platform: linux/arm64

steps:
- uses: actions/checkout@v4

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@ed68ef82c095e0d48ec87eccea555d944a631a4c # v46.0.5
with:
files: "${{ inputs.directory }}/**"

- name: Prepare tags
run: |
TAGS=""
while IFS= read -r tag
do
# Remove leading and trailing whitespace
tag=$(echo "$tag" | xargs)
# Skip empty tags
if [ -z "$tag" ]; then
continue
fi
TAGS="type=raw,value=${{ matrix.arch }}-$tag\n$TAGS"
done < <(printf '%s\n' "${{ inputs.tags }}")

echo "TAGS=$TAGS" >> $GITHUB_ENV

- uses: ./.github/actions/build_docker_image
if: steps.changed-files.outputs.any_changed == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
images: |
${{ env.GHCR_REPO }}/${{ inputs.image_name }}
push_image: ${{ github.event_name != 'pull_request' }}
directory: ${{ inputs.directory }}
tags: ${{ env.TAGS }}
platforms: ${{ matrix.platform }}
build_args: ${{ inputs.build_args }}

merge:
name: Merge and push multi-arch ${{ inputs.image_name }} image
runs-on: heavy
needs: build

steps:
- uses: actions/checkout@v4

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@ed68ef82c095e0d48ec87eccea555d944a631a4c # v46.0.5
with:
files: "${{ inputs.directory }}/**"

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Make GHCR_REPO lowercase
run: |
echo "GHCR_REPO_LC=$(echo ${{ env.GHCR_REPO }} | tr '[:upper:]' '[:lower:]')" >> ${GITHUB_ENV}

- name: Prepare manifest arguments
run: |
MANIFEST_ARGS=""
echo "${{ inputs.tags }}" | while read -r tag; do
# Remove leading and trailing whitespace
tag=$(echo "$tag" | xargs)
# Skip empty tags
if [ -z "$tag" ]; then
continue
fi
while IFS= read -r image_tag; do
MANIFEST_ARGS="$MANIFEST_ARGS --amend ${{ env.GHCR_REPO_LC }}/${{ inputs.image_name }}:${image_tag}"
done < <(printf '%s\n' "${{ inputs.tags }}")
done

echo "MANIFEST_ARGS=$MANIFEST_ARGS" >> $GITHUB_ENV

- name: Create and push multi-arch manifest
if: github.event_name != 'pull_request' && steps.changed-files.outputs.any_changed == 'true'
run: |
export image=${{ env.GHCR_REPO_LC }}/${{ inputs.image_name }}
docker buildx imagetools create \
$MANIFEST_ARGS \
$image:arm64-latest \
$image:amd64-latest
Loading
Loading
0