Repository navigation
95 lines (95 loc) · 3.48 KB
/
Copy pathdocker-publish.yaml
File metadata and controls
95 lines (95 loc) · 3.48 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
# This job will build and push the Docker image to Docker Hub.
name: docker-publish
on:
workflow_dispatch:
inputs:
version:
type: string
required: true
description: The release version (e.g., X.Y.Z), without the v.
latest:
type: boolean
description: Tag with latest
default: false
publish:
type: boolean
description: Publish the image to Docker Hub
default: false
permissions: read-all
jobs:
docker:
runs-on: ubuntu-latest
if: github.repository == 'bufbuild/buf'
steps:
- name: Validate SemVer
run: |
VERSION=${{ github.event.inputs.version }}
SEMVER_REGEX='^[0-9]*\.[0-9]*\.[0-9]*$'
if [[ ! $VERSION =~ $SEMVER_REGEX ]]; then
echo "Error: '$VERSION' is not a valid SemVer version"
exit 1
else
echo "Version '$VERSION' is a valid SemVer version"
fi
- name: checkout
id: checkout
uses: actions/checkout@v5
with:
ref: refs/tags/v${{ github.event.inputs.version }}
- name: setup-qemu
uses: docker/setup-qemu-action@v3
id: qemu
with:
platforms: linux/386,linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6,linux/ppc64le,linux/riscv64,linux/s390x
- name: setup-docker-buildx
uses: docker/setup-buildx-action@v3
- name: login-docker
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: docker-meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
bufbuild/buf
tags: |
type=raw,value=latest,enable=${{ github.event.inputs.latest }}
type=semver,pattern={{major}},value=v${{ github.event.inputs.version }}
type=semver,pattern={{major}}.{{minor}},value=v${{ github.event.inputs.version }}
type=semver,pattern={{major}}.{{minor}}.{{patch}},value=v${{ github.event.inputs.version }}
type=semver,pattern={{version}},value=v${{ github.event.inputs.version }}
labels: |
org.opencontainers.image.revision=${{ steps.checkout.outputs.commit }}
org.opencontainers.image.version=${{ github.event.inputs.version }}
flavor: |
latest=false
- name: docker-build
uses: docker/build-push-action@v6
with:
context: . # This uses the checkout context
file: Dockerfile.buf
load: true
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: docker-test
run: |
OUTPUT=$(docker run --rm bufbuild/buf:${{ github.event.inputs.version }} --version)
if [ "$OUTPUT" == "${{ github.event.inputs.version }}" ]; then
echo "Version matches"
else
echo "Version does not match: expected ${{ github.event.inputs.version }}, got $OUTPUT"
exit 1
fi
- name: docker-build-publish
uses: docker/build-push-action@v6
if: ${{ github.event.inputs.publish == 'true' }}
with:
context: . # This uses the checkout context
file: Dockerfile.buf
platforms: ${{ steps.qemu.outputs.platforms }}
push: ${{ github.event.inputs.publish == 'true' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}