forked from misiektoja/spotify_monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
115 lines (105 loc) · 4.32 KB
/
Copy pathpublish-debug-docker.yml
File metadata and controls
115 lines (105 loc) · 4.32 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
109
110
111
112
113
114
115
name: Publish debug Docker image
# The secret grabber ships on its own cadence, so this image tracks the extractor's version rather than
# a spotify_monitor release: a change on main publishes it, and a weekly rebuild refreshes the base.
on:
push:
branches: [main]
paths:
- debug/spotify_monitor_secret_grabber.py
- debug/spotify_monitor_secret_grabber_docker/**
- .github/workflows/publish-debug-docker.yml
schedule:
# Chromium and Debian publish fixes between extractor changes, so the image is rebuilt weekly.
- cron: "41 5 * * 3"
workflow_dispatch:
inputs:
tag:
description: Optional image tag like 1.4, defaults to the version declared in the extractor
required: false
type: string
push_latest:
description: Also push latest tag
required: false
type: boolean
default: true
env:
IMAGE_NAME: misiektoja/spotify-secrets-grabber
permissions: {}
jobs:
test:
name: Tests and container smoke checks
# A called workflow cannot exceed what the calling job grants, so the checkout in tests.yml needs this.
permissions:
contents: read
uses: ./.github/workflows/tests.yml
publish-debug-docker:
name: Build and publish multi-architecture debug image to Docker Hub
needs: test
# A fork cannot push to this Docker Hub namespace, so the scheduled rebuild stays with the source repository.
if: github.repository == 'misiektoja/spotify_monitor'
runs-on: ubuntu-latest
environment:
name: docker
url: https://hub.docker.com/r/misiektoja/spotify-secrets-grabber
permissions:
contents: read
steps:
- name: Check out source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up QEMU
uses: docker/setup-qemu-action@96fe6ef7f33517b61c61be40b68a1882f3264fb8 # v4.2.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4.3.0
- name: Resolve image tags
id: resolve_tags
shell: bash
# Event and input values reach the script through the environment. Interpolating them directly into
# run: would let a crafted input run shell commands in a job already holding the registry token
env:
EVENT_NAME: ${{ github.event_name }}
INPUT_TAG: ${{ github.event.inputs.tag }}
INPUT_PUSH_LATEST: ${{ github.event.inputs.push_latest }}
run: |
set -euo pipefail
base_tag="$INPUT_TAG"
push_latest="true"
if [[ "$EVENT_NAME" == "workflow_dispatch" ]]; then
push_latest="$INPUT_PUSH_LATEST"
fi
if [[ -z "$base_tag" ]]; then
# The extractor declares its own version in its docstring, which is what users see in the tool
base_tag="$(grep -m1 -oE '^v[0-9]+\.[0-9]+(\.[0-9]+)?$' debug/spotify_monitor_secret_grabber.py | cut -c2-)"
fi
if [[ -z "$base_tag" ]]; then
echo "Failed to resolve image tag from the extractor version" >&2
exit 1
fi
# A tag becomes part of an image reference, so refuse anything outside the characters a tag may use
if [[ ! "$base_tag" =~ ^[A-Za-z0-9._-]+$ ]]; then
echo "Refusing unsafe image tag: $base_tag" >&2
exit 1
fi
tags=("${IMAGE_NAME}:${base_tag}" "${IMAGE_NAME}:${GITHUB_SHA::7}")
if [[ "$push_latest" == "true" ]]; then
tags+=("${IMAGE_NAME}:latest")
fi
{
echo "tags<<EOF"
printf '%s\n' "${tags[@]}"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Log in to Docker Hub
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push multi-architecture image
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0
with:
context: ./debug
file: ./debug/spotify_monitor_secret_grabber_docker/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.resolve_tags.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max