-
Notifications
You must be signed in to change notification settings - Fork 2
69 lines (67 loc) · 2.24 KB
/
build-and-push.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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 }}