-
Notifications
You must be signed in to change notification settings - Fork 0
222 lines (208 loc) · 9.4 KB
/
docker-image.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
218
219
220
221
222
name: Docker Image CI
on:
push:
branches: ["main", "dev*", "dev/*", "fix*", "fix/*"]
tags: ["*.*.*"]
jobs:
build:
strategy:
fail-fast: false
matrix:
image: [
{
ver: "6.0",
arch: alpine3.20,
matching: "6.0",
tags: "6.0-alpine3.20,6.0-alpine,latest",
},
{
ver: "6.0",
arch: bullseye-slim,
matching: "6.0",
tags: "6.0-bullseye-slim",
},
{
ver: "6.0",
arch: bookworm-slim,
matching: "6.0",
tags: "6.0-bookworm-slim",
},
{ ver: "6.0", arch: focal, matching: "6.0", tags: "6.0-focal" },
{ ver: "6.0", arch: jammy, matching: "6.0", tags: "6.0-jammy" },
{
ver: "8.0",
arch: alpine3.20,
matching: "8.0",
tags: "8.0-alpine,8.0-alpine3.20",
},
{
ver: "8.0",
arch: bookworm-slim,
matching: "8.0",
tags: "8.0-bookworm-slim",
},
{ ver: "8.0", arch: jammy, matching: "8.0", tags: "8.0-jammy" },
{ ver: "8.0", arch: noble, matching: "8.0", tags: "8.0-noble" },
# {
# ver: "8.0",
# arch: azurelinux3.0,
# matching: "8.0",
# tags: "8.0-azurelinux3.0",
# },
# { ver: 8.0-preview, arch: jammy-chiseled, matching: "8.0.0-preview" },
{
ver: "9.0",
arch: alpine3.20,
matching: "9.0",
tags: "9.0-alpine,9.0-alpine3.20,9.0",
},
{
ver: "9.0",
arch: bookworm-slim,
matching: "9.0",
tags: "9.0-bookworm-slim",
},
{ ver: "9.0", arch: noble, matching: "9.0", tags: "9.0-noble" },
# {
# ver: "9.0",
# arch: azurelinux3.0,
# matching: "9.0",
# tags: "9.0-azurelinux3.0",
# },
# {
# ver: 10.0-preview,
# arch: alpine3.20,
# matching: "10.0.0-preview",
# tags: "10.0-alpine,10.0-preview-alpine,10.0-preview,10.0-alpine3.20,10.0",
# },
# {
# ver: 10.0-preview,
# arch: bookworm-slim,
# matching: "10.0.0-preview",
# tags: "10.0-preview-bookworm-slim,10.0-bookworm-slim",
# },
# {
# ver: 10.0-preview,
# arch: noble,
# matching: "10.0.0-preview",
# tags: "10.0-preview-noble,10.0-noble",
# },
]
name: ${{ matrix.image.ver }}-${{ matrix.image.arch }}
runs-on: ubuntu-latest
env:
ASPNET_VERSION: ${{ matrix.image.ver }}
IMAGE_TAG: ${{ matrix.image.ver }}-${{ matrix.image.arch }}
SKIP_DOCKER: "false"
IS_TAG: ${{ startsWith(github.ref, 'refs/tags/') }}
IS_SEMVER_TAG: "false"
IS_MULTI_RELEASE: "false"
steps:
- name: Check Tag Ref Multi
if: ${{ env.IS_TAG == 'true' && startsWith(github.ref_name, 'release_') }}
shell: pwsh
run: |
$tagRaw = '${{ github.ref_name }}'.Substring('release_'.Length)
$tokens = $tagRaw -split '_'
foreach($token in $tokens) {
$isMatchVersion = $token.Contains('${{ matrix.image.ver }}')
$pattern = '^(?<version>\d+\.\d+(\.\d+)?)(-(?<preview>[a-zA-Z.]+([\-\.]?\d+)?)([\-\.].*)?)?$'
if (!$isMatchVersion) {
if ($token -match $pattern -And '${{ matrix.image.ver }}' -match $pattern) {
$configVersion = '${{ matrix.image.ver }}' -replace $pattern,'${version}'
$configPreview = '${{ matrix.image.ver }}' -replace $pattern,'${preview}'
$currentVersion = $token -replace $pattern,'${version}'
$currentPreview = $token -replace $pattern,'${preview}'
$isMatchVersion = $currentVersion.StartsWith($configVersion) -And $currentPreview.StartsWith($configPreview)
}
}
if ($isMatchVersion) {
"IS_MULTI_RELEASE=true" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"IS_SEMVER_TAG=true" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"ASPNET_VERSION=$token" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"IMAGE_TAG=$token-${{ matrix.image.arch }}" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
Write-Output "Update $token-${{ matrix.image.arch }} for ${{ env.IMAGE_TAG }}"
}
}
- name: Check Tag Ref
if: ${{ success() && env.IS_MULTI_RELEASE != 'true' }}
run: |
SKIP_DOCKER=${{ env.SKIP_DOCKER }}
IS_SEMVER_TAG=${{ env.IS_SEMVER_TAG }}
IS_TAG=${{ env.IS_TAG }}
if [ "$IS_TAG" == 'true' ]; then
if [[ '${{ github.ref_name }}' =~ ^([0-9]+\.[0-9]+(\.[0-9]+)?(-.+)?)$ ]]; then
IS_SEMVER_TAG=true
echo "IS_SEMVER_TAG=$IS_SEMVER_TAG" >> $GITHUB_ENV
if [[ '${{ github.ref_name }}' != *'${{ matrix.image.matching }}'* ]]; then
SKIP_DOCKER=true
echo "SKIP_DOCKER=$SKIP_DOCKER" >> $GITHUB_ENV
echo "Disable docker build for SemVer config ${{ matrix.image.ver }} on ${{ github.ref_name }}"
else
echo "ASPNET_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
echo "IMAGE_TAG=${{ github.ref_name }}-${{ matrix.image.arch }}" >> $GITHUB_ENV
echo "Update SemVer ASPNET_VERSION to ${{ github.ref_name }}"
fi
fi
fi
if [ $IS_SEMVER_TAG != true ] && [ $SKIP_DOCKER != true ]; then
DOCKER_IMAGE=mcr.microsoft.com/dotnet/aspnet:$ASPNET_VERSION
docker pull $DOCKER_IMAGE
ASPNET_VERSION=$(docker inspect $DOCKER_IMAGE --format "{{ index (index .Config.Env) }}" | tr ' ' '\n' | grep ASPNET_VERSION= | sed 's/^.*=//' | sed 's/]$//')
echo "ASPNET_VERSION=$ASPNET_VERSION" >> $GITHUB_ENV
echo "IMAGE_TAG=${ASPNET_VERSION}-${{ matrix.image.arch }}" >> $GITHUB_ENV
echo "Update Non-SemVer ASPNET_VERSION to $ASPNET_VERSION"
fi
- name: Update Image Tag
if: ${{ success() && env.SKIP_DOCKER != 'true' && env.IS_SEMVER_TAG !='true' && ( contains(env.ASPNET_VERSION, '-preview.') || contains(env.ASPNET_VERSION, '-rc.') ) }}
shell: pwsh
run: |
$aspnetVersion = '${{ env.ASPNET_VERSION }}'
# 8.0.0-preview.7.23375.9
$pattern = '^(?<version>\d+\.\d+(\.\d+)?)(-(?<preview>[a-zA-Z.]+([\-\.]?\d+)?)([\-\.].*)?)?$'
if ($aspnetVersion -match $pattern) {
$newVersionImageTag = $aspnetVersion -replace $pattern,'${version}-${preview}'
$newImageTag = "$newVersionImageTag-${{ matrix.image.arch }}"
Write-Host "ASPNET Version: $aspnetVersion"
Write-Host "New IMAGE_TAG: $newImageTag"
"IMAGE_TAG=$newImageTag" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
}
- uses: actions/checkout@v4
if: ${{ success() && env.SKIP_DOCKER != 'true' && github.event_name != 'pull_request' }}
- name: Docker meta
id: meta
if: ${{ success() && env.SKIP_DOCKER != 'true' && github.event_name != 'pull_request' }}
uses: docker/metadata-action@v5
with:
images: netlah/aspnet-webssh
tags: |
type=match,enable=true,priority=900,prefix=,suffix=,pattern=^(\d+\.\d+(\.\d+)?(-.+)?)$,group=1
type=sha,enable=true,priority=600,prefix=sha-,suffix=,format=short
type=ref,event=branch,priority=500,prefix=,suffix=
- name: Enabling Docker Daemon With experimental features
if: ${{ success() && env.SKIP_DOCKER != 'true' && github.event_name != 'pull_request' }}
run: |
echo 'Before update daemon.json'
sudo cat /etc/docker/daemon.json
sudo bash -c 'echo "{ "\""exec-opts"\"": ["\""native.cgroupdriver=cgroupfs"\""], "\""cgroup-parent"\"": "\""/actions_job"\"", "\""experimental"\"": true }" > /etc/docker/daemon.json'
echo 'After update daemon.json'
sudo cat /etc/docker/daemon.json
sudo systemctl restart docker.service
- name: Set up Docker Buildx
if: ${{ success() && env.SKIP_DOCKER != 'true' && github.event_name != 'pull_request' }}
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
if: ${{ success() && env.SKIP_DOCKER != 'true' && github.event_name != 'pull_request' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Build and push
if: ${{ success() && env.SKIP_DOCKER != 'true' && github.event_name != 'pull_request' }}
shell: pwsh
run: |
if ('${{ env.IS_SEMVER_TAG }}' -eq $true) { $repos += @('netlah/aspnet-webssh') }
$repos += @('${{ secrets.DOCKER_HUB_REPOS }}')
./docker-build.ps1 -imageTag ${{ env.IMAGE_TAG }} -dockerRepository $repos -Squash -Labels $(@'
${{ steps.meta.outputs.labels }}
'@.Trim()) -Tags '${{ matrix.image.tags }}' -Verbose