From 4dc09384a3c291c47592da504e3da2ac1b1f25c2 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Fri, 30 Jun 2023 11:25:30 -0400 Subject: [PATCH 1/2] refactor: buildx bake --- .github/workflows/CI.yml | 6 +- .github/workflows/release-images.yml | 2 +- CONTRIBUTING.md | 29 ++++++ docker-bake.hcl | 144 ++------------------------- 4 files changed, 41 insertions(+), 140 deletions(-) create mode 100644 CONTRIBUTING.md diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 2ff9dc4..0c5646a 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -34,9 +34,7 @@ jobs: 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 ..." @@ -57,7 +55,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 diff --git a/.github/workflows/release-images.yml b/.github/workflows/release-images.yml index 2356ff1..9db57cb 100644 --- a/.github/workflows/release-images.yml +++ b/.github/workflows/release-images.yml @@ -18,4 +18,4 @@ jobs: - name: Docker Buildx Bake 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 clang-tools diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..454ef36 --- /dev/null +++ b/CONTRIBUTING.md @@ -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 +``` diff --git a/docker-bake.hcl b/docker-bake.hcl index 2a89127..ffd4c93 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -1,5 +1,5 @@ # ---- groups ---- -group "linux" { +group "clang-tools" { targets = [ "clang-tools-6", "clang-tools-7", @@ -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"] } From fac9f4641fcf64692506763e95f22a80c43f1092 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Sat, 1 Jul 2023 14:17:23 +0000 Subject: [PATCH 2/2] fix: udate CI workflows --- .github/workflows/CI.yml | 4 ++++ .github/workflows/release-images.yml | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 0c5646a..34ef9eb 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -5,10 +5,12 @@ on: branches: [ master ] paths: - '**Dockerfile' + - 'docker-bake.hcl' pull_request: branches: [ master ] paths: - '**Dockerfile' + - 'docker-bake.hcl' jobs: build: @@ -28,6 +30,8 @@ jobs: - name: Get changed files id: changed-files uses: tj-actions/changed-files@v18.4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2.8.0 - name: Build & Test (Publish) image run: | docker login -u '${{ secrets.DOCKER_USERNAME }}' -p '${{ secrets.DOCKER_PASSWORD }}' diff --git a/.github/workflows/release-images.yml b/.github/workflows/release-images.yml index 9db57cb..839011b 100644 --- a/.github/workflows/release-images.yml +++ b/.github/workflows/release-images.yml @@ -4,6 +4,9 @@ on: workflow_dispatch: push: branches: [ master ] + paths: + - '**Dockerfile' + - 'docker-bake.hcl' jobs: build: @@ -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/setup-buildx-action@v2.8.0 + - name: Build and push images run: | docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} - docker buildx bake --file docker-bake.hcl clang-tools + docker buildx bake --file docker-bake.hcl --push clang-tools