-
Notifications
You must be signed in to change notification settings - Fork 4
153 lines (132 loc) · 4.94 KB
/
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
name: Publish
on:
push:
branches:
- "main"
paths:
- "images/**/*"
# add workflow dispatch to manually publish the current images
workflow_dispatch:
concurrency:
# Cancel in-progress jobs if a new job is trigged by a commit from the same branch
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
REGISTRY_IMAGE: friendsofredaxo/redaxo
jobs:
collect:
name: Collect images from directories
runs-on: ubuntu-latest
# Map step outputs to job outputs, so that the data can be used in upcoming jobs
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idoutputs
outputs:
IMAGES: ${{ steps.images.outputs.directories }}
steps:
- name: Checkout repository
# https://github.com/actions/checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Collect images from directories
id: images
run: |
cd images
directories=$(tree -J -d -L 1 | jq -c '.[0].contents | map(.name)')
echo $directories
echo "directories=$directories" >> $GITHUB_OUTPUT
publish:
name: Publish
runs-on: ubuntu-latest
needs: [collect]
strategy:
fail-fast: false
matrix:
image: ${{ fromJson(needs.collect.outputs.IMAGES) }}
steps:
- name: Checkout repository
# https://github.com/marketplace/actions/checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Create tag list for image
# We make use of yp (https://mikefarah.gitbook.io/yq/) to create a taglist from
# the image’s `tags.yml` file, where all given tags (like `5-stable`, `5-edge`) are
# combined with all image registries (like ghcr, Docker Hub).
run: |
taglist=$(yq 'map(
(
"${{ env.REGISTRY_IMAGE }}",
"ghcr.io/${{ env.REGISTRY_IMAGE }}"
)
+ ":" + .[]) | to_csv' ./images/${{ matrix.image }}/tags.yml)
echo "$taglist"
echo "TAGLIST=$taglist" >> $GITHUB_ENV
- name: Set up QEMU
# https://github.com/marketplace/actions/docker-setup-qemu
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
# https://github.com/marketplace/actions/docker-setup-buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
# https://github.com/marketplace/actions/docker-login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
# https://github.com/marketplace/actions/docker-login
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
# https://github.com/marketplace/actions/build-and-push-docker-images
uses: docker/build-push-action@v6
with:
context: ./images/${{ matrix.image }}
platforms: linux/amd64,linux/arm64
push: true
provenance: false
tags: ${{ env.TAGLIST }}
update:
name: Update
runs-on: ubuntu-latest
needs: [publish]
steps:
- name: Checkout repository
# https://github.com/marketplace/actions/checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Login to Docker Hub
# https://github.com/marketplace/actions/docker-login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
# https://github.com/marketplace/actions/docker-login
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Update repo description
# https://github.com/marketplace/actions/docker-hub-description
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: ${{ env.REGISTRY_IMAGE }}
short-description: ${{ github.event.repository.description }}
enable-url-completion: true
- name: Delete untagged containers from GitHub Container Registry
# https://github.com/marketplace/actions/delete-untagged-ghcr
uses: Chizkiyahu/delete-untagged-ghcr-action@v4
with:
token: ${{ secrets.GH_PACKAGES }}
untagged_only: true
owner_type: org
except_untagged_multiplatform: true