Skip to content

Commit

Permalink
ci: try to remake stage automation
Browse files Browse the repository at this point in the history
Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun committed Mar 23, 2024
1 parent b011743 commit a5ed47a
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 9 deletions.
53 changes: 53 additions & 0 deletions .github/actions/docker-push-by-digest/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2024 tison <[email protected]>
#
# 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
60 changes: 60 additions & 0 deletions .github/actions/docker-release/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright 2024 tison <[email protected]>
#
# 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
82 changes: 82 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copyright 2024 tison <[email protected]>
#
# 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}}
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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.

0 comments on commit a5ed47a

Please sign in to comment.