Skip to content

Commit 65271fa

Browse files
authored
feat: goreleaser, multi platform build, cosign (#167)
1 parent ed8a368 commit 65271fa

10 files changed

+207
-131
lines changed

.github/workflows/build-and-publish-release.yml

-68
This file was deleted.

.github/workflows/release.yaml

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: release
2+
3+
on:
4+
push:
5+
tags:
6+
- v*.*.* # stable release, v0.0.1
7+
- v*.*.*-pre.* # pre-release, v0.0.1-pre.calendardate
8+
9+
permissions:
10+
contents: write
11+
packages: write
12+
id-token: write # needed for signing the images with GitHub OIDC Token
13+
14+
jobs:
15+
release:
16+
runs-on: ubuntu-22.04
17+
steps:
18+
- name: Set up QEMU # required for multi architecture build - https://goreleaser.com/cookbooks/multi-platform-docker-images/?h=multi#other-things-to-pay-attention-to
19+
uses: docker/setup-qemu-action@v2
20+
21+
- name: Checkout
22+
uses: actions/checkout@v3
23+
with:
24+
fetch-depth: 0 # required for changelog to work properly - https://github.com/goreleaser/goreleaser-action#usage
25+
submodules: true
26+
27+
- name: Install NodeJS
28+
uses: actions/setup-node@v3
29+
with:
30+
node-version: '17'
31+
32+
- name: Build argo-watcher UI
33+
run: make build-ui
34+
35+
- name: Install Cosign
36+
uses: sigstore/[email protected]
37+
38+
- name: Install Syft for SBOM Generation
39+
uses: anchore/sbom-action@v0
40+
41+
- name: Set up Go
42+
uses: actions/setup-go@v4
43+
with:
44+
go-version-file: go.mod
45+
46+
- name: Login to GitHub Container Registry
47+
uses: docker/login-action@v2
48+
with:
49+
registry: ghcr.io
50+
username: ${{ github.actor }}
51+
password: ${{ secrets.GITHUB_TOKEN }}
52+
53+
- name: Run GoReleaser for stable release
54+
uses: goreleaser/goreleaser-action@v4
55+
if: (!contains(github.ref, 'pre'))
56+
with:
57+
version: v1.19.2
58+
args: release --clean
59+
env:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
62+
- name: Run GoReleaser for pre-release
63+
uses: goreleaser/goreleaser-action@v4
64+
if: contains(github.ref, 'pre')
65+
with:
66+
version: v1.19.2
67+
args: release --clean
68+
env:
69+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
70+
GORELEASER_CURRENT_TAG: ${{ steps.changelog.outputs.RELEASE_TAG }}
71+
72+
- name: Update helm chart
73+
uses: shini4i/helm-charts-updater@v1
74+
if: startsWith(github.ref, 'refs/tags/v')
75+
with:
76+
github_token: ${{ secrets.GH_TOKEN }}
77+
gh_user: shini4i
78+
gh_repo: charts
79+
chart_name: argo-watcher
80+
app_version: ${{ github.ref_name }}
81+
update_chart_annotations: true

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ bin/
2323
# dynamicly generated files
2424
cmd/argo-watcher/docs
2525
cmd/argo-watcher/mock
26+
27+
# goreleaser
28+
dist/

.goreleaser.yaml

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
before:
2+
hooks:
3+
- make install-deps docs mocks
4+
- go mod tidy
5+
6+
builds:
7+
- id: argo-watcher
8+
main: ./cmd/argo-watcher
9+
env:
10+
- CGO_ENABLED=0
11+
goos:
12+
- linux
13+
goarch:
14+
- amd64
15+
- arm64
16+
17+
dockers:
18+
- image_templates:
19+
- 'ghcr.io/shini4i/{{.ProjectName}}:{{ .Tag }}-amd64'
20+
use: buildx
21+
build_flag_templates:
22+
- "--pull"
23+
- "--platform=linux/amd64"
24+
- "--label=org.opencontainers.image.created={{.Date}}"
25+
- "--label=org.opencontainers.image.title={{.ProjectName}}"
26+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
27+
- "--label=org.opencontainers.image.version={{.Version}}"
28+
- "--label=org.opencontainers.image.licenses=MIT"
29+
goos: linux
30+
goarch: amd64
31+
extra_files:
32+
- web/build
33+
- image_templates:
34+
- 'ghcr.io/shini4i/{{.ProjectName}}:{{ .Tag }}-arm64'
35+
use: buildx
36+
build_flag_templates:
37+
- "--pull"
38+
- "--platform=linux/arm64"
39+
- "--label=org.opencontainers.image.created={{.Date}}"
40+
- "--label=org.opencontainers.image.title={{.ProjectName}}"
41+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
42+
- "--label=org.opencontainers.image.version={{.Version}}"
43+
- "--label=org.opencontainers.image.licenses=MIT"
44+
goos: linux
45+
goarch: arm64
46+
extra_files:
47+
- web/build
48+
49+
docker_manifests:
50+
- name_template: 'ghcr.io/shini4i/{{.ProjectName}}:{{ .Tag }}'
51+
image_templates:
52+
- 'ghcr.io/shini4i/{{.ProjectName}}:{{ .Tag }}-amd64'
53+
- 'ghcr.io/shini4i/{{.ProjectName}}:{{ .Tag }}-arm64'
54+
55+
archives:
56+
- format: tar.gz
57+
name_template: "{{ .ProjectName }}_{{ .Tag }}_{{ .Os }}_{{ .Arch }}"
58+
59+
sboms:
60+
- artifacts: archive
61+
62+
signs:
63+
- cmd: cosign
64+
certificate: "${artifact}.pem"
65+
output: true
66+
artifacts: checksum
67+
args:
68+
- "sign-blob"
69+
- "--output-certificate=${certificate}"
70+
- "--output-signature=${signature}"
71+
- "${artifact}"
72+
- "--yes"
73+
74+
docker_signs:
75+
- cmd: cosign
76+
artifacts: manifests
77+
args:
78+
- "sign"
79+
- "${artifact}@${digest}"
80+
- "--yes"
81+
82+
checksum:
83+
name_template: 'checksums.txt'
84+
85+
snapshot:
86+
name_template: "{{ incpatch .Version }}-next"
87+
88+
changelog:
89+
use:
90+
github-native
91+
92+
release:
93+
prerelease: auto
94+
draft: false

Dockerfile

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
FROM alpine:3.18
22

3-
COPY ./bin/argo-watcher /argo-watcher
4-
COPY ./web/build /static
3+
COPY argo-watcher /argo-watcher
4+
COPY web/build /static
55

66
RUN addgroup -S argo-watcher && adduser -S argo-watcher -G argo-watcher
77
RUN apk add --no-cache ca-certificates
88

9-
COPY db /db
10-
119
USER argo-watcher
1210

1311
CMD ["/argo-watcher", "-server"]

Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ build: ensure-dirs docs ## Build the binaries
3131
@CGO_ENABLED=0 go build -ldflags="-s -w -X main.version=${VERSION}" -o bin/argo-watcher ./cmd/argo-watcher
3232
@echo "===> Done"
3333

34+
.PHONY: build-goreleaser
35+
build-goreleaser:
36+
@echo "===> Building [$(CYAN)${VERSION}$(RESET)] version of [$(CYAN)argo-watcher$(RESET)] binary"
37+
@goreleaser build --snapshot --clean --single-target
38+
@echo "===> Done"
39+
3440
.PHONY: build-ui
3541
build-ui: ## Build the UI
3642
@echo "===> Building UI"

go.mod

+3-13
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ require (
1717
github.com/swaggo/gin-swagger v1.5.2
1818
github.com/swaggo/swag v1.16.1
1919
go.uber.org/mock v0.2.0
20+
gorm.io/datatypes v1.2.0
21+
gorm.io/driver/postgres v1.5.2
22+
gorm.io/gorm v1.25.2
2023
)
2124

2225
require (
@@ -38,8 +41,6 @@ require (
3841
github.com/go-sql-driver/mysql v1.7.0 // indirect
3942
github.com/goccy/go-json v0.10.2 // indirect
4043
github.com/golang/protobuf v1.5.2 // indirect
41-
github.com/hashicorp/errwrap v1.1.0 // indirect
42-
github.com/hashicorp/go-multierror v1.1.1 // indirect
4344
github.com/jackc/pgpassfile v1.0.0 // indirect
4445
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
4546
github.com/jackc/pgx/v5 v5.3.1 // indirect
@@ -60,15 +61,8 @@ require (
6061
github.com/prometheus/client_model v0.2.0 // indirect
6162
github.com/prometheus/common v0.32.1 // indirect
6263
github.com/prometheus/procfs v0.7.3 // indirect
63-
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
6464
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
6565
github.com/ugorji/go/codec v1.2.11 // indirect
66-
github.com/uptrace/bun v1.1.14 // indirect
67-
github.com/uptrace/bun/dialect/pgdialect v1.1.14 // indirect
68-
github.com/uptrace/bun/driver/pgdriver v1.1.14 // indirect
69-
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
70-
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
71-
go.uber.org/atomic v1.7.0 // indirect
7266
golang.org/x/arch v0.3.0 // indirect
7367
golang.org/x/crypto v0.10.0 // indirect
7468
golang.org/x/net v0.11.0 // indirect
@@ -77,9 +71,5 @@ require (
7771
golang.org/x/tools v0.10.0 // indirect
7872
google.golang.org/protobuf v1.30.0 // indirect
7973
gopkg.in/yaml.v3 v3.0.1 // indirect
80-
gorm.io/datatypes v1.2.0 // indirect
8174
gorm.io/driver/mysql v1.4.7 // indirect
82-
gorm.io/driver/postgres v1.5.2 // indirect
83-
gorm.io/gorm v1.25.2 // indirect
84-
mellium.im/sasl v0.3.1 // indirect
8575
)

0 commit comments

Comments
 (0)