Skip to content

Commit 00f0122

Browse files
authored
feat(ci): add release workflow (#139)
* chore(ci): release pipeline Signed-off-by: Michael Crenshaw <[email protected]> * bump images Signed-off-by: Michael Crenshaw <[email protected]> * pin goreleaser version Signed-off-by: Michael Crenshaw <[email protected]> * release dockerfile Signed-off-by: Michael Crenshaw <[email protected]> * only release on the promoter repo Signed-off-by: Michael Crenshaw <[email protected]> * address comments Signed-off-by: Michael Crenshaw <[email protected]> * normalize Signed-off-by: Michael Crenshaw <[email protected]> --------- Signed-off-by: Michael Crenshaw <[email protected]>
1 parent 9d290e3 commit 00f0122

File tree

8 files changed

+208
-0
lines changed

8 files changed

+208
-0
lines changed

.github/workflows/release.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# see https://github.com/argoproj-labs/argocd-ephemeral-access/blob/main/.github/workflows/release.yaml
2+
name: release
3+
4+
on:
5+
push:
6+
tags:
7+
- 'v*'
8+
env:
9+
# If set in the repo env vars it will use this tag to build the release notes.
10+
# Useful when creating a release tag after a release candidate tags phase.
11+
GORELEASER_PREVIOUS_TAG: ${{vars.GORELEASER_PREVIOUS_TAG}}
12+
13+
defaults:
14+
run:
15+
shell: bash
16+
17+
jobs:
18+
release:
19+
runs-on: ubuntu-20.04
20+
if: github.repository == 'argoproj-labs/gitops-promoter'
21+
name: Release
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
25+
with:
26+
fetch-depth: 0
27+
28+
- name: Setup Go
29+
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
30+
with:
31+
go-version: 1.22
32+
33+
- name: Docker Login in quay.io
34+
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
35+
with:
36+
registry: quay.io
37+
username: ${{ secrets.QUAY_USERNAME }}
38+
password: ${{ secrets.QUAY_TOKEN }}
39+
40+
- name: Run GoReleaser
41+
uses: goreleaser/goreleaser-action@9ed2f89a662bf1735a48bc8557fd212fa902bebf # v6.1.0
42+
with:
43+
distribution: goreleaser
44+
version: v2.4.8
45+
args: release --clean
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@ go.work
3232
secret.yaml
3333

3434
junit.xml
35+
36+
dist

.goreleaser.yaml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Based on: https://github.com/argoproj-labs/gitops-promoter/blob/main/.goreleaser.yaml
2+
3+
# The lines below are called `modelines`. See `:help modeline`
4+
# yaml-language-server: $schema=https://raw.githubusercontent.com/goreleaser/goreleaser/v2.3.2/www/docs/static/schema.json
5+
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
6+
7+
project_name: gitops-promoter
8+
version: 2
9+
10+
before:
11+
hooks:
12+
- go mod tidy
13+
- go mod download
14+
- make manifests-release IMAGE_TAG={{ .Tag }}
15+
- rm -rf dist
16+
17+
builds:
18+
- id: gitops-promoter
19+
main: ./cmd
20+
binary: gitops-promoter
21+
env:
22+
- CGO_ENABLED=0
23+
flags:
24+
- -v
25+
goos:
26+
- linux
27+
- windows
28+
- darwin
29+
ldflags:
30+
- -X github.com/argoproj-labs/gitops-promoter/common.version={{ .Version }}
31+
- -X github.com/argoproj-labs/gitops-promoter/common.buildDate={{ .Date }}
32+
- -extldflags="-static"
33+
34+
dockers:
35+
- image_templates:
36+
- quay.io/argoprojlabs/gitops-promoter:{{ .Tag }}
37+
dockerfile: release.Dockerfile
38+
skip_push: "{{ .IsSnapshot }}"
39+
build_flag_templates:
40+
- "--pull"
41+
- "--label=org.opencontainers.image.created={{.Date}}"
42+
- "--label=org.opencontainers.image.title={{.ProjectName}}"
43+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
44+
- "--label=org.opencontainers.image.version={{.Version}}"
45+
- "--platform=linux/amd64"
46+
47+
archives:
48+
- id: binary
49+
format: tar.gz
50+
builds:
51+
- "gitops-promoter"
52+
# this name template makes the OS and Arch compatible with the results of `uname`.
53+
name_template: >-
54+
{{ .ProjectName }}_
55+
{{- title .Os }}_
56+
{{- if eq .Arch "amd64" }}x86_64
57+
{{- else if eq .Arch "386" }}i386
58+
{{- else }}{{ .Arch }}{{ end }}
59+
{{- if .Arm }}v{{ .Arm }}{{ end }}
60+
# use zip for windows archives
61+
format_overrides:
62+
- goos: windows
63+
format: zip
64+
65+
release:
66+
prerelease: auto
67+
draft: true
68+
extra_files:
69+
- glob: ./install.yaml
70+
header: |
71+
## gitops-promoter
72+
{{ .Date }}
73+
74+
### Container images
75+
76+
- quay.io/argoprojlabs/gitops-promoter:{{ .Tag }}
77+
78+
footer: |
79+
**Full Changelog**: https://github.com/argoproj-labs/gitops-promoter/compare/{{ .PreviousTag }}...{{ .Tag }}
80+
81+
changelog:
82+
use:
83+
github
84+
sort: asc
85+
abbrev: 0
86+
groups: # Regex use RE2 syntax as defined here: https://github.com/google/re2/wiki/Syntax.
87+
- title: 'Features'
88+
regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
89+
order: 100
90+
- title: 'Bug fixes'
91+
regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
92+
order: 200
93+
- title: 'Documentation'
94+
regexp: '^.*?docs(\([[:word:]]+\))??!?:.+$'
95+
order: 300
96+
- title: 'Dependency updates'
97+
regexp: '^.*?(feat|fix|chore)\(deps?.+\)!?:.+$'
98+
order: 400
99+
- title: 'Other work'
100+
order: 999
101+
filters:
102+
exclude:
103+
- '^test:'
104+
- '^.*?Bump(\([[:word:]]+\))?.+$'

Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ docker-build: ## Build docker image with the manager.
131131
docker-push: ## Push docker image with the manager.
132132
$(CONTAINER_TOOL) push ${IMG}
133133

134+
.PHONY: goreleaser-build-local
135+
goreleaser-build-local: goreleaser ## Run goreleaser build locally. Use to validate the goreleaser configuration.
136+
$(GORELEASER) build --snapshot --clean --single-target --verbose
137+
134138
# PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
135139
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
136140
# - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
@@ -154,6 +158,10 @@ build-installer: manifests generate kustomize ## Generate a consolidated YAML wi
154158
# cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
155159
$(KUSTOMIZE) build config/default > dist/install.yaml
156160

161+
.PHONY: manifests-release
162+
manifests-release: generate manifests kustomize ## Generate the consolidated install.yaml with the release tag.
163+
./hack/manifests-release.sh $(KUSTOMIZE) $(IMAGE_TAG)
164+
157165
##@ Deployment
158166

159167
ifndef ignore-not-found
@@ -193,6 +201,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
193201
MOCKERY = $(LOCALBIN)/mockery-$(MOCKERY_VERSION)
194202
NILAWAY = $(LOCALBIN)/nilaway-$(NILAWAY_VERSION)
195203
GINKGO = $(LOCALBIN)/ginkgo-$(GINKGO_VERSION)
204+
GORELEASER ?= $(LOCALBIN)/goreleaser-$(GORELEASER_VERSION)
196205

197206
## Tool Versions
198207
KUSTOMIZE_VERSION ?= v5.3.0
@@ -202,6 +211,7 @@ GOLANGCI_LINT_VERSION ?= v1.62.0
202211
MOCKERY_VERSION ?= v2.42.2
203212
NILAWAY_VERSION ?= latest
204213
GINKGO_VERSION=$(shell go list -m all | grep github.com/onsi/ginkgo/v2 | awk '{print $$2}')
214+
GORELEASER_VERSION ?= v2.4.8
205215
.PHONY: kustomize
206216
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
207217
$(KUSTOMIZE): $(LOCALBIN)
@@ -238,6 +248,11 @@ nilaway:
238248
ginkgo:
239249
$(call go-install-tool,$(GINKGO),github.com/onsi/ginkgo/v2/ginkgo,${GINKGO_VERSION})
240250

251+
.PHONY: goreleaser
252+
goreleaser: $(GORELEASER)
253+
$(GORELEASER): $(LOCALBIN)
254+
$(call go-install-tool,$(GORELEASER),github.com/goreleaser/goreleaser/v2,$(GORELEASER_VERSION))
255+
241256
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
242257
# $1 - target path with name of binary (ideally with version)
243258
# $2 - package url which can be installed

config/default/kustomization.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ patches:
3232
# endpoint w/o any authn/z, please comment the following line.
3333
- path: manager_auth_proxy_patch.yaml
3434

35+
images:
36+
- name: argoproj-labs/gitops-promoter
37+
newName: quay.io/argoprojlabs/gitops-promoter
38+
newTag: v0.0.0
39+
3540
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
3641
# crd/kustomization.yaml
3742
#- path: manager_webhook_patch.yaml

hack/manifests-release.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#! /usr/bin/env bash
2+
set -euox pipefail
3+
4+
SRCROOT="$( CDPATH='' cd -- "$(dirname "$0")/.." && pwd -P )"
5+
AUTOGENMSG="# This is an auto-generated file. DO NOT EDIT"
6+
7+
KUSTOMIZE="${1:-}"
8+
if [ -z "$KUSTOMIZE" ]; then
9+
echo "Path to kustomize not provided"
10+
exit 1
11+
fi
12+
13+
IMAGE_TAG="${2:-}"
14+
if [ -z "$IMAGE_TAG" ]; then
15+
echo "Image tag not provided"
16+
exit 1
17+
fi
18+
19+
IMAGE_NAMESPACE="${IMAGE_NAMESPACE:-quay.io/argoprojlabs/gitops-promoter}"
20+
IMAGE_FQN="$IMAGE_NAMESPACE:$IMAGE_TAG"
21+
22+
$KUSTOMIZE version
23+
cd "${SRCROOT}/config/default" && $KUSTOMIZE edit set image "argoproj-labs/gitops-promoter=${IMAGE_FQN}"
24+
echo "${AUTOGENMSG}" > "${SRCROOT}/install.yaml"
25+
$KUSTOMIZE build "${SRCROOT}/config/default" >> "${SRCROOT}/install.yaml"

dist/install.yaml renamed to install.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# This is an auto-generated file. DO NOT EDIT
12
apiVersion: v1
23
kind: Namespace
34
metadata:

release.Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM gcr.io/distroless/static:nonroot
2+
3+
WORKDIR /
4+
5+
# goreleaser runs docker build in a context that contains just the Dockerfile and the binary.
6+
7+
COPY gitops-promoter .
8+
USER 65532:65532
9+
ENTRYPOINT ["/gitops-promoter"]

0 commit comments

Comments
 (0)