-
Notifications
You must be signed in to change notification settings - Fork 0
88 lines (75 loc) · 3.01 KB
/
docker-image.yml
File metadata and controls
88 lines (75 loc) · 3.01 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: Build and Push Docker Image
on:
push:
branches:
- master
schedule:
- cron: '0 0 * * *' # Runs daily at midnight
workflow_dispatch:
inputs:
dbsync_ref:
description: 'cardano-db-sync tag or commit SHA to build (defaults to latest release)'
required: false
type: string
permissions:
contents: read
packages: write
jobs:
build:
runs-on: ubuntu-latest
outputs:
dbsync_ref: ${{ steps.resolve_dbsync_ref.outputs.dbsync_ref }}
image_tag: ${{ steps.resolve_dbsync_ref.outputs.image_tag }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Resolve dbsync ref
id: resolve_dbsync_ref
env:
DBSYNC_REF_INPUT: ${{ github.event.inputs.dbsync_ref }}
run: |
dbsync_ref=$(printf '%s' "$DBSYNC_REF_INPUT" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
if [[ -z "$dbsync_ref" ]]; then
dbsync_ref=$(curl -fsSL https://api.github.com/repos/intersectmbo/cardano-db-sync/releases/latest | jq -r .tag_name)
if [[ -z "$dbsync_ref" || "$dbsync_ref" == "null" ]]; then
echo "Failed to get latest tag"; exit 1
fi
elif git ls-remote --exit-code --tags https://github.com/intersectmbo/cardano-db-sync.git "refs/tags/$dbsync_ref" >/dev/null 2>&1; then
echo "Found cardano-db-sync tag: $dbsync_ref"
else
if [[ ! "$dbsync_ref" =~ ^[0-9a-fA-F]{7,40}$ ]]; then
echo "dbsync_ref must be a cardano-db-sync tag or commit SHA: $dbsync_ref"
exit 1
fi
status_code=$(curl -s -o /tmp/dbsync-commit.json -w "%{http_code}" "https://api.github.com/repos/intersectmbo/cardano-db-sync/commits/$dbsync_ref")
if [[ "$status_code" != "200" ]]; then
echo "dbsync_ref must be a cardano-db-sync tag or commit SHA: $dbsync_ref"
exit 1
fi
fi
image_tag=$(printf '%s' "$dbsync_ref" | sed -E 's/[^A-Za-z0-9_.-]+/-/g; s/^[.-]+//; s/[.-]+$//')
image_tag=${image_tag:0:128}
if [[ -z "$image_tag" ]]; then
echo "Unable to derive Docker image tag from dbsync ref: $dbsync_ref"; exit 1
fi
echo "Target dbsync ref: $dbsync_ref"
echo "Target image tag: $image_tag"
echo "dbsync_ref=$dbsync_ref" >> $GITHUB_OUTPUT
echo "image_tag=$image_tag" >> $GITHUB_OUTPUT
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: ghcr.io/${{ github.repository_owner }}/cardano-db-sync:${{ steps.resolve_dbsync_ref.outputs.image_tag }}
build-args: |
DBSYNC_TAG=${{ steps.resolve_dbsync_ref.outputs.dbsync_ref }}