Skip to content

Fix browse definition #453

Fix browse definition

Fix browse definition #453

Workflow file for this run

# 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') }}