diff --git a/.github/scripts/build-image.sh b/.github/scripts/build-image.sh new file mode 100755 index 0000000..63a6a0d --- /dev/null +++ b/.github/scripts/build-image.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +set -euo pipefail + +IMAGE=$1 + +echo "Building $IMAGE" + +RELEASE=$(./images/${IMAGE}/latest.sh) +VERSION=${RELEASE%%_*} +VERSION=${VERSION#release-} +VERSION=${VERSION#v} + +if [[ -z $VERSION ]]; then + echo "Failed to retrieve latest version for $IMAGE" +else + docker buildx build \ + --push \ + --platform linux/amd64,linux/arm64 \ + --tag ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/${IMAGE}:${VERSION} \ + --tag ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/${IMAGE}:latest \ + --build-arg RELEASE=${RELEASE} \ + --build-arg VERSION=${VERSION} \ + --build-arg GOLANG_VERSION="1.20" \ + --build-arg CHISEL_VERSION="v0.9.1" \ + --label "org.opencontainers.image.authors=${GITHUB_REPOSITORY_OWNER}" \ + --label "org.opencontainers.image.source=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" \ + --label "org.opencontainers.image.version=${VERSION}" \ + --label "org.opencontainers.image.vendor=${GITHUB_REPOSITORY_OWNER}" \ + --label "org.opencontainers.image.title=${IMAGE}" \ + - < images/${IMAGE}/Dockerfile +fi diff --git a/.github/workflows/build-images.yaml b/.github/workflows/build-images.yaml new file mode 100644 index 0000000..883a3ff --- /dev/null +++ b/.github/workflows/build-images.yaml @@ -0,0 +1,41 @@ +--- +on: + push: + branches: + - main + +name: Build images + +jobs: + generate-images-matrix: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.generate-images-matrix.outputs.matrix }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Generate images matrix + id: generate-images-matrix + run: echo "matrix={\"images\":[$(ls -mQ images)]}" | tee $GITHUB_OUTPUT + + build-images: + runs-on: ubuntu-latest + needs: generate-images-matrix + strategy: + matrix: + image: ${{ fromJSON(needs.generate-images-matrix.outputs.matrix).images }} + 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: Login to Github container registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build image + run: ./.github/scripts/build-image.sh ${{ matrix.image }}