-
Notifications
You must be signed in to change notification settings - Fork 2
145 lines (130 loc) · 4.68 KB
/
buildImageRdmaTools.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
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