.github/workflows/buildImageRdmaTools.yaml #9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Image Rdma Tools | |
env: | |
IMAGE_NAME: rdma-tools | |
IMAGE_REPO: ${{ github.repository }} | |
ONLINE_REGISTER: ghcr.io | |
BUILD_PLATFORM: linux/amd64,linux/arm64 | |
ONLINE_REGISTER_USER: ${{ github.actor }} | |
ONLINE_REGISTER_PASSWORD: ${{ secrets.GITHUB_TOKEN }} | |
DOCKERFILE_PATH: rdma-tools/image | |
on: | |
push: | |
tags: | |
- rdma-tools-v[0-9]+.[0-9]+.[0-9]+ | |
pull_request_target: | |
types: | |
- opened | |
- synchronize | |
- reopened | |
paths: | |
# can not use env here | |
- network-tools/image/** | |
workflow_dispatch: | |
inputs: | |
ref: | |
description: 'sha, branch or tag for code' | |
required: true | |
default: main | |
imageTag: | |
description: 'image tag' | |
required: true | |
default: v1.0.0 | |
permissions: write-all | |
jobs: | |
build-and-push: | |
timeout-minutes: 30 | |
environment: release-base-images | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up Docker Buildx | |
uses: docker/[email protected] | |
- name: Inspect builder | |
run: | | |
echo "Name: ${{ steps.buildx.outputs.name }}" | |
echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}" | |
echo "Status: ${{ steps.buildx.outputs.status }}" | |
echo "Flags: ${{ steps.buildx.outputs.flags }}" | |
echo "Platforms: ${{ steps.buildx.outputs.platforms }}" | |
- name: Set up QEMU | |
id: qemu | |
uses: docker/[email protected] | |
- name: Get Code Version Before Checkout | |
id: get_event_version | |
continue-on-error: false | |
run: | | |
echo '${{ toJSON(github) }}' | |
if ${{ github.event_name == 'workflow_dispatch' }}; then | |
echo "call by workflow_dispatch" | |
echo "code_sha=${{ github.event.inputs.ref }}" >> $GITHUB_ENV | |
echo "image_tag=${{ github.event.inputs.imageTag }}" >> $GITHUB_ENV | |
echo "push_image=true" >> $GITHUB_ENV | |
elif ${{ github.event_name == 'push' }} ; then | |
echo "call by push tag" | |
image_tag=${GITHUB_REF##*/} | |
image_tag=$( grep -o -E "v[0-9]+.[0-9]+.[0-9]+" <<< "${image_tag}" ) | |
echo "code_sha=${GITHUB_REF##*/}" >> $GITHUB_ENV | |
echo "image_tag=${image_tag}" >> $GITHUB_ENV | |
echo "push_image=true" >> $GITHUB_ENV | |
else | |
echo "call by PR" | |
echo "use sha ${{ github.event.pull_request.head.sha }} , by pr" | |
echo "code_sha=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV | |
echo "push_image=false" >> $GITHUB_ENV | |
fi | |
- name: Checkout Source Code | |
uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
# fetch-depth: 0 | |
ref: ${{ env.code_sha }} | |
- name: Login to online register | |
uses: docker/[email protected] | |
with: | |
username: ${{ env.ONLINE_REGISTER_USER }} | |
password: ${{ env.ONLINE_REGISTER_PASSWORD }} | |
registry: ${{ env.ONLINE_REGISTER }} | |
- name: Release build ${{ env.IMAGE_NAME }} | |
uses: docker/[email protected] | |
continue-on-error: false | |
id: docker_build_release | |
with: | |
context: ./${{ env.DOCKERFILE_PATH }} | |
file: ./${{ env.DOCKERFILE_PATH }}/Dockerfile | |
push: ${{ env.push_image }} | |
provenance: false | |
github-token: ${{ secrets.WELAN_PAT }} | |
platforms: ${{ env.BUILD_PLATFORM }} | |
tags: | | |
${{ env.ONLINE_REGISTER }}/${{ env.IMAGE_REPO }}/${{ env.IMAGE_NAME }}:${{ env.image_tag }} | |
- name: Image Release Digest | |
shell: bash | |
run: | | |
mkdir -p image-digest/ | |
echo "## ${{ env.IMAGE_NAME }}" > image-digest/${{ env.IMAGE_NAME }}.txt | |
echo "" >> image-digest/${{ env.IMAGE_NAME }}.txt | |
echo "\`${{ env.ONLINE_REGISTER }}/${{ env.IMAGE_REPO }}/${{ env.IMAGE_NAME }}:${{ env.image_tag }}@${{ steps.docker_build_release.outputs.digest }}\`" >> image-digest/${{ env.IMAGE_NAME }}.txt | |
echo "" >> image-digest/${{ env.IMAGE_NAME }}.txt | |
- name: Upload artifact digests | |
uses: actions/[email protected] | |
with: | |
name: image-digest ${{ env.IMAGE_NAME }} | |
path: image-digest | |
retention-days: 1 | |
image-digests: | |
name: Display Digests | |
runs-on: ubuntu-latest | |
needs: build-and-push | |
steps: | |
- name: Downloading Image Digests | |
shell: bash | |
run: | | |
mkdir -p image-digest/ | |
- name: Download digests of all images built | |
uses: actions/download-artifact@v3 | |
with: | |
path: image-digest/ | |
- name: Image Digests Output | |
shell: bash | |
run: | | |
cd image-digest/ | |
find -type f | sort | xargs -d '\n' cat |