-
Notifications
You must be signed in to change notification settings - Fork 102
80 lines (69 loc) · 2.22 KB
/
container-build.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
70
71
72
73
74
75
76
77
78
79
80
name: Build and publish container image
on:
# run when tagging or pushing to master
push:
branches: [master]
tags: ["*"]
permissions:
packages: write # ghcr access
contents: write # create releases
env:
# GitHub Container Registry hostname
GHCR_HOSTNAME: ghcr.io
jobs:
build_and_push:
runs-on: ubuntu-latest
steps:
- name: Checkout the latest SHA for this branch
uses: actions/checkout@v4
if: github.event_name != 'workflow_dispatch'
- name: Checkout the specified tag
uses: actions/checkout@v4
if: github.event_name == 'workflow_dispatch'
with:
ref: ${{ github.event.inputs.tag }}
- name: Get the latest Dockerfile if needed
if: github.event_name == 'workflow_dispatch'
run: |
if [[ ! -f Dockerfile ]]; then
git fetch --depth=1 origin master
git checkout origin/master -- Dockerfile
fi
- name: Setup Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare
id: prep
run: |
VERSION="${{ github.event.inputs.tag }}"
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION="${GITHUB_REF/refs\/tags\//}"
fi
if [[ -z "$VERSION" ]]; then
VERSION="ref-${GITHUB_SHA::8}"
fi
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
- name: Generate images meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.GHCR_HOSTNAME }}/${{ github.repository }}
tags: |
type=raw,value=${{ steps.prep.outputs.VERSION }}
- name: Build the container image
uses: docker/build-push-action@v5
with:
push: true
builder: ${{ steps.buildx.outputs.name }}
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max