generated from okp4/template-oss
-
Notifications
You must be signed in to change notification settings - Fork 2
157 lines (141 loc) · 5.91 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
154
155
156
157
name: Publish
on:
push:
branches: [main]
jobs:
prepare:
name: Create build matrix
runs-on: ubuntu-22.04
outputs:
matrix: ${{ steps.matrix.outputs.config }}
any-changed: ${{ steps.changed-dockerfiles.outputs.any_changed }}
repository_owner: ${{ steps.environment.outputs.repository_owner }}
date_stamp: ${{ steps.environment.outputs.date_stamp }}
date: ${{ steps.environment.outputs.date }}
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Find changed dockerfiles
id: changed-dockerfiles
uses: tj-actions/[email protected]
with:
separator: ","
files: |
**/Dockerfile
- name: Setup environment
id: environment
run: |
echo "repository_owner=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
echo "date_stamp=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT
echo "date=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> $GITHUB_OUTPUT
- name: Setup matrix (for changed dockerfiles)
id: matrix
run: |
CONFIG=""
ALL_MODIFIED_FILES=${{ steps.changed-dockerfiles.outputs.all_modified_files }}
IFS=',' read -r -a DOCKERFILES <<< "$ALL_MODIFIED_FILES"
for DOCKERFILE in "${DOCKERFILES[@]}"; do
APATH=$(dirname ${DOCKERFILE})
VERSION=$(basename ${APATH})
NAME=$(basename $(dirname $APATH))
PLATFORMS=$(cat ${APATH}/.platforms || echo "linux/amd64")
CONFIG="${CONFIG:+${CONFIG}, }{\"path\": \"${APATH}\", \"version\": \"${VERSION}\", \"name\": \"${NAME}\", \"platforms\": \"${PLATFORMS}\"}"
done
echo "config=[${CONFIG}]" >> $GITHUB_OUTPUT
prepare-readmes:
runs-on: ubuntu-22.04
needs: prepare
if: ${{ !failure() }}
outputs:
matrix: ${{ steps.matrix.outputs.config }}
any-changed: ${{ steps.changed-readmes.outputs.any_changed }}
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Find changed readme files
id: changed-readmes
uses: tj-actions/[email protected]
with:
separator: ","
files: |
./dockerfiles/**/README.md
- name: Build iterable readmes info
id: matrix
run: |
CONFIG=""
ALL_MODIFIED_FILES=${{ steps.changed-readmes.outputs.all_modified_files }}
IFS=',' read -r -a READMES <<< $ALL_MODIFIED_FILES
for README in ${READMES[@]}; do
REPO=$(basename $(dirname ${README}))
CONFIG="${CONFIG:+${CONFIG}, }{\"repo\": \"${REPO}\", \"path\": \"${README}\"}"
done
echo "config=[${CONFIG}]" >> $GITHUB_OUTPUT
publish-docker-images:
timeout-minutes: 10
runs-on: ubuntu-22.04
needs: prepare
strategy:
matrix:
context: ${{ fromJson(needs.prepare.outputs.matrix) }}
fail-fast: false
if: needs.prepare.outputs.any-changed == 'true'
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/[email protected]
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log into GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ secrets.DOCKER_REGISTRY_ID }}
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}
- name: Log into Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_REGISTRY_ID }}
password: ${{ secrets.DOCKER_HUB_REGISTRY_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: ${{ matrix.context.path }}
platforms: ${{ matrix.context.platforms }}
push: true
tags: |
"ghcr.io/${{ needs.prepare.outputs.repository_owner }}/${{ matrix.context.name }}:${{ matrix.context.version }}-${{ needs.prepare.outputs.date_stamp }}"
"ghcr.io/${{ needs.prepare.outputs.repository_owner }}/${{ matrix.context.name }}:${{ matrix.context.version }}"
"${{ needs.prepare.outputs.repository_owner }}/${{ matrix.context.name }}:${{ matrix.context.version }}-${{ needs.prepare.outputs.date_stamp }}"
"${{ needs.prepare.outputs.repository_owner }}/${{ matrix.context.name }}:${{ matrix.context.version }}"
labels: |
org.opencontainers.image.created=${{ needs.prepare.outputs.date_stamp }}
org.opencontainers.image.name=${{ matrix.context.name }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=${{ matrix.context.version }}
org.opencontainers.image.vendor=${{ needs.prepare.outputs.repository_owner }}
org.opencontainers.image.url=https://github.com/${{ github.repository }}/tree/main/dockerfiles/${{ matrix.context.name }}/${{ matrix.context.version }}
org.opencontainers.image.source=https://github.com/${{ github.repository }}/tree/main/dockerfiles/${{ matrix.context.name }}/${{ matrix.context.version }}
update-dockerhub-readme:
timeout-minutes: 10
runs-on: ubuntu-22.04
needs: prepare-readmes
strategy:
matrix:
context: ${{ fromJson(needs.prepare-readmes.outputs.matrix) }}
fail-fast: false
if: needs.prepare-readmes.outputs.any-changed == 'true'
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKER_HUB_REGISTRY_ID }}
password: ${{ secrets.DOCKER_HUB_REGISTRY_TOKEN }}
repository: okp4/${{ matrix.context.repo }}
readme-filepath: ${{ matrix.context.path }}