-
Notifications
You must be signed in to change notification settings - Fork 1
77 lines (66 loc) · 1.89 KB
/
publish-image.yml
File metadata and controls
77 lines (66 loc) · 1.89 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
name: Publish Image
on:
workflow_dispatch:
inputs:
image_tags:
description: Comma-separated tags to publish. Defaults to staging-SHORTSHA,SHORTSHA.
required: false
type: string
default: ""
push:
tags:
- "staging-*"
- "v*"
permissions:
contents: read
concurrency:
group: publish-image-${{ github.ref }}
cancel-in-progress: false
jobs:
publish:
runs-on: ubuntu-latest
env:
IMAGE_NAME: skel84/allocdb
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Resolve tags
id: tags
shell: bash
run: |
set -euo pipefail
short_sha="${GITHUB_SHA::7}"
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
raw_tags="${{ inputs.image_tags }}"
if [[ -z "${raw_tags}" ]]; then
raw_tags="staging-${short_sha},${short_sha}"
fi
else
raw_tags="${GITHUB_REF_NAME},${short_sha}"
fi
IFS=',' read -ra tags <<< "${raw_tags}"
{
echo "tags<<EOF"
for tag in "${tags[@]}"; do
trimmed="$(echo "${tag}" | xargs)"
[[ -n "${trimmed}" ]] || continue
echo "${IMAGE_NAME}:${trimmed}"
done
echo "EOF"
} >> "${GITHUB_OUTPUT}"
- name: Build and push image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64
push: true
tags: ${{ steps.tags.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max