-
Notifications
You must be signed in to change notification settings - Fork 2
104 lines (98 loc) · 4.19 KB
/
build-container-images.yaml
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
---
name: Build and push container images
env:
CONTAINER_IMAGE_REGISTRY: ghcr.io
permissions:
contents: read
on: # yamllint disable-line rule:truthy
push:
paths:
- ".github/workflows/build-container-images.yaml"
- "docker/**"
- "config/ansible/roles/ferrarimarco_home_lab_node/files/config/dependency-updates-helper/**"
- "config/ansible/roles/ferrarimarco_home_lab_node/files/config/restic/**"
pull_request:
paths:
- ".github/workflows/build-container-images.yaml"
- "docker/**"
- "config/ansible/roles/ferrarimarco_home_lab_node/files/config/dependency-updates-helper/**"
- "config/ansible/roles/ferrarimarco_home_lab_node/files/config/restic/**"
jobs:
build-container-images:
concurrency:
# Ref: https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
# github.head_ref: head_ref or source branch of the pull request
# github.ref: ref of the branch that triggered the workflow
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}-${{ github.event_name }}-${{ matrix.container-images.name }}
cancel-in-progress: true
env:
CONTAINER_IMAGE_ID: "${{ github.repository }}-${{ matrix.container-images.name }}"
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Validate Docker build configuration
shell: bash
run: |
DOCKER_BUILD_COMMAND=(docker buildx build --check)
if [[ -n "${{ matrix.container-images.build-contexts }}" ]]; then
# TODO: add more parsing logic if there's more than one build context
# xargs trims the string
DOCKER_BUILD_COMMAND+=(--build-context="$(xargs echo "${{ matrix.container-images.build-contexts }}")")
fi
DOCKER_BUILD_COMMAND+=("${{ matrix.container-images.context-directory }}")
echo "Running: ${DOCKER_BUILD_COMMAND[*]}"
"${DOCKER_BUILD_COMMAND[@]}"
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/[email protected]
with:
images: |
${{ env.CONTAINER_IMAGE_REGISTRY }}/${{ env.CONTAINER_IMAGE_ID }}
labels: |
org.opencontainers.image.title=home-lab-${{ matrix.container-images.name }}
org.opencontainers.image.description=${{ matrix.container-images.name }} container image
tags: |
type=edge,enable={{is_default_branch}}
type=ref,event=branch,enable={{is_default_branch}}
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}.{{patch}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Build the ${{ matrix.container-images.name }} container image
uses: docker/build-push-action@v6
with:
build-contexts: ${{ matrix.container-images.build-contexts }}
cache-from: type=gha
cache-to: type=gha,mode=max
context: ${{ matrix.container-images.context-directory }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
strategy:
matrix:
container-images:
- name: ansible
build-contexts: |
ansible-configuration=config/ansible
context-directory: docker/ansible
- name: arduino-cli
build-contexts: null
context-directory: docker/arduino-cli
- name: dependency-updates-helper
build-contexts: null
context-directory: config/ansible/roles/ferrarimarco_home_lab_node/files/config/dependency-updates-helper
- name: restic
build-contexts: null
context-directory: config/ansible/roles/ferrarimarco_home_lab_node/files/config/restic
- name: cd-container
build-contexts: null
context-directory: docker/release-please-commitlint