-
Notifications
You must be signed in to change notification settings - Fork 1
188 lines (164 loc) · 6.51 KB
/
container-build-and-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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#
# File: https://github.com/cpp-projects-showcase/docker-images/blob/main/.github/workflows/container-build-and-publish.yml
#
# On Docker Hub:
# * https://hub.docker.com/repository/docker/infrahelpers/cpppython/tags
#
# Dockerfiles:
# * CentOS Stream 9: https://github.com/cpp-projects-showcase/docker-images/blob/main/centos9/Dockerfile
# * Usual tags on Docker Hub: infrahelpers/cpppython:centos9
# * Rocky 9: https://github.com/cpp-projects-showcase/docker-images/blob/main/rocky9/Dockerfile
# * Usual tags on Docker Hub: infrahelpers/cpppython:rocky9
#
# Docker Cloud builds
# -------------------
# The number of build minutes are limited per month, and increasing
# that limit is expensive. The activation of Docker Cloud builds is
# therefore commented throughout this CI/CD pipeline.
# References:
# * https://docs.docker.com/build-cloud/
# * https://docs.docker.com/build-cloud/ci/
# * Cloud builders: https://app.docker.com/build/accounts/infrahelpers/builders
#
# SBOM and attestations of provenance
# -----------------------------------
# * https://docs.docker.com/scout/policy/#supply-chain-attestations
# * https://docs.docker.com/build/metadata/attestations/
# * With GitHub Actions:
# https://docs.docker.com/build/ci/github-actions/attestations/
#
# Scheduling builds
# -----------------
# * https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows
# * https://crontab.guru/#0_2_*_*_*
#
name: Build and publish container images onto Docker Cloud
on:
push:
branches:
- main
schedule:
- cron: "0 2 * * *" # Trigeer a build every 1st day of the month at 02:00 UTC
workflow_dispatch:
env:
ORG_NAME: infrahelpers
IMAGE_NAME: infrahelpers/cpppython
jobs:
# CentOS Stream 9
build_centos9_image:
# https://github.com/cpp-projects-showcase/docker-images/settings/environments/4430897264/edit
environment: docker-hub
runs-on: ubuntu-latest
steps:
# https://github.com/actions/checkout
- name: Checkout
uses: actions/checkout@v4
# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
# https://github.com/docker/login-action
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
# Uncomment the following to activate the Docker Cloud builds
#with:
# version: "lab:latest"
# driver: cloud
# endpoint: "${{ env.ORG_NAME}}/default"
# install: true
# https://github.com/docker/metadata-action
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}:centos9
- name: Run privileged
run: sudo docker run --privileged --rm tonistiigi/binfmt --install arm64
# https://github.com/docker/build-push-action
- name: Build CentOS Stream 9 image
id: docker_build_centos9
uses: docker/build-push-action@v6
with:
builder: ${{ steps.buildx.outputs.name }}
context: ./centos9
file: ./centos9/Dockerfile
push: true
provenance: mode=max
sbom: true
tags: |
${{ env.IMAGE_NAME }}:centos9
# For pull requests, export results to the build cache.
# Otherwise, push to a registry.
# Uncomment the following 3 lines to activate the Docker Cloud builds
#outputs: ${{ github.event_name == 'pull_request' && 'type=cacheonly' || 'type=registry' }}
#cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:build-cache-centos9
#cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:build-cache-centos9,mode=max
# Comment the following 2 lines when activating the Docker Cloud builds
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64/v8
# Rocky 9
build_rocky9_image:
# https://github.com/cpp-projects-showcase/docker-images/settings/environments/4430897264/edit
environment: docker-hub
runs-on: ubuntu-latest
steps:
# https://github.com/actions/checkout
- name: Checkout
uses: actions/checkout@v4
# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
# https://github.com/docker/login-action
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
# Uncomment the following to activate the Docker Cloud builds
#with:
# version: "lab:latest"
# driver: cloud
# endpoint: "${{ env.ORG_NAME}}/default"
# install: true
# https://github.com/docker/metadata-action
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}:rocky9
- name: Run privileged
run: sudo docker run --privileged --rm tonistiigi/binfmt --install arm64
# https://github.com/docker/build-push-action
- name: Build Rocky 9 image
id: docker_build_rocky9
uses: docker/build-push-action@v6
with:
builder: ${{ steps.buildx.outputs.name }}
context: ./rocky9
file: ./rocky9/Dockerfile
push: true
provenance: mode=max
sbom: true
tags: |
${{ env.IMAGE_NAME }}:rocky9
# For pull requests, export results to the build cache.
# Otherwise, push to a registry.
# Uncomment the following 3 lines to activate the Docker Cloud builds
#outputs: ${{ github.event_name == 'pull_request' && 'type=cacheonly' || 'type=registry' }}
#cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:build-cache-rocky9
#cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:build-cache-rocky9,mode=max
# Comment the following 2 lines when activating the Docker Cloud builds
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64/v8