-
Notifications
You must be signed in to change notification settings - Fork 11
332 lines (293 loc) · 10.4 KB
/
main.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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# Copyright 2023 UMH Systems GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
name: main
on:
push:
branches:
- '**'
tags:
- v*
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-docker:
permissions:
packages: write
contents: read
timeout-minutes: 60
strategy:
matrix:
architecture: ['amd64', 'arm64', 'arm/v7']
runs-on:
group: ${{ matrix.architecture == 'arm64' && 'arc-runners-small' || matrix.architecture == 'arm/v7' && 'arc-runners-small' || 'arc-runners' }}
outputs:
tags: ${{ steps.meta.outputs.tags }}
BASE_TAGS: ${{ steps.output-tags.outputs.BASE_TAGS }}
env:
PR_ID: ${{ github.event.pull_request.number }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request && github.head_ref || github.ref_name }}
- name: Check if Docker daemon is running
id: check_docker
run: |
SECONDS=0
TIMEOUT=120
while ! docker info >/dev/null 2>&1; do
if [ $SECONDS -ge $TIMEOUT ]; then
echo "Docker daemon is not running after ${TIMEOUT} seconds, exiting..."
docker info
exit 1
fi
echo "Waiting for Docker daemon to start..."
sleep 1
done
echo "Docker daemon is running."
- name: Login to GitHub Container registry
uses: docker/login-action@v3
env:
GITHUB_USER: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
registry: ghcr.io
username: $GITHUB_USER
password: ${{ secrets.GITHUB_TOKEN }}
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
with:
image: management.umh.app/oci/tonistiigi/binfmt:latest
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set PLATFORM_SHORT
id: platform_short
shell: bash
run: |
PLATFORM_SHORT="${{ matrix.architecture }}"
PLATFORM_SHORT="${PLATFORM_SHORT//\//-}"
echo "PLATFORM_SHORT=${PLATFORM_SHORT}" >> $GITHUB_OUTPUT
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern=latest,include_prereleases=false
type=ref,event=branch
type=ref,event=pr
type=sha
- name: Prepare tags with platform suffix
id: prepare_tags
run: |
TAGS="${{ steps.meta.outputs.tags }}"
PLATFORM_SUFFIX="-${{ steps.platform_short.outputs.PLATFORM_SHORT }}"
echo "Original Tags: $TAGS"
echo "Platform Suffix: $PLATFORM_SUFFIX"
# Replace newlines with commas
TAGS_CLEAN=$(echo "$TAGS" | tr '\n' ',' | sed 's/,$//')
echo "Cleaned Tags: $TAGS_CLEAN"
# Split tags into an array
IFS=',' read -ra TAG_ARRAY <<< "$TAGS_CLEAN"
# Append platform suffix to each tag
for TAG in "${TAG_ARRAY[@]}"; do
TAG_WITH_SUFFIX="${TAG}${PLATFORM_SUFFIX}"
NEW_TAGS_ARRAY+=("$TAG_WITH_SUFFIX")
done
# Join the new tags into a comma-separated string
NEW_TAGS=$(IFS=','; echo "${NEW_TAGS_ARRAY[*]}")
echo "Tags with Platform Suffix: $NEW_TAGS"
# Set the output variable
echo "NEW_TAGS=$NEW_TAGS" >> $GITHUB_OUTPUT
- name: Build and Push Docker Image
uses: docker/build-push-action@v4
with:
push: true
platforms: linux/${{ matrix.architecture }}
tags: ${{ steps.prepare_tags.outputs.NEW_TAGS }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
APP_VERSION=${{ steps.meta.outputs.version }}
provenance: false
file: ./Dockerfile
- name: Set Output Tags
id: output-tags
run: |
echo "BASE_TAGS<<EOF" >> $GITHUB_OUTPUT
echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
create-manifests:
needs: build-docker
if: needs.build-docker.outputs.tags != ''
permissions:
contents: read
packages: write
runs-on:
group: arc-runners
defaults:
run:
shell: bash
steps:
- name: Login to GitHub Container registry
uses: docker/login-action@v3
env:
GITHUB_USER: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
registry: ghcr.io
username: $GITHUB_USER
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Create multiarch manifests
run: |
# Enable debug mode and error handling
set -euxo pipefail
# Get the list of base tags
TAGS="${{ needs.build-docker.outputs.BASE_TAGS }}"
echo "TAGS: $TAGS"
# Split tags into an array using newlines as the delimiter
IFS=$'\n' readarray -t TAG_ARRAY <<< "$TAGS"
echo "Number of tags: ${#TAG_ARRAY[@]}"
for i in "${!TAG_ARRAY[@]}"; do
echo "TAG_ARRAY[$i]: ${TAG_ARRAY[$i]}"
done
# Define architectures
ARCHITECTURES=("amd64" "arm64" "arm/v7")
# Create manifests for each base tag
for TAG in "${TAG_ARRAY[@]}"; do
echo "Processing tag $TAG"
# Construct platform-specific tags
PLATFORM_TAGS=""
for ARCH in "${ARCHITECTURES[@]}"; do
PLATFORM_SHORT="${ARCH//\//-}"
PLATFORM_TAG="${TAG}-${PLATFORM_SHORT}"
PLATFORM_TAGS="${PLATFORM_TAGS} ${PLATFORM_TAG}"
done
echo "Checking availability of images for $TAG"
MISSING_IMAGES=0
for IMAGE in ${PLATFORM_TAGS}; do
echo "Checking image: $IMAGE"
if ! docker buildx imagetools inspect "$IMAGE" >/dev/null 2>&1; then
echo "Image not found: $IMAGE"
MISSING_IMAGES=1
else
echo "Image exists: $IMAGE"
fi
done
if [ $MISSING_IMAGES -ne 0 ]; then
echo "One or more images are missing for $TAG. Skipping manifest creation."
continue
fi
echo "Creating manifest for $TAG from $PLATFORM_TAGS"
docker buildx imagetools create -t "${TAG}" ${PLATFORM_TAGS}
done
build-binaries:
if: startsWith(github.ref, 'refs/tags/')
strategy:
matrix:
include:
- goos: linux
goarch: amd64
- goos: linux
goarch: arm64
- goos: linux
goarch: armv7
- goos: windows
goarch: amd64
- goos: windows
goarch: arm64
- goos: windows
goarch: arm
- goos: darwin
goarch: amd64
- goos: darwin
goarch: arm64
runs-on:
group: ${{ matrix.architecture == 'arm64' && 'arc-runners-small' || matrix.architecture == 'armv7' && 'arc-runners-small' || 'arc-runners' }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request && github.head_ref || github.ref_name }}
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
with:
image: management.umh.app/oci/tonistiigi/binfmt:latest
- name: Install Cross-Compilers
run: |
sudo apt-get update
sudo apt-get install -y gcc-multilib gcc-mingw-w64
- name: Set up Build Environment
run: |
echo "GOOS=${{ matrix.goos }}" >> $GITHUB_ENV
if [ "${{ matrix.goarch }}" == "armv7" ]; then
echo "GOARM=7" >> $GITHUB_ENV
echo "GOARCH=arm" >> $GITHUB_ENV
else
echo "GOARCH=${{ matrix.goarch }}" >> $GITHUB_ENV
fi
if [ "${{ matrix.goos }}" == "windows" ]; then
FILE_EXTENSION=".exe"
else
FILE_EXTENSION=""
fi
echo "OUTPUT_NAME=benthos-${{ matrix.goos }}-${{ matrix.goarch }}${FILE_EXTENSION}"
echo "OUTPUT_NAME=benthos-${{ matrix.goos }}-${{ matrix.goarch }}${FILE_EXTENSION}" >> $GITHUB_ENV
- name: Print working directory
run: pwd
- name: List files in working directory
run: ls -la
- name: Build Binary
run: |
mkdir -p ./dist
GOOS=${{ env.GOOS }} GOARCH=${{ env.GOARCH }} GOARM=${{ env.GOARM }} \
CGO_ENABLED=0 GOPROXY=https://golangproxy.umh.app,https://proxy.golang.org,direct \
go build \
-ldflags "-s -w \
-X github.com/redpanda-data/benthos/v4/internal/cli.Version=${APP_VERSION} \
-X github.com/redpanda-data/benthos/v4/internal/cli.DateBuilt=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
-o ./dist/${{ env.OUTPUT_NAME }} \
cmd/benthos/main.go
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: binaries
path: ./dist/${{ env.OUTPUT_NAME }}
release:
if: needs.build-binaries.result == 'success'
needs: build-binaries
permissions:
contents: write
runs-on:
group: arc-runners # Use your own runners
steps:
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
name: binaries
path: ./artifacts
- name: Create or Update Release
uses: ncipollo/release-action@v1
with:
tag: ${{ github.ref_name }}
artifacts: './artifacts/*'
token: ${{ secrets.GITHUB_TOKEN }}
allowUpdates: true
prerelease: ${{ contains(github.ref, 'beta') || contains(github.ref, 'alpha') }}