-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
878 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,387 @@ | ||
|
||
name: Reusable build workflow | ||
on: | ||
workflow_call: | ||
inputs: | ||
ref: | ||
description: 'The branch, tag or SHA to build' | ||
required: true | ||
type: string | ||
release: | ||
description: 'Release version tag for this build' | ||
default: '' | ||
required: false | ||
type: string | ||
docker: | ||
description: 'Build docker images' | ||
default: false | ||
required: true | ||
type: boolean | ||
docker_repository: | ||
description: 'Docker Hub Repository' | ||
default: '' | ||
required: false | ||
type: string | ||
docker_tag_prefix: | ||
description: 'Docker Image Tag Prefix' | ||
default: '' | ||
required: false | ||
type: string | ||
additional_tags: | ||
description: 'Additional Docker Image Tags (JSON)' | ||
default: '' | ||
required: false | ||
type: string | ||
secrets: | ||
DOCKERHUB_USERNAME: | ||
description: 'Docker Hub Username' | ||
required: false | ||
DOCKERHUB_TOKEN: | ||
description: 'Docker Hub Token' | ||
required: false | ||
|
||
# shared build jobs | ||
jobs: | ||
build_linux_amd64_binary: | ||
name: Build linux/amd64 binary | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ inputs.ref }} | ||
|
||
# setup global dependencies | ||
- name: Set up go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.21.x | ||
|
||
# setup project dependencies | ||
- name: Get dependencies | ||
run: | | ||
go get -v -t -d ./... | ||
# build binaries | ||
- name: Build linux amd64 binary | ||
run: | | ||
make build | ||
env: | ||
RELEASE: ${{ inputs.release }} | ||
|
||
# upload artifacts | ||
- name: "Upload artifact: assertoor_linux_amd64" | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
path: ./bin/* | ||
name: assertoor_linux_amd64 | ||
|
||
build_linux_arm64_binary: | ||
name: Build linux/arm64 binary | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ inputs.ref }} | ||
|
||
# setup global dependencies | ||
- name: Set up go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.21.x | ||
|
||
# setup cross build libs | ||
- name: Get cross build dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get -y install gcc-aarch64-linux-gnu libstdc++-11-dev-arm64-cross libstdc++-12-dev-arm64-cross | ||
# setup project dependencies | ||
- name: Get dependencies | ||
run: | | ||
go get -v -t -d ./... | ||
# build binaries | ||
- name: Build linux arm64 binary | ||
run: | | ||
make build GOARCH=arm64 CC=/usr/bin/aarch64-linux-gnu-gcc | ||
env: | ||
RELEASE: ${{ inputs.release }} | ||
|
||
# upload artifacts | ||
- name: "Upload artifact: assertoor_linux_arm64" | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
path: ./bin/* | ||
name: assertoor_linux_arm64 | ||
|
||
build_windows_binary: | ||
name: Build windows/amd64 binary | ||
runs-on: windows-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ inputs.ref }} | ||
|
||
# setup global dependencies | ||
- name: Set up go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.21.x | ||
|
||
# setup project dependencies | ||
- name: Get dependencies | ||
run: | | ||
go get -v -t -d ./... | ||
# build binaries | ||
- name: Build windows binary | ||
run: | | ||
make build | ||
env: | ||
RELEASE: ${{ inputs.release }} | ||
|
||
# upload artifacts | ||
- name: "Upload artifact: assertoor_windows_amd64" | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
path: ./bin/* | ||
name: assertoor_windows_amd64 | ||
|
||
build_darwin_amd64_binary: | ||
name: Build macos/amd64 binary | ||
runs-on: macos-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ inputs.ref }} | ||
|
||
# setup global dependencies | ||
- name: Set up go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.21.x | ||
|
||
# setup project dependencies | ||
- name: Get dependencies | ||
run: | | ||
go get -v -t -d ./... | ||
# build binaries | ||
- name: Build macos amd64 binary | ||
run: | | ||
make build | ||
env: | ||
RELEASE: ${{ inputs.release }} | ||
|
||
# upload artifacts | ||
- name: "Upload artifact: assertoor_darwin_amd64" | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
path: ./bin/* | ||
name: assertoor_darwin_amd64 | ||
|
||
build_darwin_arm64_binary: | ||
name: Build macos/arm64 binary | ||
runs-on: macos-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ inputs.ref }} | ||
|
||
# setup global dependencies | ||
- name: Set up go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.21.x | ||
|
||
# setup project dependencies | ||
- name: Get dependencies | ||
run: | | ||
go get -v -t -d ./... | ||
# build binaries | ||
- name: Build macos arm64 binary | ||
run: | | ||
make build GOARCH=arm64 | ||
env: | ||
RELEASE: ${{ inputs.release }} | ||
|
||
# upload artifacts | ||
- name: "Upload artifact: assertoor_darwin_arm64" | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
path: ./bin/* | ||
name: assertoor_darwin_arm64 | ||
|
||
build_amd64_docker_image: | ||
name: Build amd64 docker image | ||
needs: [build_linux_amd64_binary] | ||
if: ${{ inputs.docker }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ inputs.ref }} | ||
|
||
- name: Get build version | ||
id: vars | ||
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | ||
|
||
# prepare docker | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
- name: Login to Docker Hub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
# download build artifacts | ||
- name: Download build artifacts | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: assertoor_linux_amd64 | ||
path: ./bin | ||
|
||
# prepare environment | ||
- name: Prepare build environment | ||
run: | | ||
chmod +x ./bin/* | ||
ls -lach ./bin | ||
# build amd64 image | ||
- name: Build amd64 docker image | ||
run: | | ||
docker build . --file Dockerfile-stub \ | ||
--tag ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-amd64 \ | ||
--tag ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-${{ steps.vars.outputs.sha_short }}-amd64 \ | ||
--platform=linux/amd64 | ||
- name: Push amd64 docker images | ||
run: | | ||
docker push ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-amd64 | ||
docker push ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-${{ steps.vars.outputs.sha_short }}-amd64 | ||
build_arm64_docker_image: | ||
name: Build arm64 docker image | ||
needs: [build_linux_arm64_binary] | ||
if: ${{ inputs.docker }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ inputs.ref }} | ||
- name: Get build version | ||
id: vars | ||
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | ||
|
||
# prepare docker | ||
- name: Set up Docker QEMU | ||
uses: docker/setup-qemu-action@v2 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
- name: Login to Docker Hub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
# download build artifacts | ||
- name: Download build artifacts | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: assertoor_linux_arm64 | ||
path: ./bin | ||
|
||
# prepare environment | ||
- name: Prepare build environment | ||
run: | | ||
chmod +x ./bin/* | ||
ls -lach ./bin | ||
# build arm64 image | ||
- name: Build arm64 docker image | ||
run: | | ||
docker build . --file Dockerfile-stub \ | ||
--tag ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-arm64 \ | ||
--tag ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-${{ steps.vars.outputs.sha_short }}-arm64 \ | ||
--platform=linux/arm64 | ||
- name: Push arm64 docker image | ||
run: | | ||
docker push ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-arm64 | ||
docker push ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-${{ steps.vars.outputs.sha_short }}-arm64 | ||
build_multiarch_image: | ||
name: Build multiarch docker image | ||
needs: [build_amd64_docker_image, build_arm64_docker_image] | ||
if: ${{ inputs.docker }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ inputs.ref }} | ||
- name: Get build version | ||
id: vars | ||
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | ||
|
||
# prepare docker | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
- name: Login to Docker Hub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
# build multiarch image | ||
- name: Build multiarch docker manifest | ||
run: | | ||
docker manifest create ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-${{ steps.vars.outputs.sha_short }} \ | ||
--amend ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-${{ steps.vars.outputs.sha_short }}-amd64 \ | ||
--amend ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-${{ steps.vars.outputs.sha_short }}-arm64 | ||
- name: Push multiarch docker manifest | ||
run: | | ||
docker manifest push ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-${{ steps.vars.outputs.sha_short }} | ||
build_extra_image: | ||
name: Build additional docker manifests | ||
needs: [build_multiarch_image] | ||
if: ${{ inputs.additional_tags }} | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
tag: ${{ fromJSON(inputs.additional_tags) }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ inputs.ref }} | ||
- name: Get build version | ||
id: vars | ||
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | ||
|
||
# prepare docker | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
- name: Login to Docker Hub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
# build multiarch image | ||
- name: "Build additional docker manifest: ${{ matrix.tag }}" | ||
run: | | ||
docker manifest create ${{ inputs.docker_repository }}:${{ matrix.tag }}-amd64 \ | ||
--amend ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-${{ steps.vars.outputs.sha_short }}-amd64 | ||
docker manifest create ${{ inputs.docker_repository }}:${{ matrix.tag }}-arm64 \ | ||
--amend ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-${{ steps.vars.outputs.sha_short }}-arm64 | ||
docker manifest create ${{ inputs.docker_repository }}:${{ matrix.tag }} \ | ||
--amend ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-${{ steps.vars.outputs.sha_short }}-amd64 \ | ||
--amend ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-${{ steps.vars.outputs.sha_short }}-arm64 | ||
- name: "Push additional docker manifest: ${{ matrix.tag }}" | ||
run: | | ||
docker manifest push ${{ inputs.docker_repository }}:${{ matrix.tag }}-amd64 | ||
docker manifest push ${{ inputs.docker_repository }}:${{ matrix.tag }}-arm64 | ||
docker manifest push ${{ inputs.docker_repository }}:${{ matrix.tag }} |
Oops, something went wrong.