Repository navigation
101 lines (95 loc) · 3.78 KB
/
Copy pathdocker-workflow.yml
File metadata and controls
101 lines (95 loc) · 3.78 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
name: Docker Build & Push
permissions:
contents: read
on:
workflow_call:
inputs:
push:
description: 'Whether to push the Docker images'
required: false
default: false
type: boolean
jobs:
docker:
permissions:
actions: write
contents: read
packages: write
id-token: write
runs-on: ubuntu-24.04-arm
name: "Build and Push Sitrep Image"
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# `git describe` below needs the tags and enough history to count commits since
# the last one. The default shallow fetch has neither, and --always would quietly
# degrade to a bare SHA rather than failing.
fetch-depth: 0
- name: Download UI build artifacts
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: ui-build
path: ui/build/
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version: "stable"
- uses: ko-build/setup-ko@61b4d1d396f5b2e7d6bb6fefdce3dc38d1a13445 # v0.10
- name: Install Go dependencies
run: go mod download
- name: Docker meta
id: meta
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
with:
images: ghcr.io/f-eld-ch/sitrep
tags: |
# Release tags are published by GoReleaser. This workflow builds branch images.
type=raw,value=stable,enable=${{ github.ref == format('refs/heads/{0}', 'main') }},priority=910
type=raw,value=develop,enable={{is_default_branch}},priority=905
# priority 900
type=semver,pattern={{major}}.{{minor}},prefix=v
type=semver,pattern={{major}},prefix=v
# priority 700
type=edge,branch=develop
# priority 600
type=ref,event=branch
type=ref,event=pr,prefix=pr-,enable=true
- name: Prepare Image Tags and Labels
id: image_tags_labels
run: |
# prepare tags
tags=""
separator=""
prefix=${KO_DOCKER_REPO}
IFS=$'\n'
for tag in ${DOCKER_METADATA_OUTPUT_TAGS}; do
tags="$tags${separator}${tag#${prefix}:}"
separator=","
done
echo "tags=$tags" >> $GITHUB_OUTPUT
# prepare labels
labels=""
IFS=$'\n'
separator=""
for label in ${DOCKER_METADATA_OUTPUT_LABELS}; do
labels="${labels}${separator}--image-label '$label'"
separator=" "
done
echo "labels=$labels" >> $GITHUB_OUTPUT
- name: Ko Build
run: |
# Deliberately `git describe` rather than the image tag from metadata-action.
# That yields the literal "develop" on the default branch, "stable" on main and
# "pr-N" on pull requests — only tagged releases got a real version, and most
# deploys are not tagged. This anchors every build to the last release and counts
# from it (v26.8.0-64-g136b9bf0), and is byte-identical to what the UI bakes in,
# so the two never disagree. The image tags themselves are unaffected: they come
# from image_tags_labels below.
SITREP_VERSION="$(git describe --tags --always)"
if [ -z "$SITREP_VERSION" ]; then
echo "::error::git describe produced an empty version; refusing to build an unversioned image"
exit 1
fi
echo "Stamping version: $SITREP_VERSION"
export SITREP_VERSION
ko build --bare . --tags ${{ steps.image_tags_labels.outputs.tags }} ${{ steps.image_tags_labels.outputs.labels }}