-
Notifications
You must be signed in to change notification settings - Fork 0
163 lines (143 loc) · 5.58 KB
/
build-image-base.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
name: Auto Build Image Base
env:
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 }}
on:
pull_request_target:
types:
- opened
- synchronize
- reopened
paths:
# can not use env here
- images/smartdocter-agent-base/**
workflow_dispatch:
inputs:
ref:
description: 'sha, tag, branch'
required: true
default: main
permissions: write-all
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
build-and-push:
timeout-minutes: 30
environment: release-base-images
runs-on: ubuntu-latest
strategy:
matrix:
include:
- name: smartdocter-agent-base
dockerfile: ./images/smartdocter-agent-base/Dockerfile
context: ./images/smartdocter-agent-base
- name: smartdocter-controller-base
dockerfile: ./images/smartdocter-controller-base/Dockerfile
context: ./images/smartdocter-controller-base
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: |
if ${{ github.event_name == 'workflow_dispatch' }}; then
ref=${{ github.event.inputs.ref }}
echo "use re $ref , by workflow_dispatch"
echo ::set-output name=event_ref::${ref}
else
#trigger by pr
echo "use sha ${{ github.event.pull_request.head.sha }} , by pr"
echo ::set-output name=event_ref::${{ github.event.pull_request.head.sha }}
fi
- name: Checkout Source Code
uses: actions/checkout@v3
with:
persist-credentials: false
# fetch-depth: 0
ref: ${{ steps.get_event_version.outputs.event_ref }}
# after checkout code , could get the commit id of path ./images/baseimage , used for base image tag
- name: Generating Base Image Tag
id: base_tag
run: |
echo ::set-output name=tag::"$(git ls-tree --full-tree HEAD -- ${{ matrix.context }} | awk '{ print $3 }')"
# check whether we have upload the same base image to online register , if so, we could not build it
- name: Checking if tag already exists
id: tag-in-repositories
shell: bash
run: |
if docker buildx imagetools inspect ${{ env.ONLINE_REGISTER }}/${{ env.IMAGE_REPO }}/${{ matrix.name }}:${{ steps.base_tag.outputs.tag }} &>/dev/null; then
echo ::set-output name=exists::"true"
echo "the target base image exist , no need to build it "
else
echo ::set-output name=exists::"false"
echo "the target base image does not exist , build it "
fi
- name: Login to online register
if: ${{ steps.tag-in-repositories.outputs.exists == 'false' }}
uses: docker/[email protected]
with:
username: ${{ env.ONLINE_REGISTER_USER }}
password: ${{ env.ONLINE_REGISTER_PASSWORD }}
registry: ${{ env.ONLINE_REGISTER }}
- name: Release build ${{ matrix.name }}
if: ${{ steps.tag-in-repositories.outputs.exists == 'false' }}
uses: docker/[email protected]
continue-on-error: false
id: docker_build_release
with:
context: ${{ matrix.context }}
file: ./${{ matrix.dockerfile }}
push: true
github-token: ${{ secrets.WELAN_PAT }}
platforms: ${{ env.BUILD_PLATFORM }}
tags: |
${{ env.ONLINE_REGISTER }}/${{ env.IMAGE_REPO }}/${{ matrix.name }}:${{ steps.base_tag.outputs.tag }}
- name: Image Release Digest
if: ${{ steps.tag-in-repositories.outputs.exists == 'false' }}
shell: bash
run: |
mkdir -p image-digest/
echo "## ${{ matrix.name }}" > image-digest/${{ matrix.name }}.txt
echo "" >> image-digest/${{ matrix.name }}.txt
echo "\`${{ env.ONLINE_REGISTER }}/${{ env.IMAGE_REPO }}/${{ matrix.name }}:${{ steps.base_tag.outputs.tag }}@${{ steps.docker_build_release.outputs.digest }}\`" >> image-digest/${{ matrix.name }}.txt
echo "" >> image-digest/${{ matrix.name }}.txt
- name: Upload artifact digests
if: ${{ steps.tag-in-repositories.outputs.exists == 'false' }}
uses: actions/[email protected]
with:
name: image-digest-${{ matrix.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/[email protected]
with:
path: image-digest/
- name: Image Digests Output
shell: bash
run: |
cd image-digest/
find -type f | sort | xargs -d '\n' cat