-
Notifications
You must be signed in to change notification settings - Fork 3
108 lines (94 loc) · 3.84 KB
/
Copy pathdocker.yml
File metadata and controls
108 lines (94 loc) · 3.84 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
name: Docker
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: 'Git tag to build. Leave empty to build from latest main commit.'
required: false
type: string
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_BASE: ghcr.io/scipp/esslivedata
jobs:
build-and-push:
name: ${{ matrix.target }}/${{ matrix.instrument }}
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
# This should be updated whenever a new instrument is added to pyproject.toml
instrument: [dream, bifrost, loki, odin, estia]
target: [backend, dashboard]
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ inputs.tag || github.event.release.tag_name || 'main' }}
fetch-depth: 0
- name: Determine version
id: version
run: |
if [ "${{ github.event_name }}" = "release" ]; then
# Release: use the tag directly
VERSION="${{ github.event.release.tag_name }}"
IS_RELEASE=true
elif [ -n "${{ inputs.tag }}" ]; then
# Manual dispatch with tag: use the tag
VERSION="${{ inputs.tag }}"
IS_RELEASE=true
else
# Manual dispatch without tag: derive dev version from main
LATEST_TAG=$(git describe --tags --abbrev=0 --match '[0-9]*.[0-9]*.[0-9]*')
COMMITS_SINCE=$(git rev-list "${LATEST_TAG}..HEAD" --count)
SHORT_SHA=$(git rev-parse --short HEAD)
MAJOR=$(echo "${LATEST_TAG}" | cut -d. -f1)
MINOR=$(echo "${LATEST_TAG}" | cut -d. -f2)
PATCH=$(echo "${LATEST_TAG}" | cut -d. -f3)
NEXT_PATCH=$((PATCH + 1))
VERSION="${MAJOR}.${MINOR}.${NEXT_PATCH}.dev${COMMITS_SINCE}"
IS_RELEASE=false
echo "Latest tag: ${LATEST_TAG}, commits since: ${COMMITS_SINCE}, sha: ${SHORT_SHA}"
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "is_release=${IS_RELEASE}" >> "$GITHUB_OUTPUT"
echo "Building version: ${VERSION} (release: ${IS_RELEASE})"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Determine image tags
id: tags
run: |
IMAGE="${{ env.IMAGE_BASE }}-${{ matrix.target }}-${{ matrix.instrument }}"
TAGS="${IMAGE}:${{ steps.version.outputs.version }}"
if [ "${{ steps.version.outputs.is_release }}" = "true" ]; then
TAGS="${TAGS},${IMAGE}:latest"
fi
echo "tags=${TAGS}" >> "$GITHUB_OUTPUT"
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
target: ${{ matrix.target }}
push: true
tags: ${{ steps.tags.outputs.tags }}
build-args: |
SETUPTOOLS_SCM_PRETEND_VERSION=${{ steps.version.outputs.version }}
INSTRUMENT=${{ matrix.instrument }}
labels: |
org.opencontainers.image.title=esslivedata-${{ matrix.target }}-${{ matrix.instrument }}
org.opencontainers.image.description=ESSlivedata ${{ matrix.target }} for ${{ matrix.instrument }}
org.opencontainers.image.version=${{ steps.version.outputs.version }}
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
cache-from: type=gha,scope=${{ matrix.target }}-${{ matrix.instrument }}
cache-to: type=gha,mode=max,scope=${{ matrix.target }}-${{ matrix.instrument }}