-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ci] Support multi-arch Docker images (amd64/arm64)
Signed-off-by: dntosas <[email protected]>
- Loading branch information
Showing
8 changed files
with
140 additions
and
87 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,106 @@ | ||
# before: | ||
# hooks: | ||
# - go mod download | ||
dist: bin | ||
project_name: capi2argo-cluster-operator | ||
env: | ||
- DOCKER_REPO="ghcr.io/dntosas" | ||
builds: | ||
- env: | ||
- CGO_ENABLED=0 | ||
binary: "{{ .ProjectName }}" | ||
goos: | ||
- linux | ||
goarch: | ||
- amd64 | ||
- arm64 | ||
flags: | ||
- -trimpath | ||
- -mod=vendor | ||
ldflags: | ||
- -s -w | ||
- -X {{ .ProjectName }}/cmd.Version={{ .Version }} | ||
- -X {{ .ProjectName }}/cmd.CommitHash={{ .FullCommit }} | ||
main: . | ||
|
||
dockers: | ||
# amd64 | ||
- image_templates: | ||
- ghcr.io/dntosas/{{ .ProjectName }}:{{ .Version }}-amd64 | ||
- ghcr.io/dntosas/{{ .ProjectName }}:v{{ .Version }}-amd64 | ||
- ghcr.io/dntosas/{{ .ProjectName }}:latest-amd64 | ||
dockerfile: Dockerfile | ||
use: buildx | ||
goos: linux | ||
goarch: amd64 | ||
build_flag_templates: | ||
- "--pull" | ||
- "--label=org.opencontainers.image.created={{.Date}}" | ||
- "--label=org.opencontainers.image.title={{.ProjectName}}" | ||
- "--label=org.opencontainers.image.revision={{.FullCommit}}" | ||
- "--label=org.opencontainers.image.version={{.Version}}" | ||
- "--platform=linux/amd64" | ||
# arm64 | ||
- image_templates: | ||
- ghcr.io/dntosas/{{ .ProjectName }}:{{ .Version }}-arm64 | ||
- ghcr.io/dntosas/{{ .ProjectName }}:v{{ .Version }}-arm64 | ||
- ghcr.io/dntosas/{{ .ProjectName }}:latest-arm64 | ||
dockerfile: Dockerfile | ||
use: buildx | ||
goos: linux | ||
goarch: arm64 | ||
build_flag_templates: | ||
- "--pull" | ||
- "--label=org.opencontainers.image.created={{.Date}}" | ||
- "--label=org.opencontainers.image.title={{.ProjectName}}" | ||
- "--label=org.opencontainers.image.revision={{.FullCommit}}" | ||
- "--label=org.opencontainers.image.version={{.Version}}" | ||
- "--platform=linux/arm64/v8" | ||
|
||
docker_manifests: | ||
# https://goreleaser.com/customization/docker_manifest/ | ||
- name_template: ghcr.io/dntosas/{{ .ProjectName }}:{{ .Version }} | ||
image_templates: | ||
- ghcr.io/dntosas/{{ .ProjectName }}:{{ .Version }}-amd64 | ||
- ghcr.io/dntosas/{{ .ProjectName }}:{{ .Version }}-arm64 | ||
- name_template: ghcr.io/dntosas/{{ .ProjectName }}:v{{ .Version }} | ||
image_templates: | ||
- ghcr.io/dntosas/{{ .ProjectName }}:{{ .Version }}-amd64 | ||
- ghcr.io/dntosas/{{ .ProjectName }}:{{ .Version }}-arm64 | ||
- name_template: ghcr.io/dntosas/{{ .ProjectName }}:latest | ||
image_templates: | ||
- ghcr.io/dntosas/{{ .ProjectName }}:latest-amd64 | ||
- ghcr.io/dntosas/{{ .ProjectName }}:latest-arm64 | ||
|
||
# TODO: Sign docker images | ||
# docker_signs: | ||
# - artifacts: all | ||
# stdin: "{{ .Env.COSIGN_PASSWORD }}" | ||
# args: ["sign", "--key=cosign.key", "${artifact}@${digest}", "--yes"] | ||
|
||
archives: | ||
- format: tar.gz | ||
# this name template makes the OS and Arch compatible with the results of uname. | ||
name_template: >- | ||
{{ .ProjectName }}_ | ||
{{- title .Os }}_ | ||
{{- if eq .Arch "amd64" }}x86_64 | ||
{{- else if eq .Arch "386" }}i386 | ||
{{- else }}{{ .Arch }}{{ end }} | ||
{{- if .Arm }}v{{ .Arm }}{{ end }} | ||
# use zip for windows archives | ||
format_overrides: | ||
- goos: windows | ||
format: zip | ||
checksum: | ||
name_template: 'checksums.txt' | ||
snapshot: | ||
name_template: "{{ incpatch .Version }}-SNAPSHOT" | ||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- '^Merge\spull\srequest\s' | ||
|
||
# release: | ||
# draft: true |
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 |
---|---|---|
|
@@ -16,44 +16,11 @@ jobs: | |
|
||
- name: Checkout code | ||
uses: actions/[email protected] | ||
|
||
- name: "Extract data from tag: version, message, body" | ||
id: tag | ||
run: | | ||
git fetch --tags --force | ||
- name: Build CLI binary and Docker image | ||
run: make build | ||
|
||
- name: Generate sha256 checksums | ||
run: make checksums | ||
|
||
- name: Produce Release Body | ||
id: git_log | ||
uses: beatlabs/release-changelog-action@64cc16a4cca8ccf9672c9383cc9234c675a5acbe #v0.0.1 | ||
with: | ||
tag_regex: "v[0-9]+.[0-9]+.[0-9]+" | ||
fetch-depth: 0 | ||
|
||
- name: Create Release | ||
id: create_release | ||
uses: actions/[email protected] | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ github.ref }} | ||
release_name: ${{ github.ref }} | ||
body: ${{ steps.git_log.outputs.release_body }} | ||
draft: false | ||
prerelease: false | ||
|
||
- name: Docker Metadata | ||
id: meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: | | ||
ghcr.io/dntosas/capi2argo-cluster-operator | ||
tags: | | ||
type=semver,pattern=v{{major}}.{{minor}}.{{patch}} | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v2 | ||
|
@@ -63,55 +30,31 @@ jobs: | |
password: ${{ secrets.GITHUB_TOKEN }} | ||
logout: false | ||
|
||
- name: Build and Push Docker Image | ||
uses: docker/[email protected] | ||
with: | ||
context: . | ||
file: .//Dockerfile | ||
tags: | | ||
${{ steps.meta.outputs.tags }} | ||
pull: true | ||
push: true | ||
|
||
- name: Upload Release Asset Linux | ||
id: upload-release-asset-linux | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: ./bin/capi2argo-cluster-operator | ||
asset_name: capi2argo-cluster-operator | ||
asset_content_type: application/octet-stream | ||
|
||
- name: Upload Release Asset Linux checksum | ||
id: upload-release-asset-linux-checksum | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: ./bin/capi2argo-cluster-operator.sha256 | ||
asset_name: capi2argo-cluster-operator.sha256 | ||
asset_content_type: text/plain | ||
|
||
- name: Install Cosign | ||
uses: sigstore/[email protected] | ||
with: | ||
cosign-release: 'v1.9.0' | ||
cosign-release: 'v2.0.0' | ||
|
||
- name: Write signing key to disk | ||
- name: Write Cosign signing key to disk | ||
run: 'echo "$KEY" > cosign.key' | ||
shell: bash | ||
env: | ||
KEY: ${{ secrets.COSIGN_PRIVATE_KEY }} | ||
|
||
- name: Sign container image with annotations from our environment | ||
run: | | ||
cosign sign --key cosign.key \ | ||
-a "repo=${{ github.repository }}" \ | ||
-a "workflow=${{ github.workflow }}" \ | ||
-a "ref=${{ github.sha }}" \ | ||
ghcr.io/dntosas/capi2argo-cluster-operator:${{ github.event.release.tag_name }} | ||
- name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v4 | ||
with: | ||
args: release --clean --config .github/config/goreleaser.yaml | ||
env: | ||
COSIGN_PASSWORD: "" | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
COSIGN_PASSWORD: ${{ secrets.COSIGN_PRIVATE_KEY }} | ||
|
||
# - name: Sign container image with annotations from our environment | ||
# run: | | ||
# cosign sign --key cosign.key \ | ||
# -a "repo=${{ github.repository }}" \ | ||
# -a "workflow=${{ github.workflow }}" \ | ||
# -a "ref=${{ github.sha }}" \ | ||
# ghcr.io/dntosas/capi2argo-cluster-operator:${{ github.event.release.tag_name }} | ||
# env: | ||
# COSIGN_PASSWORD: "" |
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 |
---|---|---|
|
@@ -23,3 +23,7 @@ testbin/* | |
*.swp | ||
*.swo | ||
*~ | ||
|
||
dist/ | ||
|
||
cosign.key |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Switch to distroless as minimal base image to package the capi2argo-cluster-operator binary | ||
FROM "gcr.io/distroless/static:nonroot" | ||
WORKDIR / | ||
COPY bin/capi2argo-cluster-operator . | ||
COPY capi2argo-cluster-operator . | ||
USER 65532:65532 | ||
ENTRYPOINT ["/capi2argo-cluster-operator"] |
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
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
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
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