-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
210 lines (188 loc) · 7.9 KB
/
action.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
name: Build And Push DDTV Docker images
author: moomiji
description: 'Build And Push DDTV Docker images with build-push-action'
inputs:
push:
description: "Push is a shorthand for --output=type=registry"
required: false
default: 'true'
repo:
description: 'Name of docker image library.'
required: true
os_id:
description: 'Id of os.'
required: true
version:
description: 'Version of DDTV.'
required: true
dotnet-image-version:
description: "Version of dotnet image."
required: true
path:
description: "Path of DDTV build output."
required: true
runtime:
description: "Dotnet runtime identifier" # linux-x64 ..
required: true
runs:
using: "composite"
steps:
- if: github.repository_id == '207967312'
uses: docker/login-action@v3
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_PASSWORD }}
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ github.token }}
- uses: docker/setup-buildx-action@v3
- name: Set GITHUB_ENV
shell: bash
run: |
owner_lower=${GITHUB_REPOSITORY_OWNER,,}
# 匹配如下:[release5.0.200a release 5.0.200a 5.0 5 .0 .200a] (release)(((5)))(.0)(.200a)啊
if [[ "${{ inputs.version }}" =~ ^([a-zA-Z]*)((([0-9]*)(\.[0-9]*)?)([a-zA-Z0-9\._+-]*)).*$ ]]; then
[[ "${{ inputs.runtime }}" == "linux-x64" ]] && echo "::notice title=DDTV Docker::version(${BASH_REMATCH[*]})"
else
echo "::error title=DDTV Docker::${{ inputs.version }} is not a valid version."
exit 1
fi
case "${{ inputs.runtime }}" in
linux*x64) suffix=-amd64; platforms=linux/amd64; ;;
linux*arm64) suffix=-arm64v8; platforms=linux/arm64; ;;
linux*arm) suffix=-arm32v7; platforms=linux/arm/v7; ;;
esac
echo "platforms=$platforms" >> $GITHUB_ENV
echo "tags<<EOF" >> $GITHUB_ENV
echo "${BASH_REMATCH[2]}${{ inputs.os_id == 'debian' && '' || format('-{0}', inputs.os_id) }}" >> $GITHUB_ENV
echo "${BASH_REMATCH[3]}${{ inputs.os_id == 'debian' && '' || format('-{0}', inputs.os_id) }}" >> $GITHUB_ENV
echo "${{ inputs.os_id }}" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "flavor<<EOF" >> $GITHUB_ENV
echo "latest=${{ inputs.os_id == 'debian' }}" >> $GITHUB_ENV
echo "suffix=$suffix,onlatest=true" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "images<<EOF" >> $GITHUB_ENV
if ${{ github.repository_id == '207967312' && !startsWith(inputs.version, 'dev') }}; then
echo "${{ inputs.repo }}" >> $GITHUB_ENV
fi
echo "ghcr.io/$owner_lower/${{ inputs.repo }}" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "REGISTRY_IMAGE=ghcr.io/$owner_lower/${{ inputs.repo }}" >> $GITHUB_ENV
echo "IMAGE_TAG=${BASH_REMATCH[2]}${{ inputs.os_id == 'debian' && '' || format('-{0}', inputs.os_id) }}" >> $GITHUB_ENV
ddtv_deps_image_tag=ghcr.io/$owner_lower/ddtv/deps:${{ inputs.os_id }}$suffix
echo "ddtv_deps_image=ghcr.io/$owner_lower/ddtv/deps" >> $GITHUB_ENV
echo "ddtv_deps_image_tag=$ddtv_deps_image_tag" >> $GITHUB_ENV
docker pull $ddtv_deps_image_tag || true
ddtv_date="$(docker inspect $ddtv_deps_image_tag | jq '. + [{"Created":"1970-01-01T08:00:00"}]' || true)"
echo $ddtv_date
ddtv_date="$(echo "$ddtv_date" | jq -r '.[0] | .Created')"
echo 2
ddtv_date=$(date -d "$ddtv_date" +%s)
echo 3
mcr__date="$(curl https://mcr.microsoft.com/api/v1/catalog/dotnet/runtime-deps/tags?reg=mar | jq -r '.[] | select(.name == "8.0" ) | .lastModifiedDate')"
echo 4
mcr__date=$(date -d "$mcr__date" +%s)
echo 5
file_date=$(cat ${{ github.action_path }}/ddtv/deps/lastModifiedDate)
echo 6
file_date=$(date -d "$file_date" +%s)
echo "ddtv_date: $ddtv_date; mcr__date: $mcr__date; file_date: $file_date"
if [[ "$ddtv_date" -lt "$mcr__date" || "$ddtv_date" -lt "$file_date" ]]; then
echo "need_build_deps=true" >> $GITHUB_ENV
fi
- if: inputs.runtime != '' && env.need_build_deps == 'true'
name: Metadata for deps
id: deps
uses: docker/metadata-action@v5
with:
images: |
${{ env.ddtv_deps_image }}
flavor: |
${{ env.flavor }}
tags: |
${{ github.run_id }}-${{ inputs.os_id }}
${{ inputs.os_id }}
- name: Metadata for image
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.images }}
flavor: |
${{ env.flavor }}
tags: |
${{ env.tags }}
- if: inputs.runtime != ''
name: Prepare
shell: bash
run: |
shopt -s globstar nullglob
cd ${{ github.action_path }}
chmod -v +x ./**/*.sh
cd ./**/"${{ inputs.repo }}"
KeyFile=Core.dll
File_Path=$(find "${{ inputs.path }}" -name "$KeyFile" | awk '{print $1}' FS="/$KeyFile")
mv -v "$File_Path" ./root/DDTV
mv -v ../docker-entrypoint.sh ./root
# mv -v ../*-*.sh ./root/docker-entrypoint.d
- if: inputs.runtime != ''
uses: docker/setup-qemu-action@v3
- if: inputs.runtime != '' && env.need_build_deps == 'true'
name: Build and push by digest
uses: docker/build-push-action@v5
with:
context: ${{ github.action_path }}/ddtv/deps/
file: ${{ github.action_path }}/ddtv/deps/Dockerfile
tags: ${{ steps.deps.outputs.tags }}
push: true
platforms: ${{ env.platforms }}
build-args: REPO=mcr.microsoft.com/dotnet/runtime-deps:${{ inputs.dotnet-image-version }}
- if: inputs.runtime != ''
id: build
name: Build and push by digest
uses: docker/build-push-action@v5
with:
context: ${{ github.action_path }}/${{ inputs.repo }}/
file: ${{ github.action_path }}/${{ inputs.repo }}/Dockerfile
tags: ${{ steps.meta.outputs.tags }}
push: ${{ inputs.push }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ env.platforms }}
build-args: REPO=${{ env.ddtv_deps_image_tag }}
- if: inputs.runtime != '' && inputs.push == 'true'
name: Export digest
shell: bash
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- if: inputs.runtime != '' && inputs.push == 'true'
name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ inputs.os_id }}-${{ inputs.runtime }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
- if: inputs.runtime == '' && inputs.push == 'true'
name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests/${{ inputs.os_id }}
pattern: digests-${{ inputs.os_id }}-*
merge-multiple: true
- if: inputs.runtime == '' && inputs.push == 'true'
name: Create manifest list and push
working-directory: /tmp/digests/${{ inputs.os_id }}
shell: bash
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- if: inputs.runtime == '' && inputs.push == 'true'
name: Inspect image
shell: bash
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ env.IMAGE_TAG }}