-
Notifications
You must be signed in to change notification settings - Fork 0
119 lines (107 loc) · 4.12 KB
/
docker.yml
File metadata and controls
119 lines (107 loc) · 4.12 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
name: Docker
# Builds and publishes the sql-splitter image to Docker Hub and GHCR.
#
# Triggers:
# - push to a version tag (v*): builds that tag
# - workflow_dispatch with `tag` input: builds the given ref (used to backfill old releases)
#
# Required secrets:
# - DOCKERHUB_USERNAME: Docker Hub account (e.g. helgesverre)
# - DOCKERHUB_TOKEN: Docker Hub access token with read/write/delete on the repo
#
# GHCR uses the workflow's GITHUB_TOKEN -- no extra secret needed.
on:
push:
tags:
- 'v*'
pull_request:
paths:
- 'Dockerfile'
- '.dockerignore'
- '.github/workflows/docker.yml'
- 'Cargo.toml'
- 'Cargo.lock'
workflow_dispatch:
inputs:
tag:
description: 'Git tag to build (e.g. v1.13.5). Required for backfill runs.'
required: true
type: string
permissions:
contents: read
packages: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Resolve ref to build
id: ref
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "ref=${{ inputs.tag }}" >> "$GITHUB_OUTPUT"
elif [ "${{ github.event_name }}" = "pull_request" ]; then
# PR validation: build the PR head, don't push
echo "ref=${{ github.event.pull_request.head.sha }}" >> "$GITHUB_OUTPUT"
else
echo "ref=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
fi
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "push=false" >> "$GITHUB_OUTPUT"
else
echo "push=true" >> "$GITHUB_OUTPUT"
fi
- uses: actions/checkout@v4
with:
ref: ${{ steps.ref.outputs.ref }}
fetch-depth: 0
- name: Overlay Dockerfile from main (backfill runs)
# Tags published before Docker support was added don't have a Dockerfile.
# On workflow_dispatch backfills, copy the current Dockerfile + .dockerignore
# from main on top of the tag's source tree so old releases can still be built.
if: github.event_name == 'workflow_dispatch'
run: |
git fetch origin main --depth=1
git checkout origin/main -- Dockerfile .dockerignore
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
if: steps.ref.outputs.push == 'true'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Log in to GHCR
if: steps.ref.outputs.push == 'true'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Compute image metadata
id: meta
if: steps.ref.outputs.push == 'true'
uses: docker/metadata-action@v5
with:
images: |
docker.io/${{ secrets.DOCKERHUB_USERNAME }}/sql-splitter
ghcr.io/${{ github.repository_owner }}/sql-splitter
# Strip any leading "v" so we get both `v1.13.5` and `1.13.5`, plus partial semver tags.
# `latest` is applied automatically when the ref is the highest semver tag.
tags: |
type=semver,pattern={{version}},value=${{ steps.ref.outputs.ref }}
type=semver,pattern={{major}}.{{minor}},value=${{ steps.ref.outputs.ref }}
type=semver,pattern={{major}},value=${{ steps.ref.outputs.ref }}
type=raw,value=${{ steps.ref.outputs.ref }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
# PR validation builds amd64 only to keep CI quick; tag/dispatch publishes multi-arch.
platforms: ${{ steps.ref.outputs.push == 'true' && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
push: ${{ steps.ref.outputs.push == 'true' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max