Skip to content

Add examples for burning native tokens, paying to a script, and payme… #16

Add examples for burning native tokens, paying to a script, and payme…

Add examples for burning native tokens, paying to a script, and payme… #16

name: Build docker images
on:
push:
branches:
- master
tags:
- "v*"
env:
IMAGE: ghcr.io/dquadrant/kuber
HYDRA_IMAGE: ghcr.io/dquadrant/kuber-hydra
COMMIT_SHA: ${{ github.sha }}
jobs:
build:
if: ${{ !github.event.repository.fork }}
strategy:
matrix:
include:
- arch: amd64
runner: ubuntu-latest
- arch: arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache cabal store
uses: actions/cache@v5
with:
path: dist-newstyle/build/docker/cabal-cache
key: cabal-${{ matrix.arch }}-${{ hashFiles('kuber.cabal', 'kuber-hydra/kuber-hydra.cabal') }}
restore-keys: |
cabal-${{ matrix.arch }}-
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Cabal update
run: ./.ci/build cabal update
- name: Build and Push Architecture Image
run: |
IMAGE_TAG="${{ env.IMAGE }}:${{ env.COMMIT_SHA }}-${{ matrix.arch }}"
./.ci/build -t "$IMAGE_TAG"
docker push "$IMAGE_TAG"
manifest:
if: ${{ !github.event.repository.fork }}
needs: build
runs-on: ubuntu-latest
permissions:
packages: write
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push multi-arch manifest
run: |
BASE="${{ env.IMAGE }}"
# 1. Create the primary manifest tied to the commit SHA
docker buildx imagetools create \
-t "${BASE}:${{ env.COMMIT_SHA }}" \
"${BASE}:${{ env.COMMIT_SHA }}-amd64" \
"${BASE}:${{ env.COMMIT_SHA }}-arm64"
# 2. Add 'latest' tag for master branch or version tags
if [[ "${{ github.ref }}" == "refs/heads/master" ]] || [[ "${{ github.ref }}" == refs/tags/v* ]]; then
docker buildx imagetools create -t "${BASE}:latest" "${BASE}:${{ env.COMMIT_SHA }}"
fi
# 3. Add Version and Major tags (e.g., v1.2.3 and v1)
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
TAG_NAME="${GITHUB_REF#refs/tags/}"
docker buildx imagetools create -t "${BASE}:${TAG_NAME}" "${BASE}:${{ env.COMMIT_SHA }}"
if [[ "$TAG_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
MAJOR_TAG="${TAG_NAME%%.*}"
docker buildx imagetools create -t "${BASE}:${MAJOR_TAG}" "${BASE}:${{ env.COMMIT_SHA }}"
fi
fi
build-hydra:
if: ${{ !github.event.repository.fork }}
needs: manifest
strategy:
matrix:
include:
- arch: amd64
runner: ubuntu-latest
- arch: arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push kuber-hydra arch image
run: |
docker buildx build \
--platform linux/${{ matrix.arch }} \
--build-arg BASE_TAG="${{ env.COMMIT_SHA }}" \
-f ./.ci/Dockerfile.hydra \
-t "${{ env.HYDRA_IMAGE }}:${{ env.COMMIT_SHA }}-${{ matrix.arch }}" \
--push .
manifest-hydra:
if: ${{ !github.event.repository.fork }}
needs: build-hydra
runs-on: ubuntu-latest
permissions:
packages: write
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push kuber-hydra manifest
run: |
BASE="${{ env.HYDRA_IMAGE }}"
# 1. Create the primary manifest tied to the commit SHA
docker buildx imagetools create \
-t "${BASE}:${{ env.COMMIT_SHA }}" \
"${BASE}:${{ env.COMMIT_SHA }}-amd64" \
"${BASE}:${{ env.COMMIT_SHA }}-arm64"
# 2. Add 'latest' tag for master branch or version tags
if [[ "${{ github.ref }}" == "refs/heads/master" ]] || [[ "${{ github.ref }}" == refs/tags/v* ]]; then
docker buildx imagetools create -t "${BASE}:latest" "${BASE}:${{ env.COMMIT_SHA }}"
fi
# 3. Add Version and Major tags (e.g., v1.2.3 and v1)
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
TAG_NAME="${GITHUB_REF#refs/tags/}"
docker buildx imagetools create -t "${BASE}:${TAG_NAME}" "${BASE}:${{ env.COMMIT_SHA }}"
if [[ "$TAG_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
MAJOR_TAG="${TAG_NAME%%.*}"
docker buildx imagetools create -t "${BASE}:${MAJOR_TAG}" "${BASE}:${{ env.COMMIT_SHA }}"
fi
fi
- name: Cleanup temporary hydra arch images
run: |
OWNER="dquadrant"
PACKAGE_NAME="kuber-hydra"
for ARCH in amd64 arm64; do
TAG="${{ env.COMMIT_SHA }}-${ARCH}"
VERSION_ID=$(gh api "/orgs/${OWNER}/packages/container/${PACKAGE_NAME}/versions" \
--paginate \
--jq ".[] | select(.metadata.container.tags[] == \"${TAG}\") | .id")
if [ -n "$VERSION_ID" ]; then
gh api --method DELETE "/orgs/${OWNER}/packages/container/${PACKAGE_NAME}/versions/${VERSION_ID}"
fi
done
cleanup:
# Run after both manifest and manifest-hydra complete.
# This ensures the arch-specific base images are not deleted before build-hydra uses them.
if: ${{ !github.event.repository.fork }}
needs: [manifest, manifest-hydra]
runs-on: ubuntu-latest
permissions:
packages: write
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Cleanup temporary kuber architecture images
run: |
OWNER="dquadrant"
PACKAGE_NAME="kuber"
for ARCH in amd64 arm64; do
TAG="${{ env.COMMIT_SHA }}-${ARCH}"
echo "Searching for version ID for tag: ${TAG}"
VERSION_ID=$(gh api "/orgs/${OWNER}/packages/container/${PACKAGE_NAME}/versions" \
--paginate \
--jq ".[] | select(.metadata.container.tags[] == \"${TAG}\") | .id")
if [ -n "$VERSION_ID" ]; then
echo "Deleting temporary arch tag ${TAG} (ID: ${VERSION_ID})"
gh api --method DELETE "/orgs/${OWNER}/packages/container/${PACKAGE_NAME}/versions/${VERSION_ID}"
else
echo "Tag ${TAG} not found, skipping."
fi
done