-
Notifications
You must be signed in to change notification settings - Fork 0
88 lines (78 loc) · 2.65 KB
/
docker.yml
File metadata and controls
88 lines (78 loc) · 2.65 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: Docker
on:
# Automatically run after the Release workflow completes successfully.
# (Events created by GITHUB_TOKEN don't trigger "release: published" in
# other workflows, so we use workflow_run instead.)
workflow_run:
workflows: ["Release"]
types: [completed]
# Manual trigger with an explicit tag.
workflow_dispatch:
inputs:
tag:
description: 'Tag to build (e.g., v1.0.0)'
required: true
type: string
permissions:
contents: read
packages: write
jobs:
docker:
name: Build and Push Docker Image
runs-on: ubuntu-latest
# Only run if the Release workflow succeeded (skip on failure/cancelled),
# or if this was triggered manually.
if: >-
github.event_name == 'workflow_dispatch' ||
github.event.workflow_run.conclusion == 'success'
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Determine tag
id: get_tag
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG="${{ inputs.tag }}"
else
# workflow_run: find the latest semver tag pointing at HEAD
TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
fi
if [ -z "$TAG" ]; then
echo "::error::Could not determine release tag"
exit 1
fi
echo "tag=$TAG" >> $GITHUB_OUTPUT
echo "Using tag: $TAG"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ghcr.io/didstopia/githubby
tags: |
type=semver,pattern={{version}},value=${{ steps.get_tag.outputs.tag }}
type=semver,pattern={{major}}.{{minor}},value=${{ steps.get_tag.outputs.tag }}
type=semver,pattern={{major}},value=${{ steps.get_tag.outputs.tag }}
type=raw,value=latest
- name: Build and push
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ steps.get_tag.outputs.tag }}
COMMIT=${{ github.sha }}
BUILD_DATE=${{ github.event.repository.updated_at }}
cache-from: type=gha
cache-to: type=gha,mode=max