Skip to content

Commit b5ae9c1

Browse files
authored
refactor: buildx bake matrix target (#59)
* refactor: buildx bake * fix: udate CI workflows
1 parent 316a60d commit b5ae9c1

File tree

4 files changed

+51
-141
lines changed

4 files changed

+51
-141
lines changed

.github/workflows/CI.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ on:
55
branches: [ master ]
66
paths:
77
- '**Dockerfile'
8+
- 'docker-bake.hcl'
89
pull_request:
910
branches: [ master ]
1011
paths:
1112
- '**Dockerfile'
13+
- 'docker-bake.hcl'
1214

1315
jobs:
1416
build:
@@ -28,15 +30,15 @@ jobs:
2830
- name: Get changed files
2931
id: changed-files
3032
uses: tj-actions/[email protected]
33+
- name: Set up Docker Buildx
34+
uses: docker/[email protected]
3135
- name: Build & Test (Publish) image
3236
run: |
3337
docker login -u '${{ secrets.DOCKER_USERNAME }}' -p '${{ secrets.DOCKER_PASSWORD }}'
3438
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
3539
if [[ "$file" == *"Dockerfile" ]]; then
3640
set -e
37-
echo "start to build ..."
38-
make prune
39-
make build TARGET=clang-tools-`dirname $file`
41+
docker buildx bake --file docker-bake.hcl clang-tools-`dirname $file`
4042
docker images
4143
4244
echo "start to test ..."
@@ -57,7 +59,7 @@ jobs:
5759
5860
if [[ $GITHUB_EVENT_NAME == 'push' ]]; then
5961
echo "start to publish ..."
60-
make publish TARGET=clang-tools-`dirname $file`
62+
docker buildx bake --file docker-bake.hcl --push clang-tools-`dirname $file`
6163
fi
6264
fi
6365
done

.github/workflows/release-images.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ on:
44
workflow_dispatch:
55
push:
66
branches: [ master ]
7+
paths:
8+
- '**Dockerfile'
9+
- 'docker-bake.hcl'
710

811
jobs:
912
build:
@@ -15,7 +18,9 @@ jobs:
1518
echo $CR_PAT | docker login ghcr.io -u shenxianpeng --password-stdin
1619
env:
1720
CR_PAT: ${{ secrets.CR_PAT }}
18-
- name: Docker Buildx Bake
21+
- name: Set up Docker Buildx
22+
uses: docker/[email protected]
23+
- name: Build and push images
1924
run: |
2025
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
21-
docker buildx bake --file docker-bake.hcl --push linux
26+
docker buildx bake --file docker-bake.hcl --push clang-tools

CONTRIBUTING.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Contributing
2+
3+
Thank you for investing your time in contributing to our project! We welcome feedback, bug reports, and pull requests!
4+
5+
## New contributor guide
6+
7+
For pull requests, please stick to the following guidelines
8+
9+
* Put a reasonable amount of comments into the code.
10+
* Fork clang-tools-docker on your GitHub user account, do your changes there and then create a PR against `master` branch of cpp-linter-action repository.
11+
* Separate unrelated changes into multiple pull requests.
12+
13+
Please note that by contributing any code or documentation to this repository (by raising pull requests, or otherwise) you explicitly agree to the [License Agreement](https://github.com/cpp-linter/clang-tools-docker/blob/master/LICENSE).
14+
15+
## Build image with [`docker buildx bake`](https://docs.docker.com/engine/reference/commandline/buildx_bake/)
16+
17+
> **Note**
18+
> Becasue I used buildx [matrix-builds](https://docs.docker.com/build/bake/configuring-build/#matrix-builds), `buildx` version must be v0.11.0 or above.
19+
20+
```bash
21+
# Build all docker iamges
22+
docker buildx bake --file docker-bake.hcl clang-tools
23+
24+
# Build specific version of clang-tools docker images
25+
docker buildx bake --file docker-bake.hcl clang-tools:16
26+
27+
# If want to docker build and push images, add `--push` flag.
28+
docker buildx bake --file docker-bake.hcl --push clang-tools:16
29+
```

docker-bake.hcl

Lines changed: 9 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ---- groups ----
2-
group "linux" {
2+
group "clang-tools" {
33
targets = [
44
"clang-tools-6",
55
"clang-tools-7",
@@ -32,142 +32,16 @@ variable "ALPINE_VERSION" {
3232
}
3333

3434
# ---- targets ----
35-
target "clang-tools-6" {
36-
dockerfile = "6/Dockerfile"
35+
target "clang-tools" {
36+
matrix = {
37+
tgt = ["all", "16", "15", "14", "13", "12", "12-alpine", "11", "11-alpine", "10", "9", "8", "7", "6"]
38+
}
39+
name = "clang-tools-${tgt}"
40+
dockerfile = "${tgt}/Dockerfile"
3741
context = "."
3842
tags = [
39-
"${DOCKER_REPO}:6",
40-
"${GITHUB_REPO}:6"
41-
]
42-
platforms = ["linux/amd64"]
43-
}
44-
45-
target "clang-tools-7" {
46-
dockerfile = "7/Dockerfile"
47-
context = "."
48-
tags = [
49-
"${DOCKER_REPO}:7",
50-
"${GITHUB_REPO}:7"
51-
]
52-
platforms = ["linux/amd64"]
53-
}
54-
55-
target "clang-tools-8" {
56-
dockerfile = "8/Dockerfile"
57-
context = "."
58-
tags = [
59-
"${DOCKER_REPO}:8",
60-
"${GITHUB_REPO}:8"
61-
]
62-
platforms = ["linux/amd64"]
63-
}
64-
65-
target "clang-tools-9" {
66-
dockerfile = "9/Dockerfile"
67-
context = "."
68-
tags = [
69-
"${DOCKER_REPO}:9",
70-
"${GITHUB_REPO}:9"
71-
]
72-
platforms = ["linux/amd64"]
73-
}
74-
75-
target "clang-tools-10" {
76-
dockerfile = "10/Dockerfile"
77-
context = "."
78-
tags = [
79-
"${DOCKER_REPO}:10",
80-
"${GITHUB_REPO}:10"
81-
]
82-
platforms = ["linux/amd64"]
83-
}
84-
85-
target "clang-tools-11" {
86-
dockerfile = "11/Dockerfile"
87-
context = "."
88-
tags = [
89-
"${DOCKER_REPO}:11",
90-
"${GITHUB_REPO}:11"
91-
]
92-
platforms = ["linux/amd64"]
93-
}
94-
95-
target "clang-tools-11-alpine" {
96-
dockerfile = "11-alpine/Dockerfile"
97-
context = "."
98-
tags = [
99-
"${DOCKER_REPO}:11-alpine-${ALPINE_VERSION}",
100-
"${GITHUB_REPO}:11-alpine-${ALPINE_VERSION}"
101-
]
102-
platforms = ["linux/amd64"]
103-
}
104-
105-
target "clang-tools-12" {
106-
dockerfile = "12/Dockerfile"
107-
context = "."
108-
tags = [
109-
"${DOCKER_REPO}:12",
110-
"${GITHUB_REPO}:12"
111-
]
112-
platforms = ["linux/amd64"]
113-
}
114-
115-
target "clang-tools-12-alpine" {
116-
dockerfile = "12-alpine/Dockerfile"
117-
context = "."
118-
tags = [
119-
"${DOCKER_REPO}:12-alpine-${ALPINE_VERSION}",
120-
"${GITHUB_REPO}:12-alpine-${ALPINE_VERSION}"
121-
]
122-
platforms = ["linux/amd64"]
123-
}
124-
125-
target "clang-tools-13" {
126-
dockerfile = "13/Dockerfile"
127-
context = "."
128-
tags = [
129-
"${DOCKER_REPO}:13",
130-
"${GITHUB_REPO}:13"
131-
]
132-
platforms = ["linux/amd64"]
133-
}
134-
135-
target "clang-tools-14" {
136-
dockerfile = "14/Dockerfile"
137-
context = "."
138-
tags = [
139-
"${DOCKER_REPO}:14",
140-
"${GITHUB_REPO}:14"
141-
]
142-
platforms = ["linux/amd64"]
143-
}
144-
145-
target "clang-tools-15" {
146-
dockerfile = "15/Dockerfile"
147-
context = "."
148-
tags = [
149-
"${DOCKER_REPO}:15",
150-
"${GITHUB_REPO}:15"
151-
]
152-
platforms = ["linux/amd64"]
153-
}
154-
155-
target "clang-tools-16" {
156-
dockerfile = "16/Dockerfile"
157-
context = "."
158-
tags = [
159-
"${DOCKER_REPO}:16",
160-
"${GITHUB_REPO}:16"
161-
]
162-
platforms = ["linux/amd64"]
163-
}
164-
165-
target "clang-tools-all" {
166-
dockerfile = "all/Dockerfile"
167-
context = "."
168-
tags = [
169-
"${DOCKER_REPO}:all",
170-
"${GITHUB_REPO}:all"
43+
"${DOCKER_REPO}:${tgt}",
44+
"${GITHUB_REPO}:${tgt}"
17145
]
17246
platforms = ["linux/amd64"]
17347
}

0 commit comments

Comments
 (0)