From a7e3f3046732188b7dedba57920c24028750453a Mon Sep 17 00:00:00 2001 From: Philipp Schmitt Date: Wed, 11 Mar 2020 19:00:43 +0100 Subject: [PATCH] Add multiarch support + Daily builds with GitHub Actions --- .github/workflows/github-build.yml | 28 ++++++++++++++++ buildx.sh | 54 ++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 .github/workflows/github-build.yml create mode 100755 buildx.sh diff --git a/.github/workflows/github-build.yml b/.github/workflows/github-build.yml new file mode 100644 index 0000000..a6f859a --- /dev/null +++ b/.github/workflows/github-build.yml @@ -0,0 +1,28 @@ +name: GitHub Actions CI + +on: + push: + schedule: + - cron: '0 6 * * *' + +jobs: + buildx: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@master + with: + ref: ${{ github.ref }} + + - name: Docker login + uses: azure/docker-login@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build docker container + env: + DOCKER_CLI_EXPERIMENTAL: enabled + run: | + curl -fsSL https://raw.githubusercontent.com/pschmitt/ci-setup-docker-buildx/master/setup.sh | bash + ./buildx.sh diff --git a/buildx.sh b/buildx.sh new file mode 100755 index 0000000..e5fb06b --- /dev/null +++ b/buildx.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +IMAGE_NAME="willfarrell/autoheal" + +usage() { + echo "Usage: $0" +} + +array_join() { + local IFS="$1" + shift + echo "$*" +} + +get_available_architectures() { + local image="$1" + local tag="${2:-latest}" + + docker buildx imagetools inspect --raw "${image}:${tag}" | \ + jq -r '.manifests[].platform | .os + "/" + .architecture + "/" + .variant' | \ + sed 's#/$##' | sort +} + +if [[ "${BASH_SOURCE[0]}" == "${0}" ]] +then + set -ex + + cd "$(readlink -f "$(dirname "$0")")" || exit 9 + + read -r base_image base_tag <<< \ + "$(sed -nr 's/^FROM\s+([^:]+):?((\w+).*)\s*$/\1 \3/p' Dockerfile | head -1)" + # shellcheck disable=2207 + platforms=($(get_available_architectures "$base_image" "$base_tag")) + + PUSH_IMAGE=true + BUILD_TYPE=manual + + if [[ "$TRAVIS" == "true" ]] + then + BUILD_TYPE=travis + elif [[ "$GITHUB_ACTIONS" == "true" ]] + then + BUILD_TYPE=github + fi + + docker buildx build \ + --platform "$(array_join "," "${platforms[@]}")" \ + --output "type=image,push=${PUSH_IMAGE}" \ + --no-cache \ + --label=build-type="$BUILD_TYPE" \ + --label=built-on="$HOSTNAME" \ + --tag "${IMAGE_NAME}:latest" \ + . +fi