Skip to content

build-and-push

build-and-push #276

name: build-and-push
on:
workflow_dispatch: {}
schedule:
- cron: "0 0 * * *"
jobs:
check-version:
runs-on: ubuntu-latest
outputs:
keel_tag: ${{ steps.keel_tag.outputs.value }}
image_exists: ${{ steps.image_exists.outputs.value }}
steps:
- name: Get the latest release of keelhq/keel
id: keel_tag
run: |
set -ex
TAG="$(curl https://api.github.com/repos/keel-hq/keel/releases/latest -s | jq .name -r)"
echo "value=${TAG}" >> $GITHUB_OUTPUT
- name: Login to Docker Hub
uses: docker/login-action@master
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Check if image exists
id: image_exists
run: |
set -ex
IMAGE="${{ secrets.DOCKERHUB_USERNAME }}/keel:${{ steps.keel_tag.outputs.value }}"
if docker manifest inspect "$IMAGE" &> /dev/null; then
echo "value=true" >> $GITHUB_OUTPUT
else
echo "value=false" >> $GITHUB_OUTPUT
fi
build-and-push:
needs:
- check-version
if: needs.check-version.outputs.image_exists == 'false'
runs-on: ubuntu-latest
steps:
- name: Checkout Keel
uses: actions/checkout@main
with:
repository: keel-hq/keel
ref: ${{ env.TAG }}
path: keel
- name: Set up QEMU
uses: docker/setup-qemu-action@master
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@master
- name: Login to Docker Hub
uses: docker/login-action@master
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@master
with:
context: keel
# This is not ideal but the frequency of releases is low enough that it's not a big deal
platforms: linux/amd64,linux/arm64
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: "${{ env.IMAGE }}:${{ env.TAG }},${{ env.IMAGE }}:latest"
env:
IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/keel
TAG: ${{ needs.check-version.outputs.keel_tag }}