-
-
Notifications
You must be signed in to change notification settings - Fork 0
242 lines (212 loc) · 9.6 KB
/
publish-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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
name: 🐳 Docker Images
on:
workflow_dispatch:
push:
branches:
- '**'
tags:
- '**'
paths:
- 'src/**'
schedule:
- cron: '0 0 * * 0'
env:
Repository: dublok/jackett
jobs:
build-and-push:
runs-on: ubuntu-latest
outputs:
SHA_SHORT: ${{ steps.fetch-sha.outputs.SHA_SHORT }}
BRANCH_NAME: ${{ steps.extract-branch-name.outputs.BRANCH_NAME }}
strategy:
matrix:
platform: [amd64, arm64] # arm64, s390x
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Fetch Commit SHA
id: fetch-sha
run: |
echo "SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Extract Branch Name
id: extract-branch-name
run: |
echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV
echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT
- name: ENV Variables
run: |
source $GITHUB_ENV
echo "BRANCH_NAME: ${BRANCH_NAME}"
echo "SHA_SHORT: ${SHA_SHORT}"
echo "GITHUB_REF_NAME: ${GITHUB_REF_NAME}"
- name: Define Tags
run: |
source $GITHUB_ENV
TEMP_TAGS="${{ env.Repository }}:${SHA_SHORT}-${{ matrix.platform }}"
echo "TEMP_TAGS=${TEMP_TAGS}" >> $GITHUB_ENV
- name: Tags
run: |
source $GITHUB_ENV
echo "TEMP_TAGS: ${TEMP_TAGS}"
- name: Set Build Args
run: |
echo "BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_ENV
SHA_SHORT=$(git rev-parse --short HEAD)
echo "VERSION=${GITHUB_REF_NAME}/${SHA_SHORT}" >> $GITHUB_ENV
echo "TARGETPLATFORM=${{ matrix.platform }}" >> $GITHUB_ENV
if [ "${{ matrix.platform }}" == "amd64" ]; then
echo "ARCH=x86_64" >> $GITHUB_ENV
elif [ "${{ matrix.platform }}" == "arm64" ]; then
echo "ARCH=aarch64" >> $GITHUB_ENV
fi
- name: Combine Build Args
run: |
echo "BUILD_ARGS=TARGETPLATFORM=${{ env.TARGETPLATFORM }} ARCH=${{ env.ARCH }} BUILD_DATE=${{ env.BUILD_DATE }} VERSION=${{ env.VERSION }}" >> $GITHUB_ENV
- name: Print Build Args
run: |
source $GITHUB_ENV
echo "BUILD_ARGS: ${BUILD_ARGS}"
- name: Build and Push Docker Images
uses: docker/build-push-action@v5.0.0
with:
context: ./src
file: ./src/Dockerfile
push: true
platforms: ${{ matrix.platform }}
tags: ${{ env.TEMP_TAGS }}
build-args: |
TARGETPLATFORM=${{ env.TARGETPLATFORM }}
ARCH=${{ env.ARCH }}
BUILD_DATE=${{ env.BUILD_DATE }}
VERSION=${{ env.VERSION }}
create-and-push-manifest:
needs: build-and-push
runs-on: ubuntu-latest
env:
SHA_SHORT: ${{ needs.build-and-push.outputs.SHA_SHORT }}
BRANCH_NAME: ${{ needs.build-and-push.outputs.BRANCH_NAME }}
steps:
- name: Print ENV Variables
run: |
echo "SHA_SHORT: ${{ env.SHA_SHORT }}"
echo "BRANCH_NAME: ${{ env.BRANCH_NAME }}"
echo "GITHUB_REF_NAME: ${GITHUB_REF_NAME}"
- name: Fetch Tags from Docker Hub
id: fetch-tags
run: |
SHA_SHORT=${{ env.SHA_SHORT }}
RESPONSE=$(curl -s -H "Authorization: Bearer ${{ secrets.DOCKER_TOKEN }}" "https://hub.docker.com/v2/repositories/${{ env.Repository }}/tags?name=$SHA_SHORT")
TAGS=$(echo $RESPONSE | jq -r '.results[].name' | tr '\n' ',' | sed 's/,$//')
echo "Fetched tags: $TAGS"
echo "TAGS=$TAGS" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Create and push multi-arch manifest
id: create_manifest
run: |
TAGS=${{ env.TAGS }}
IFS=',' read -r -a TAG_ARRAY <<< "$TAGS"
IMAGETOOLS_CMD="docker buildx imagetools create --tag ${{ env.Repository }}:${{ env.SHA_SHORT }} --tag ${{ env.Repository }}:${GITHUB_REF_NAME} "
IMAGE_LIST="${{ env.Repository }}:${{ env.SHA_SHORT }},${{ env.Repository }}:${GITHUB_REF_NAME}"
if [[ "${GITHUB_REF_NAME}" == v* ]]; then
# Extract major version (e.g., v1 from v1.0.2, v1.0.2.1, etc.)
if [[ "${GITHUB_REF_NAME}" =~ ^v([0-9]+) ]]; then
MAJOR_VERSION="v${BASH_REMATCH[1]}"
# Extract additional version components
VERSION_REGEX='^v([0-9]+)(\.[0-9]+)?(\.[0-9]+)?(\.[0-9]+)?([aA-zZ])?$'
if [[ "${GITHUB_REF_NAME}" =~ $VERSION_REGEX ]]; then
MAJOR_MINOR_VERSION="v${BASH_REMATCH[1]}${BASH_REMATCH[2]}"
MAJOR_MINOR_PATCH_VERSION="v${BASH_REMATCH[1]}${BASH_REMATCH[2]}${BASH_REMATCH[3]}"
FULL_VERSION="v${BASH_REMATCH[1]}${BASH_REMATCH[2]}${BASH_REMATCH[3]}${BASH_REMATCH[4]}"
if [[ -n "${BASH_REMATCH[5]}" ]]; then
SUFFIX="${BASH_REMATCH[5]}"
FULL_VERSION_WITH_SUFFIX="${FULL_VERSION}${SUFFIX}"
else
SUFFIX=""
FULL_VERSION_WITH_SUFFIX="${FULL_VERSION}"
fi
fi
if [[ "${SUFFIX}" =~ [aA] ]]; then
if [[ -n "$FULL_VERSION" ]]; then
IMAGETOOLS_CMD+="--tag ${{ env.Repository }}:${FULL_VERSION}-alpha "
IMAGE_LIST+=",${{ env.Repository }}:${FULL_VERSION}-alpha"
fi
if [[ -n "$MAJOR_MINOR_PATCH_VERSION" ]]; then
IMAGETOOLS_CMD+="--tag ${{ env.Repository }}:${MAJOR_MINOR_PATCH_VERSION}-alpha "
IMAGE_LIST+=",${{ env.Repository }}:${MAJOR_MINOR_PATCH_VERSION}-alpha"
fi
if [[ -n "$MAJOR_MINOR_VERSION" ]]; then
IMAGETOOLS_CMD+="--tag ${{ env.Repository }}:${MAJOR_MINOR_VERSION}-alpha "
IMAGE_LIST+=",${{ env.Repository }}:${MAJOR_MINOR_VERSION}-alpha"
fi
IMAGETOOLS_CMD+="--tag ${{ env.Repository }}:${MAJOR_VERSION}-alpha "
IMAGETOOLS_CMD+="--tag ${{ env.Repository }}:alpha "
IMAGE_LIST+=",${{ env.Repository }}:${MAJOR_VERSION}-alpha"
IMAGE_LIST+=",${{ env.Repository }}:alpha"
elif [[ "${SUFFIX}" =~ [bB] ]]; then
if [[ -n "$FULL_VERSION" ]]; then
IMAGETOOLS_CMD+="--tag ${{ env.Repository }}:${FULL_VERSION}-beta "
IMAGE_LIST+=",${{ env.Repository }}:${FULL_VERSION}-beta"
fi
if [[ -n "$MAJOR_MINOR_PATCH_VERSION" ]]; then
IMAGETOOLS_CMD+="--tag ${{ env.Repository }}:${MAJOR_MINOR_PATCH_VERSION}-beta "
IMAGE_LIST+=",${{ env.Repository }}:${MAJOR_MINOR_PATCH_VERSION}-beta"
fi
if [[ -n "$MAJOR_MINOR_VERSION" ]]; then
IMAGETOOLS_CMD+="--tag ${{ env.Repository }}:${MAJOR_MINOR_VERSION}-beta "
IMAGE_LIST+=",${{ env.Repository }}:${MAJOR_MINOR_VERSION}-beta"
fi
IMAGETOOLS_CMD+="--tag ${{ env.Repository }}:${MAJOR_VERSION}-beta "
IMAGETOOLS_CMD+="--tag ${{ env.Repository }}:beta "
IMAGE_LIST+=",${{ env.Repository }}:${MAJOR_VERSION}-beta"
IMAGE_LIST+=",${{ env.Repository }}:beta"
else
if [[ -n "$FULL_VERSION" ]]; then
IMAGETOOLS_CMD+="--tag ${{ env.Repository }}:${FULL_VERSION} "
IMAGE_LIST+=",${{ env.Repository }}:${FULL_VERSION}"
fi
if [[ -n "$MAJOR_MINOR_PATCH_VERSION" ]]; then
IMAGETOOLS_CMD+="--tag ${{ env.Repository }}:${MAJOR_MINOR_PATCH_VERSION} "
IMAGE_LIST+=",${{ env.Repository }}:${MAJOR_MINOR_PATCH_VERSION}"
fi
if [[ -n "$MAJOR_MINOR_VERSION" ]]; then
IMAGETOOLS_CMD+="--tag ${{ env.Repository }}:${MAJOR_MINOR_VERSION} "
IMAGE_LIST+=",${{ env.Repository }}:${MAJOR_MINOR_VERSION}"
fi
IMAGETOOLS_CMD+="--tag ${{ env.Repository }}:${MAJOR_VERSION} "
IMAGETOOLS_CMD+="--tag ${{ env.Repository }}:latest "
IMAGE_LIST+=",${{ env.Repository }}:${MAJOR_VERSION}"
IMAGE_LIST+=",${{ env.Repository }}:latest"
fi
fi
fi
for TAG in "${TAG_ARRAY[@]}"; do
IMAGETOOLS_CMD+="${{ env.Repository }}:$TAG "
done
echo "IMAGE_LIST=$IMAGE_LIST" >> $GITHUB_ENV
echo "Running command: $IMAGETOOLS_CMD"
eval $IMAGETOOLS_CMD
- name: Run Docker Package Versions Action
uses: DockForge/SBOMinify@latest
with:
images: ${{ env.IMAGE_LIST }}
github_token: ${{ secrets.GITHUB_TOKEN }}
output_path: "sboms"
sbom_file_prefix: ""
sbom_file_suffix: ""
sbom_file_name: "[TAG]"