From a5ed47a45556be5bb089fe37ab2cd1d683b79328 Mon Sep 17 00:00:00 2001 From: tison Date: Sat, 23 Mar 2024 21:51:52 +0800 Subject: [PATCH] ci: try to remake stage automation Signed-off-by: tison --- .../actions/docker-push-by-digest/action.yml | 53 ++++++++++++ .github/actions/docker-release/action.yml | 60 ++++++++++++++ .github/workflows/release.yml | 82 +++++++++++++++++++ README.md | 17 ++-- 4 files changed, 203 insertions(+), 9 deletions(-) create mode 100644 .github/actions/docker-push-by-digest/action.yml create mode 100644 .github/actions/docker-release/action.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/actions/docker-push-by-digest/action.yml b/.github/actions/docker-push-by-digest/action.yml new file mode 100644 index 0000000..61cdeb5 --- /dev/null +++ b/.github/actions/docker-push-by-digest/action.yml @@ -0,0 +1,53 @@ +# Copyright 2024 tison +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Docker push by digest +description: Build and push Docker image by digest + +inputs: + name: + description: The name of Docker image + required: true + file: + description: The name of Dockerfile in use + required: true + +outputs: + digest: + description: Docker image digest if pushed + value: ${{ steps.push.outputs.digest }} + +runs: + using: composite + steps: + - uses: docker/setup-buildx-action@v2 + - uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ github.token }} + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{ github.repository_owner }}/${{ inputs.name }} + - name: Build and push + id: push + uses: docker/build-push-action@v3 + with: + context: . + file: ${{ inputs.file }} + tags: ghcr.io/${{ github.repository_owner }}/${{ inputs.name }} + labels: ${{ steps.meta.outputs.labels }} + outputs: type=image,push=true,push-by-digest=true diff --git a/.github/actions/docker-release/action.yml b/.github/actions/docker-release/action.yml new file mode 100644 index 0000000..8e2b6ea --- /dev/null +++ b/.github/actions/docker-release/action.yml @@ -0,0 +1,60 @@ +# Copyright 2024 tison +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Docker release +description: Release Docker Images + +inputs: + name: + description: The name of Docker image + required: true + digests: + description: The digest of images to be merged + required: true + +runs: + using: composite + steps: + - uses: docker/setup-buildx-action@v2 + - uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ github.token }} + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{ github.repository_owner }}/${{ inputs.name }} + sep-tags: ' ' + tags: | + type=semver,pattern={{raw}} + type=semver,pattern=v{{major}} + type=sha,format=long + type=edge,branch=main + - name: Build and push + if: ${{ inputs.push }} + uses: docker/build-push-action@v3 + with: + context: . + file: ${{ inputs.file }} + labels: ${{ steps.meta.outputs.labels }} + outputs: type=image,push=true,push-by-digest=true + - name: Push manifest + shell: bash + run: | + for tag in ${{ steps.meta.outputs.tags }}; do + echo "Preparing manifest for tag: $tag..." + docker buildx imagetools create -t $tag ${{ inputs.digests }} + done diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e876b5e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,82 @@ +# Copyright 2024 tison +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Release + +on: + push: + branches: ['main'] + tags: ['v*.*'] + workflow_dispatch: + +jobs: + build-and-push-hawkeye-amd64: + runs-on: ubuntu-latest + permissions: + packages: write + steps: + - uses: actions/checkout@v4 + - name: Build and push by digest + uses: ./.github/actions/docker-push-by-digest + id: build + with: + name: hawkeye + file: Dockerfile + outputs: + digest: ${{ steps.build.outputs.digest }} + + build-and-push-hawkeye-arm64: + runs-on: buildjet-4vcpu-ubuntu-2204-arm + permissions: + packages: write + steps: + - uses: actions/checkout@v4 + - name: Build and push by digest + uses: ./.github/actions/docker-push-by-digest + id: build + with: + name: hawkeye + file: Dockerfile + outputs: + digest: ${{ steps.build.outputs.digest }} + + release-hawkeye: + runs-on: ubuntu-latest + permissions: + packages: write + needs: + - build-and-push-hawkeye-amd64 + - build-and-push-hawkeye-arm64 + steps: + - uses: actions/checkout@v4 + - name: Merge and push manifest + uses: ./.github/actions/docker-release + with: + name: hawkeye + digests: ${{needs.build-and-push-hawkeye-amd64.outputs.digest}} ${{needs.build-and-push-hawkeye-arm64.outputs.digest}} + + release-native: + runs-on: ubuntu-latest + permissions: + packages: write + needs: + - build-and-push-hawkeye-amd64 + - build-and-push-hawkeye-arm64 + steps: + - uses: actions/checkout@v4 + - name: Merge and push manifest + uses: ./.github/actions/docker-release + with: + name: hawkeye-native + digests: ${{needs.build-and-push-hawkeye-native-amd64.outputs.digest}} ${{needs.build-and-push-hawkeye-native-arm64.outputs.digest}} diff --git a/README.md b/README.md index 586199c..523c1d7 100644 --- a/README.md +++ b/README.md @@ -46,16 +46,12 @@ To check license headers in GitHub Actions, add a step in your GitHub workflow: ### Docker -[Native Image](https://www.graalvm.org/22.3/reference-manual/native-image/) powered image (~45MB): - -```shell -docker run -it --rm -v $(pwd):/github/workspace ghcr.io/korandoru/hawkeye-native check -``` - -[Eclipse Temurin](https://projects.eclipse.org/projects/adoptium.temurin) JRE based image (~400MB): +Alpine image (~27MB): ```shell docker run -it --rm -v $(pwd):/github/workspace ghcr.io/korandoru/hawkeye check +# or (for historical reason, duplicate a "hawkeye-native" image) +docker run -it --rm -v $(pwd):/github/workspace ghcr.io/korandoru/hawkeye-native check ``` ## Build @@ -129,6 +125,7 @@ useDefaultMapping = true # Paths to additional header style files. The model of user-defined header style can be found below. # default: empty +# WARNING: not yet re-supported. additionalHeaders = ["..."] # Mapping rules (repeated). @@ -218,6 +215,8 @@ lastLineDetectionPattern = "..." [Apache License 2.0](LICENSE) -## Acknowledgment +## History + +This software is originally from [license-maven-plugin](https://github.com/mathieucarbou/license-maven-plugin),with an initial motivation to bring it beyond a Maven plugin. The core abstractions like `Document`, `Header`, and `HeaderParser` are originally copied from the license-maven-plugin sources under the terms of Apache License 2.0. -This software is derived from [license-maven-plugin](https://github.com/mathieucarbou/license-maven-plugin), with an initial motivation to bring it beyond a Maven plugin. The core abstractions like `Document`, `Header`, and `HeaderResource` are originally copied from the license-maven-plugin sources under the terms of Apache License 2.0. +Later, when I started focusing on the Docker image's size and integrate with Git, I found that Rust is better than Java (GraalVM Native Image) for this purpose. So I rewrote the core logic in Rust and keep ship a slim image.