-
Notifications
You must be signed in to change notification settings - Fork 0
212 lines (187 loc) · 8.35 KB
/
docker.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
name: Build Docker Image
on:
push:
branches:
- "dev/**"
- "main"
- "rel/**"
paths:
- "**.cs"
- "**.csproj"
- "**.json"
- "**.props"
- "**.sln"
- "CHANGELOG.md"
- "**.Dockerfile"
- "**/docker.yml"
workflow_dispatch:
schedule:
# once a day at 02:00 UTC to cleanup old runs
- cron: "0 2 * * *"
permissions:
actions: write
checks: write
contents: read
jobs:
cleanup:
name: Cleanup Runs
if: ${{ github.event_name == 'schedule' }}
uses: dotnet/arcade/.github/workflows/scheduled-action-cleanup-base.yml@main
with:
repository_owners: ${{ github.repository_owner }}
extract_meta:
name: Extract metadata for use
if: ${{ github.event_name != 'schedule' }}
runs-on: ubuntu-24.04
outputs:
environment: ${{ steps.get-environment.outputs.environment }}
environment_alpine: ${{ steps.get-environment.outputs.environment_alpine }}
config: ${{ steps.get-config.outputs.config }}
dockerfile: ${{ steps.get-dockerfile.outputs.dockerfile }}
dockerfile_alpine: ${{ steps.get-dockerfile.outputs.dockerfile_alpine }}
datetime: ${{ steps.get-datetime.outputs.time }}
loc_cs: ${{ steps.get-loc_cs.outputs.total_lines }}
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: Get build environment
id: get-environment
run: |
if ${{ contains(github.event.head_commit.message, '[release]') || contains(github.event.head_commit.message, '[pre-release]') || contains(github.event.ref, 'rel/') || contains(github.event.ref, 'dev/') || contains(github.event.ref, 'dependabot/') }}; then
echo "environment=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
echo "environment_alpine=${{ github.ref_name }}-alpine" >> "$GITHUB_OUTPUT"
elif ${{ contains(github.ref_name, 'main') && (!contains(github.event.head_commit.message, '[pre-release]') || !contains(github.event.head_commit.message, '[release]')) }}; then
echo "environment=dev" >> "$GITHUB_OUTPUT"
echo "environment_alpine=dev-alpine" >> "$GITHUB_OUTPUT"
fi
- name: Get build config
id: get-config
run: |
if ${{ (contains(github.event.head_commit.message, '[release]') || contains(github.event.head_commit.message, '[pre-release]') || contains(github.event.ref, 'rel/')) }}; then
echo "config=Docker" >> "$GITHUB_OUTPUT"
else
echo "config=Docker-debug" >> "$GITHUB_OUTPUT"
fi
- name: Get correct Dockerfile
id: get-dockerfile
run: |
if [[ "${{ steps.get-config.outputs.config }}" == "Docker" ]]; then
echo "dockerfile=release.Dockerfile" >> "$GITHUB_OUTPUT"
echo "dockerfile_alpine=release.alpine.Dockerfile" >> "$GITHUB_OUTPUT"
else
echo "dockerfile=dev.Dockerfile" >> "$GITHUB_OUTPUT"
echo "dockerfile_alpine=dev.alpine.Dockerfile" >> "$GITHUB_OUTPUT"
fi
- name: Get Date and Time
id: get-datetime
uses: Kaven-Universe/github-action-current-date-time@f2c12d90cff9c3e7b1f50430886e632fe31fcee1 # v1.4.0
with:
format: "YYYY-MM-DDTHH:mm:ss"
- name: Calculate Lines of Source Code
if: ${{ github.actor != 'dependabot[bot]' }}
id: get-loc_cs
uses: PavanMudigonda/lines-of-code-reporter@6c5507f592136d1c05cb1e8c30889dc4eb5561f5 # v1.6
with:
include_lang: "C#,MSBuild script"
docker-build:
name: Build Docker Image For ${{ matrix.os }} - ${{ matrix.arch }}
needs: [extract_meta]
runs-on: ubuntu-24.04${{ matrix.arch == 'arm64' && '-arm' || '' }}
strategy:
matrix:
os: [debian, alpine]
arch: [amd64, arm64]
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: Log in to Docker Hub
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Docker meta
id: meta
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v3.6.1
with:
flavor: latest=${{ matrix.os == 'debian' && (contains(github.event.head_commit.message, '[release]') || contains(github.event.ref, 'rel/')) || 'false' }}
images: sellagh/azzybot
tags: |
type=raw,value=${{ matrix.os == 'debian' && needs.extract_meta.outputs.environment || needs.extract_meta.outputs.environment_alpine }}
${{ (matrix.os == 'alpine' && contains(github.event.head_commit.message, '[release]') || contains(github.event.ref, 'rel/')) && 'type=raw,value=latest-alpine' || '' }}
- name: Set up QEMU
uses: docker/setup-qemu-action@53851d14592bedcffcf25ea515637cff71ef929a # v3.3.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.8.0
- name: Log in to Docker Hub
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push by digest
id: build
uses: docker/build-push-action@ca877d9245402d1537745e0e356eab47c3520991 # v6.13.0
env:
DOCKER_BUILD_SUMMARY: false
DOCKER_BUILD_RECORD_UPLOAD: false
with:
build-args: |
CONFIG=${{ needs.extract_meta.outputs.config }}
COMMIT=${{ github.sha }}
TIMESTAMP=${{ needs.extract_meta.outputs.datetime }}
LOC_CS=${{ needs.extract_meta.outputs.loc_cs }}
context: .
file: ${{ matrix.os == 'debian' && needs.extract_meta.outputs.dockerfile || needs.extract_meta.outputs.dockerfile_alpine }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/${{ matrix.arch }}
outputs: type=image,name=sellagh/azzybot,push-by-digest=true,name-canonical=true,push=true
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: ${{ matrix.os }}-linux-${{ matrix.arch }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge:
name: Creating Docker Release
runs-on: ubuntu-24.04
needs: [extract_meta, docker-build]
strategy:
matrix:
os: [debian, alpine]
steps:
- name: Download digests
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
path: /tmp/digests
pattern: ${{ matrix.os }}-*
merge-multiple: true
- name: Log in to Docker Hub
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.8.0
- name: Docker meta
id: meta
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v3.6.1
with:
flavor: latest=${{ matrix.os == 'debian' && (contains(github.event.head_commit.message, '[release]') || contains(github.event.ref, 'rel/')) || 'false' }}
images: sellagh/azzybot
tags: |
type=raw,value=${{ matrix.os == 'debian' && needs.extract_meta.outputs.environment || needs.extract_meta.outputs.environment_alpine }}
${{ (matrix.os == 'alpine' && contains(github.event.head_commit.message, '[release]') || contains(github.event.ref, 'rel/')) && 'type=raw,value=latest-alpine' || '' }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf 'sellagh/azzybot@sha256:%s ' *)