generated from okp4/template-oss
-
Notifications
You must be signed in to change notification settings - Fork 2
87 lines (78 loc) · 3.4 KB
/
build.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
name: Build
on:
pull_request:
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
- name: Find changed dockerfiles
id: changed-dockerfiles
uses: tj-actions/[email protected]
with:
separator: ","
files: |
**/Dockerfile
**/.platforms
- 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
make-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: Make docker image
id: docker_build
uses: docker/build-push-action@v5
with:
context: ${{ matrix.context.path }}
platforms: ${{ matrix.context.platforms }}
push: false
tags: |
"ghcr.io/${{ needs.prepare.outputs.repository_owner }}/${{ matrix.context.name }}:${{ matrix.context.version }}-${{ needs.prepare.outputs.date_stamp }}"
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 }}