diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 2ff9dc4..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,15 +30,15 @@ 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 }}' 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 +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 diff --git a/.github/workflows/release-images.yml b/.github/workflows/release-images.yml index 2356ff1..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 --push linux + docker buildx bake --file docker-bake.hcl --push 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"] }