-
-
Notifications
You must be signed in to change notification settings - Fork 7
217 lines (183 loc) · 7.34 KB
/
publish-docker-library.yml
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
210
211
212
213
214
215
216
217
name: Publish images to the Docker Library
on:
workflow_dispatch:
inputs:
pr:
description: 'Publish to the Docker Official Library'
required: true
type: boolean
default: true
draft:
description: 'Draft Pull Request'
required: true
type: boolean
env:
# Docker Library Git repository name (upstream): docker-library/official-images
docker_library: docker-library/official-images
# Docker Library Git repository name (local fork): ${{ github.actor }}/official-images or almalinux/docker-library-official-images
local_library: almalinux/docker-library-official-images
# Docker Library Git repository owner (local fork): ${{ github.actor }} or almalinux
library_owner: almalinux
jobs:
prepare-definitions:
name: "${{ matrix.version_major }} ${{ matrix.image_types }} definition preparing"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
image_types:
- default
- minimal
version_major:
- 8
- 9
- 10-kitten
steps:
-
name: Checkout ${{ github.repository }}, branch '${{ matrix.version_major }}'
uses: actions/checkout@v4
with:
ref: ${{ matrix.version_major }}
fetch-depth: 0 # Checkout all commits
-
name: Checkout ${{ env.local_library }}, branch 'master'
uses: actions/checkout@v4
with:
repository: ${{ env.local_library }}
path: official-images
-
name: "Get need data for the definition"
run: |
# Dockerfile for specific version and image type (let's take platform amd64)
platform=amd64
dockerfile=${{ matrix.image_types }}/${platform}/Dockerfile
test -f ${dockerfile}
# The recent commit of the Dockerfile
last_commit=$( git log -1 --format='%H' -- ${dockerfile} )
echo "commit_hash=${last_commit}" >> $GITHUB_ENV
# Get tags from the Dockerfile
tags=$( grep 'Tags:' ${dockerfile} | sed "s/^[[:space:]]*#[[:space:]]*Tags: \(.*\)$/\1/" )
echo "tags=${tags}" >> $GITHUB_ENV
[ -z "$last_commit-x" -o -z "$tags-x" ] && false
echo "[Debug]"
echo "tags=${tags}"
echo "commit_hash=${last_commit}"
-
name: "Render the definition"
uses: chuhlomin/render-template@v1
with:
template: docker-library-definition.tmpl
result_path: official-images/library/almalinux.${{ matrix.version_major }}.${{ matrix.image_types }}
vars: |
tags: ${{ env.tags }}
commit_hash: ${{ env.commit_hash}}
version_major: ${{ matrix.version_major }}
image_type: ${{ matrix.image_types }}
-
name: "[Debug] Check definitions"
run: |
cat official-images/library/almalinux.${{ matrix.version_major }}.${{ matrix.image_types }}
# Upload 'official-images/library/almalinux.*'
- uses: actions/upload-artifact@v4
name: Upload definitions for ${{ matrix.version_major }} ${{ matrix.image_types }}
with:
name: definition-${{ matrix.version_major }}.${{ matrix.image_types }}
path: official-images/library/almalinux.${{ matrix.version_major }}.${{ matrix.image_types }}
push-pr:
if: inputs.pr
name: "Create Pull Request with the new definition file"
runs-on: ubuntu-latest
needs:
- prepare-definitions
steps:
-
name: "Sync ${{ env.local_library }} with ${{ env.docker_library }}, branch 'master'"
run: |
# Sync ${{ env.local_library }} with ${{ env.docker_library }}, branch 'master'
gh auth login --with-token < <(echo ${{ secrets.GIT_HUB_TOKEN }})
gh repo sync ${{ env.local_library }} --force --source ${{ env.docker_library }} --branch master
-
name: Checkout ${{ env.local_library }}, branch 'master'
uses: actions/checkout@v4
with:
repository: ${{ env.local_library }}
path: official-images
token: ${{ secrets.GIT_HUB_TOKEN }}
fetch-depth: 0 # Checkout all commits
# Download uploaded above 'official-images/library/almalinux.*'
- uses: actions/download-artifact@v4
name: Download all definitions
with:
pattern: definition-*
merge-multiple: true
path: official-images/library/
-
name: "Create head of official-images/library/almalinux"
run: |
echo "# This file was generated on ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
Maintainers: The AlmaLinux OS Foundation <[email protected]> (@AlmaLinux)
GitRepo: ${{ github.server_url }}/${{ github.repository }}.git" > official-images/library/almalinux
-
name: "Merge definitions into official-images/library/almalinux"
run: |
# create official-images/library/almalinux
for file in $( ls -1 official-images/library/almalinux.*.* ); do
echo "" >> official-images/library/almalinux
cat $file >> official-images/library/almalinux
done
rm -f official-images/library/almalinux.*.*
echo "[Debug]"
cat official-images/library/almalinux
-
name: "Prepare date stamp"
run: |
# date stamp
date_stamp=$(date -u '+%Y%m%d')
echo "date_stamp=${date_stamp}" >> $GITHUB_ENV
[ -z "$date_stamp-x" ] && false
# [Debug]
echo "date_stamp=${date_stamp}"
-
name: "Prepare time stamp"
run: |
# time stamp
time_stamp=$(date -u '+%H:%M:%S')
echo "time_stamp=${time_stamp}" >> $GITHUB_ENV
[ -z "$time_stamp-x" ] && false
# [Debug]
echo "time_stamp=${time_stamp}"
-
name: "Commit and push official-images/library/almalinux"
uses: EndBug/add-and-commit@v9
with:
cwd: official-images
default_author: user_info
pull: '--rebase --autostash'
message: "AlmaLinux auto-update - ${{ env.date_stamp }} ${{ env.time_stamp }}"
push: true
-
name: Create Pull Request for official-images/library/almalinux
run: |
# create pull request with 'gh pr create'
gh_opts=''
[ "${{ inputs.draft }}" = "true" ] && gh_opts='--draft'
title="Almalinux auto-update - ${{ env.date_stamp }} ${{ env.time_stamp }}"
body="This is an auto-generated commit. Any concern or issues, please contact or email AlmaLinux OS Foundation [email protected] (@AlmaLinux)"
cd official-images
gh auth login --with-token < <(echo ${{ secrets.GIT_HUB_TOKEN }})
prs=$(gh pr list \
--repo ${{ env.docker_library }} \
--base master \
--author ${{ env.library_owner}} \
--json title \
--jq 'length')
echo "${prs} pull request(s) found for the ${{ env.docker_library }} branch master."
if [ $prs -lt 1 ]; then
echo "Create pull request with 'gh pr create'"
gh pr create \
--title "${title}" \
--body "${body}" \
--repo ${{ env.docker_library }} \
--base master \
${gh_opts}
fi