-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (75 loc) · 2.97 KB
/
docker-image.yml
File metadata and controls
87 lines (75 loc) · 2.97 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
name: Build & Push Docker Images
on:
push:
paths:
- "salami/**/Dockerfile"
- "salami/**/docker-compose.yml"
- "salami/**/VERSION"
- "salamibase/**/Dockerfile"
- "salamibase/**/docker-compose.yml"
- "salamibase/**/VERSION"
workflow_dispatch:
inputs:
target:
description: "Path to the Dockerfile (e.g. salami/grafana/12/debian-12/Dockerfile)"
required: false
type: string
permissions:
packages: write
contents: write
jobs:
detect-and-build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Fetch full git history
run: git fetch --prune --unshallow || true
- name: Determine changed Dockerfiles
id: changed
if: github.event_name == 'push'
run: |
files=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep 'Dockerfile' || true)
files=$(echo "$files" | paste -sd "," -)
echo "changed_files=$files" >> $GITHUB_OUTPUT
- name: Build & Push changed images
if: github.event_name == 'push' && steps.changed.outputs.changed_files != ''
run: |
owner=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
IFS=',' read -ra changed_files <<< "${{ steps.changed.outputs.changed_files }}"
for file in "${changed_files[@]}"; do
dir=$(dirname "$file")
name=$(echo "$dir" | xargs | tr '/' '-' | tr -d ' ')
version_file="$dir/VERSION"
if [ -f "$version_file" ]; then
version=$(cat "$version_file")
else
version="latest"
fi
image="ghcr.io/$owner/$name:$version"
echo "Building and pushing $file as $image (multi-arch)"
docker buildx build --platform linux/amd64 -t "$image" -t "ghcr.io/$owner/$name:latest" --push "$dir"
done
- name: Manual build & push
if: github.event_name == 'workflow_dispatch' && inputs.target != ''
run: |
owner=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
dir=$(dirname "${{ inputs.target }}")
name=$(echo "$dir" | xargs | tr '/' '-' | tr -d ' ')
version_file="$dir/VERSION"
if [ -f "$version_file" ]; then
version=$(cat "$version_file")
else
version="latest"
fi
image="ghcr.io/$owner/$name:$version"
echo "Building and pushing manual target ${{ inputs.target }} as $image (multi-arch)"
docker buildx build --no-cache --platform linux/amd64,linux/arm64 -t "$image" -t "ghcr.io/$owner/$name:latest" --push "$dir"