-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (73 loc) · 2.55 KB
/
docker-publish.yml
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
name: Docker
# This workflow will generate container images for each of the Github Actions
# which are using a Dockerfile.
on:
push:
branches:
- "main"
- "feature-*"
tags:
- "v*"
jobs:
prepare:
# Finds all the Dockerfiles in the repository and sets the action names
# as output to reuse as matrix strategy in the build job
runs-on: ubuntu-latest
outputs:
matrix_json: ${{ steps.set-output.outputs.matrix_json }}
steps:
- uses: actions/checkout@v4
- name: Find Dockerfiles
id: set-output
run: |
# Find all Dockerfiles in the repository
paths_with_docker=$(find -type f -name 'Dockerfile' | sed 's|/Dockerfile||' | sed 's|./||')
# Transform the list of paths into a valid JSON array to be used as matrix strategy
action_names=$(echo $paths_with_docker | jq --raw-input --compact-output 'split(" ") | { "action-name": . }')
echo "Found Dockerfiles in the repository:"
echo "${action_names}"
echo "matrix_json=${action_names}" >> "${GITHUB_OUTPUT}"
build:
runs-on: ubuntu-latest
needs:
- prepare
permissions:
contents: read
packages: write
strategy:
matrix: ${{ fromJson(needs.prepare.outputs.matrix_json) }}
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/${{ matrix.action-name }}
steps:
- uses: actions/checkout@v4
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=pr
type=ref,event=branch
type=semver,pattern={{version}}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ${{ matrix.action-name }}
file: ${{ matrix.action-name }}/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# platforms: linux/amd64,linux/arm64 # Enable if we ever need to build for ARM
cache-from: type=gha
cache-to: type=gha,mode=max