-
Notifications
You must be signed in to change notification settings - Fork 35
209 lines (186 loc) · 7.59 KB
/
manual-kubespray-release.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
name: spray artifact patch
on:
workflow_dispatch:
inputs:
branch:
type: string
description: 'branch of Kubespray'
required: true
commit_SHA1:
type: string
description: 'full commit SHA1 in which the branch located'
jobs:
check-inputs:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.check_inputs.outputs.tag }}
image_repo: ${{ steps.check_inputs.outputs.image_repo }}
spray_sha1: ${{ steps.check_inputs.outputs.spray_sha1 }}
spray_sha1_short: ${{ steps.check_inputs.outputs.spray_sha1_short }}
spray_release_num: ${{ steps.check_inputs.outputs.spray_release_num }}
spray_commit_timestamp: ${{ steps.check_inputs.outputs.spray_commit_timestamp }}
steps:
- name: ensure valid branch and commit
id: check_inputs
run: |
set -x
INPUTS_SPRAY_BRANCH=${{ inputs.branch }}
INPUTS_COMMIT_SHA1=${{ inputs.commit_SHA1 }}
SPRAY_BRANCH_SHA1=`git ls-remote -h https://github.com/kubernetes-sigs/kubespray.git ${INPUTS_SPRAY_BRANCH} | awk '{print $1}'`
if [[ -z "${SPRAY_BRANCH_SHA1}" ]]; then
echo "The specified branch '${INPUTS_SPRAY_BRANCH}' is nonexistent!" && exit 1
fi
SPRAY_SHA1=${SPRAY_BRANCH_SHA1}
git clone -b ${INPUTS_SPRAY_BRANCH} https://github.com/kubernetes-sigs/kubespray.git && cd kubespray
if [[ -n "${INPUTS_COMMIT_SHA1}" ]]; then
if [[ ${#INPUTS_COMMIT_SHA1} != 40 ]]; then
echo "Please specify the full commit SHA1!" && exit 1
fi
if ! git log --pretty="%H" | grep -q ${INPUTS_COMMIT_SHA1}; then
echo "The specifired commit SHA1 '${INPUTS_COMMIT_SHA1}' is not found in branch '${INPUTS_SPRAY_BRANCH}'"
fi
SPRAY_SHA1=${INPUTS_COMMIT_SHA1}
fi
ORGANIZATION_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F "/" '{print $1}' | tr '[:upper:]' '[:lower:]')
if [[ "${INPUTS_SPRAY_BRANCH}" == release-* ]]; then
TAG=${INPUTS_SPRAY_BRANCH#release-}-${SPRAY_SHA1:0:7}
else
TAG=${SPRAY_SHA1:0:7}
fi
echo image_repo=${ORGANIZATION_NAME} >> $GITHUB_OUTPUT
echo tag=${TAG} >> $GITHUB_OUTPUT
echo spray_sha1=${SPRAY_SHA1} >> $GITHUB_OUTPUT
echo spray_sha1_short=${SPRAY_SHA1:0:7} >> $GITHUB_OUTPUT
echo spray_release_num=${INPUTS_SPRAY_BRANCH#release-} >> $GITHUB_OUTPUT
echo spray_commit_timestamp=$(git show -s --format=%ct ${SPRAY_SHA1}) >> $GITHUB_OUTPUT
build-kubespray-image:
needs: check-inputs
uses: ./.github/workflows/call-build-imgs-for-spray.yaml
secrets: inherit
permissions:
packages: write
contents: read
with:
SPRAY_REF: ${{ needs.check-inputs.outputs.spray_sha1 }}
REPO: ${{ needs.check-inputs.outputs.image_repo }}
build-sprayjob-image:
needs: [check-inputs, build-kubespray-image]
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: sprayjob image build
uses: docker/[email protected]
with:
context: ./
file: build/images/spray-job/Dockerfile
build-args: |
SPRAY_TAG=${{ needs.check-inputs.outputs.spray_sha1_short }}
REPO=${{ needs.check-inputs.outputs.image_repo }}
SPRAY_COMMIT=${{ needs.check-inputs.outputs.spray_sha1_short }}
SPRAY_RELEASE=${{ needs.check-inputs.outputs.spray_release_num }}
SPRAY_COMMIT_TIMESTAMP=${{ needs.check-inputs.outputs.spray_commit_timestamp }}
github-token: ${{ secrets.GITHUB_TOKEN }}
push: true
provenance: false
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/${{ needs.check-inputs.outputs.image_repo }}/spray-job:${{ needs.check-inputs.outputs.tag }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-airgap-patch-image:
needs: [check-inputs, build-kubespray-image]
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: airgap-patch image build
uses: docker/[email protected]
with:
context: ./
file: build/images/airgap-patch/Dockerfile
build-args: |
SPRAY_TAG=${{ needs.check-inputs.outputs.spray_sha1_short }}
REPO=${{ needs.check-inputs.outputs.image_repo }}
SPRAY_COMMIT=${{ needs.check-inputs.outputs.spray_sha1_short }}
SPRAY_RELEASE=${{ needs.check-inputs.outputs.spray_release_num }}
SPRAY_COMMIT_TIMESTAMP=${{ needs.check-inputs.outputs.spray_commit_timestamp }}
github-token: ${{ secrets.GITHUB_TOKEN }}
push: true
provenance: false
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/${{ needs.check-inputs.outputs.image_repo }}/airgap-patch:${{ needs.check-inputs.outputs.tag }}
cache-from: type=gha
cache-to: type=gha,mode=max
gen-manifest:
needs: check-inputs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Git clone kubespray repo
uses: actions/checkout@v3
with:
repository: kubernetes-sigs/kubespray
ref: ${{ needs.check-inputs.outputs.spray_sha1 }}
path: ./kubespray
fetch-depth: 0
- name: Install yq tool
uses: mikefarah/[email protected]
- name: Generate Kubean manifest file
env:
SPRAY_TAG: ${{ needs.check-inputs.outputs.spray_sha1 }}
SPRAY_COMMIT: ${{ needs.check-inputs.outputs.spray_sha1_short }}
SPRAY_RELEASE: ${{ needs.check-inputs.outputs.spray_release_num }}
SPRAY_COMMIT_TIMESTAMP: ${{ needs.check-inputs.outputs.spray_commit_timestamp }}
run: |
bash artifacts/manage_version_cr.sh create_manifest
mkdir manifest && cp charts/kubean/templates/manifest.cr.yaml manifest/manifest-${{ needs.check-inputs.outputs.tag }}.yml
echo "manifest cr output:"
cat manifest/manifest-${{ needs.check-inputs.outputs.tag }}.yml
- name: Push Kubean manifest to another repository
env:
REPO_OWNER: ${{ github.repository_owner }}
SSH_DEPLOY_KEY: ${{ secrets.SYNC_MANIFEST_PRIVATE_KEY }}
TAG: ${{ needs.check-inputs.outputs.tag }}
run: |
./hack/sync-manifest.sh
show-artifacts:
needs: [check-inputs, build-kubespray-image, build-sprayjob-image, build-airgap-patch-image, gen-manifest]
runs-on: ubuntu-latest
steps:
- name: output artifacts
run: |
echo "ghcr.io/${{ needs.check-inputs.outputs.image_repo }}/spray-job:${{ needs.check-inputs.outputs.tag }}"
echo "ghcr.io/${{ needs.check-inputs.outputs.image_repo }}/airgap-patch:${{ needs.check-inputs.outputs.tag }}"
echo "https://github.com/kubean-io/kubean-manifest/blob/main/manifests/manifest-${{ needs.check-inputs.outputs.tag }}.yml"