diff --git a/.github/workflows/build_connectivity_tester.yml b/.github/workflows/build_connectivity_tester.yml index fb93fb6..0f30fef 100644 --- a/.github/workflows/build_connectivity_tester.yml +++ b/.github/workflows/build_connectivity_tester.yml @@ -1,79 +1,91 @@ -name: Build connectivity_tester (multi-arch) +name: build connectivity_tester (multi-arch) on: + workflow_dispatch: + inputs: + ref: + description: Git ref to build + required: true + default: feat/connectivity-tester + image_name: + description: Image name (e.g. hermes/connectivity_tester) + required: true + default: hermes/connectivity_tester + push_stackfile: + description: Upload rendered stack-compose as artifact + required: false + type: string + default: "true" push: branches: - feat/connectivity-tester - workflow_dispatch: -env: - REGISTRY: gitea.rudolf.keenetic.link - IMAGE_NAME: hermes/connectivity_tester +permissions: + contents: read jobs: build: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest strategy: fail-fast: false matrix: - platforms: + platform: - linux/amd64 - linux/arm64 + - linux/arm/v7 + outputs: + image_tag: ${{ steps.tag.outputs.value }} steps: - name: Checkout - run: | - if [ -n "${{ gitea.token }}" ]; then - git clone --depth=1 --branch "${{ gitea.ref }}" \ - "https://x-access-token:${{ gitea.token }}@gitea.rudolf.keenetic.link/hermes/ansible.git" . - fi + uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.ref || github.ref }} + fetch-depth: 0 - - name: Set up QEMU - run: | - docker run --rm --privileged tonistiigi/binfmt --install all - docker run --rm --privileged tonistiigi/qemu-user-static --reset + - name: Resolve image tag + id: tag + run: echo "value=auto-${GITHUB_SHA::8}" >> "$GITHUB_OUTPUT" - - name: Set up Buildx - run: | - docker buildx create --name multiarch --use --platform \ - linux/amd64,linux/arm64 || true - docker buildx use multiarch + - name: Resolve image_name + id: name + run: echo "value=${{ github.event.inputs.image_name || 'hermes/connectivity_tester' }}" >> "$GITHUB_OUTPUT" - name: Login to Gitea Container Registry run: | - echo "${{ secrets.GITEA_TOKEN }}" | \ - docker login "${{ env.REGISTRY }}" -u "${{ secrets.GITEA_USERNAME }}" --password-stdin + echo "${{ secrets.REGISTRY_PASSWORD }}" | \ + docker login "gitea.rudolf.keenetic.link" \ + -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin - - name: Resolve short SHA - id: short - run: echo "sha=$(git rev-parse --short=8 HEAD)" >> "$GITHUB_OUTPUT" + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - - name: Build and push + - name: Build and push image + uses: docker/build-push-action@v6 + with: + context: connectivity_tester + file: connectivity_tester/Dockerfile + platforms: ${{ matrix.platform }} + push: true + tags: | + gitea.rudolf.keenetic.link/${{ steps.name.outputs.value }}:${{ steps.tag.outputs.value }} + gitea.rudolf.keenetic.link/${{ steps.name.outputs.value }}:latest + cache-from: | + type=registry,ref=gitea.rudolf.keenetic.link/${{ steps.name.outputs.value }}:buildcache + cache-to: | + type=registry,ref=gitea.rudolf.keenetic.link/${{ steps.name.outputs.value }}:buildcache,mode=max + + - name: Render stackfile with image tag + if: github.event.inputs.push_stackfile != 'false' run: | - docker buildx build \ - --platform "${{ matrix.platforms }}" \ - --tag "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:auto-${{ steps.short.outputs.sha }}" \ - --tag "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" \ - --cache-from type=gha,scope=connectivity_tester \ - --cache-to type=gha,scope=connectivity_tester,mode=max \ - --file connectivity_tester/Dockerfile \ - --context connectivity_tester \ - --push \ - --provenance=false \ - . + mkdir -p out + sed "s|\${version}|${{ steps.tag.outputs.value }}|g" \ + connectivity_tester/stack-compose.yml \ + > "out/docker-compose-${{ steps.tag.outputs.value }}.yml" - - name: Inspect manifest - run: | - docker buildx imagetools inspect \ - "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:auto-${{ steps.short.outputs.sha }}" - - - name: Notify brencher - if: github.event_name == 'push' - run: | - BRENCHER_URL="${{ secrets.BRENCHER_WEBHOOK_URL }}" - BRENCHER_TOKEN="${{ secrets.BRENCHER_WEBHOOK_TOKEN }}" - if [ -z "$BRENCHER_URL" ]; then exit 0; fi - curl -fsS -X POST \ - -H "Authorization: Bearer ${BRENCHER_TOKEN}" \ - "${BRENCHER_URL}/api/v1/environments/connectivity_tester/refresh" - continue-on-error: true + - name: Upload rendered stackfile + if: github.event.inputs.push_stackfile != 'false' + uses: actions/upload-artifact@v4 + with: + name: stack-compose + path: out/