Skip to content

refactor: buildx bake matrix target #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ on:
branches: [ master ]
paths:
- '**Dockerfile'
- 'docker-bake.hcl'
pull_request:
branches: [ master ]
paths:
- '**Dockerfile'
- 'docker-bake.hcl'

jobs:
build:
Expand All @@ -28,15 +30,15 @@ jobs:
- name: Get changed files
id: changed-files
uses: tj-actions/[email protected]
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Build & Test (Publish) image
run: |
docker login -u '${{ secrets.DOCKER_USERNAME }}' -p '${{ secrets.DOCKER_PASSWORD }}'
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
if [[ "$file" == *"Dockerfile" ]]; then
set -e
echo "start to build ..."
make prune
make build TARGET=clang-tools-`dirname $file`
docker buildx bake --file docker-bake.hcl clang-tools-`dirname $file`
docker images

echo "start to test ..."
Expand All @@ -57,7 +59,7 @@ jobs:

if [[ $GITHUB_EVENT_NAME == 'push' ]]; then
echo "start to publish ..."
make publish TARGET=clang-tools-`dirname $file`
docker buildx bake --file docker-bake.hcl --push clang-tools-`dirname $file`
fi
fi
done
9 changes: 7 additions & 2 deletions .github/workflows/release-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
workflow_dispatch:
push:
branches: [ master ]
paths:
- '**Dockerfile'
- 'docker-bake.hcl'

jobs:
build:
Expand All @@ -15,7 +18,9 @@ jobs:
echo $CR_PAT | docker login ghcr.io -u shenxianpeng --password-stdin
env:
CR_PAT: ${{ secrets.CR_PAT }}
- name: Docker Buildx Bake
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Build and push images
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker buildx bake --file docker-bake.hcl --push linux
docker buildx bake --file docker-bake.hcl --push clang-tools
29 changes: 29 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Contributing

Thank you for investing your time in contributing to our project! We welcome feedback, bug reports, and pull requests!

## New contributor guide

For pull requests, please stick to the following guidelines

* Put a reasonable amount of comments into the code.
* 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.
* Separate unrelated changes into multiple pull requests.

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).

## Build image with [`docker buildx bake`](https://docs.docker.com/engine/reference/commandline/buildx_bake/)

> **Note**
> 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.

```bash
# Build all docker iamges
docker buildx bake --file docker-bake.hcl clang-tools

# Build specific version of clang-tools docker images
docker buildx bake --file docker-bake.hcl clang-tools:16

# If want to docker build and push images, add `--push` flag.
docker buildx bake --file docker-bake.hcl --push clang-tools:16
```
144 changes: 9 additions & 135 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ---- groups ----
group "linux" {
group "clang-tools" {
targets = [
"clang-tools-6",
"clang-tools-7",
Expand Down Expand Up @@ -32,142 +32,16 @@ variable "ALPINE_VERSION" {
}

# ---- targets ----
target "clang-tools-6" {
dockerfile = "6/Dockerfile"
target "clang-tools" {
matrix = {
tgt = ["all", "16", "15", "14", "13", "12", "12-alpine", "11", "11-alpine", "10", "9", "8", "7", "6"]
}
name = "clang-tools-${tgt}"
dockerfile = "${tgt}/Dockerfile"
context = "."
tags = [
"${DOCKER_REPO}:6",
"${GITHUB_REPO}:6"
]
platforms = ["linux/amd64"]
}

target "clang-tools-7" {
dockerfile = "7/Dockerfile"
context = "."
tags = [
"${DOCKER_REPO}:7",
"${GITHUB_REPO}:7"
]
platforms = ["linux/amd64"]
}

target "clang-tools-8" {
dockerfile = "8/Dockerfile"
context = "."
tags = [
"${DOCKER_REPO}:8",
"${GITHUB_REPO}:8"
]
platforms = ["linux/amd64"]
}

target "clang-tools-9" {
dockerfile = "9/Dockerfile"
context = "."
tags = [
"${DOCKER_REPO}:9",
"${GITHUB_REPO}:9"
]
platforms = ["linux/amd64"]
}

target "clang-tools-10" {
dockerfile = "10/Dockerfile"
context = "."
tags = [
"${DOCKER_REPO}:10",
"${GITHUB_REPO}:10"
]
platforms = ["linux/amd64"]
}

target "clang-tools-11" {
dockerfile = "11/Dockerfile"
context = "."
tags = [
"${DOCKER_REPO}:11",
"${GITHUB_REPO}:11"
]
platforms = ["linux/amd64"]
}

target "clang-tools-11-alpine" {
dockerfile = "11-alpine/Dockerfile"
context = "."
tags = [
"${DOCKER_REPO}:11-alpine-${ALPINE_VERSION}",
"${GITHUB_REPO}:11-alpine-${ALPINE_VERSION}"
]
platforms = ["linux/amd64"]
}

target "clang-tools-12" {
dockerfile = "12/Dockerfile"
context = "."
tags = [
"${DOCKER_REPO}:12",
"${GITHUB_REPO}:12"
]
platforms = ["linux/amd64"]
}

target "clang-tools-12-alpine" {
dockerfile = "12-alpine/Dockerfile"
context = "."
tags = [
"${DOCKER_REPO}:12-alpine-${ALPINE_VERSION}",
"${GITHUB_REPO}:12-alpine-${ALPINE_VERSION}"
]
platforms = ["linux/amd64"]
}

target "clang-tools-13" {
dockerfile = "13/Dockerfile"
context = "."
tags = [
"${DOCKER_REPO}:13",
"${GITHUB_REPO}:13"
]
platforms = ["linux/amd64"]
}

target "clang-tools-14" {
dockerfile = "14/Dockerfile"
context = "."
tags = [
"${DOCKER_REPO}:14",
"${GITHUB_REPO}:14"
]
platforms = ["linux/amd64"]
}

target "clang-tools-15" {
dockerfile = "15/Dockerfile"
context = "."
tags = [
"${DOCKER_REPO}:15",
"${GITHUB_REPO}:15"
]
platforms = ["linux/amd64"]
}

target "clang-tools-16" {
dockerfile = "16/Dockerfile"
context = "."
tags = [
"${DOCKER_REPO}:16",
"${GITHUB_REPO}:16"
]
platforms = ["linux/amd64"]
}

target "clang-tools-all" {
dockerfile = "all/Dockerfile"
context = "."
tags = [
"${DOCKER_REPO}:all",
"${GITHUB_REPO}:all"
"${DOCKER_REPO}:${tgt}",
"${GITHUB_REPO}:${tgt}"
]
platforms = ["linux/amd64"]
}