Skip to content

Commit

Permalink
Integrate goreleaser into repo
Browse files Browse the repository at this point in the history
Signed-off-by: timflannagan <timflannagan@gmail.com>
  • Loading branch information
timflannagan committed Jan 15, 2025
1 parent 1b8cf1d commit 7b07d89
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 14 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Release
on:
workflow_dispatch:
push:
tags:
- 'v*'
pull_request:
branches:
- main

env:
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}

permissions:
contents: write
id-token: write
packages: write

jobs:
goreleaser:
name: goreleaser
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
cache: true

- name: Log into ghcr.io
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v3
with:
registry: ${{ env.IMAGE_REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set the release related variables
id: set_vars
run: |
# we want to conditionally run the full release pipeline based on the
# event that triggered the workflow. for PRs, we only want to build
# the binaries & container images, but not create a release.
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION="${GITHUB_REF#refs/tags/}"
echo "GORELEASER_ARGS=--clean" >> $GITHUB_ENV
elif [[ $GITHUB_REF == refs/heads/main ]]; then
VERSION="$(echo "${GITHUB_REF#refs/heads/}" | sed -r 's|/+|-|g')"
echo "GORELEASER_ARGS=--clean --skip=validate" >> $GITHUB_ENV
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION="pr-$(echo "${GITHUB_REF}" | sed -E 's|refs/pull/([^/]+)/?.*|\1|')"
else
VERSION="$(git describe --tags --always)"
fi
echo "VERSION=${VERSION}" >> $GITHUB_ENV
- name: Run goreleaser
run: make release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ env.VERSION }}
IMAGE_REGISTRY: ${{ env.IMAGE_REGISTRY }}
GORELEASER_ARGS: ${{ env.GORELEASER_ARGS }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ istio-*/*

# Bin directory created by e2e test
.bin/
# Added by goreleaser init:
dist/
55 changes: 55 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
version: 2
before:
hooks:
- go mod tidy
- go mod download
builds:
- id: controller
main: ./projects/gloo/cmd/
binary: gloo-linux-{{ .Arch }}
gcflags: "{{ .Env.GCFLAGS }}"
ldflags: "{{ .Env.LDFLAGS }}"
env:
- CGO_ENABLED=0
- GO111MODULE=on
- GOARCH={{ .Arch }}
- GOOS={{ .Os }}
mod_timestamp: "{{ .CommitTimestamp }}"
goos:
- linux
goarch:
- amd64
- arm64
dockers:
- image_templates:
- &arm_image "{{ .Env.IMAGE_REGISTRY }}/{{ .Env.IMAGE_REPO }}:{{ .Env.VERSION }}-arm64"
use: buildx
dockerfile: &dockerfile projects/gloo/cmd/Dockerfile
goos: linux
goarch: arm64
build_flag_templates:
- "--pull"
- "--platform=linux/arm64"
- "--build-arg=GOARCH=arm64"
- "--build-arg=ENVOY_IMAGE={{ .Env.ENVOY_GLOO_IMAGE }}"
- image_templates:
- &amd_image "{{ .Env.IMAGE_REGISTRY }}/{{ .Env.IMAGE_REPO }}:{{ .Env.VERSION }}-amd64"
use: buildx
dockerfile: *dockerfile
goos: linux
goarch: amd64
build_flag_templates:
- "--pull"
- "--platform=linux/amd64"
- "--build-arg=GOARCH=amd64"
- "--build-arg=ENVOY_IMAGE={{ .Env.ENVOY_GLOO_IMAGE }}"
docker_manifests:
- name_template: "{{ .Env.IMAGE_REGISTRY }}/{{ .Env.IMAGE_REPO }}:{{ .Env.VERSION }}"
image_templates:
- *amd_image
- *arm_image
changelog:
disable: false
release:
prerelease: "auto"
mode: "replace"
31 changes: 17 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# https://www.gnu.org/software/make/manual/html_node/Special-Variables.html#Special-Variables
.DEFAULT_GOAL := help


#----------------------------------------------------------------------------------
# Help
#----------------------------------------------------------------------------------
Expand All @@ -21,7 +20,6 @@ help: LINE_COLUMN_WIDTH=5
help: ## Output the self-documenting make targets
@grep -hnE '^[%a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = "[:]|(## )"}; {printf "\033[36mL%-$(LINE_COLUMN_WIDTH)s%-$(NAME_COLUMN_WIDTH)s\033[0m %s\n", $$1, $$2, $$4}'


#----------------------------------------------------------------------------------
# Base
#----------------------------------------------------------------------------------
Expand All @@ -33,7 +31,8 @@ OUTPUT_DIR ?= $(ROOTDIR)/_output
# To use quay images, set the IMAGE_REGISTRY to "quay.io/solo-io" (or leave unset)
# To use dockerhub images, set the IMAGE_REGISTRY to "soloio"
# To use gcr images, set the IMAGE_REGISTRY to "gcr.io/$PROJECT_NAME"
IMAGE_REGISTRY ?= quay.io/solo-io
export IMAGE_REGISTRY ?= ghcr.io/kgateway
export IMAGE_REPO ?= kgateway

# Kind of a hack to make sure _output exists
z := $(shell mkdir -p $(OUTPUT_DIR))
Expand All @@ -49,9 +48,9 @@ SOURCES := $(shell find . -name "*.go" | grep -v test.go)
# for more information, see https://github.com/solo-io/gloo/pull/9633
# and
# https://soloio.slab.com/posts/extended-http-methods-design-doc-40j7pjeu
ENVOY_GLOO_IMAGE ?= quay.io/solo-io/envoy-gloo:1.31.2-patch3
LDFLAGS := "-X github.com/solo-io/gloo/pkg/version.Version=$(VERSION)"
GCFLAGS ?=
export ENVOY_GLOO_IMAGE ?= quay.io/solo-io/envoy-gloo:1.31.2-patch3
export LDFLAGS := -X github.com/solo-io/gloo/pkg/version.Version=$(VERSION)
export GCFLAGS ?=

UNAME_M := $(shell uname -m)
# if `GO_ARCH` is set, then it will keep its value. Else, it will be changed based off the machine's host architecture.
Expand Down Expand Up @@ -126,7 +125,6 @@ ALPINE_BASE_IMAGE ?= alpine:3.17.6
# in the tree rooted at that directory that match the given criteria.
get_sources = $(shell find $(1) -name "*.go" | grep -v test | grep -v generated.go | grep -v mock_)


#----------------------------------------------------------------------------------
# Imports
#----------------------------------------------------------------------------------
Expand Down Expand Up @@ -178,12 +176,11 @@ check-spelling:
LINTER_VERSION := $(shell cat .github/workflows/static-analysis.yaml | yq '.jobs.static-analysis.steps.[] | select( .uses == "*golangci/golangci-lint-action*") | .with.version ')

# The analyze target runs a suite of static analysis tools against the codebase.
# The options are defined in .golangci.yaml, and can be overridden by setting the ANALYZE_OPTIONS variable.
# The options are defined in .golangci.yaml, and can be overridden by setting the ANALYZE_ARGS variable.
.PHONY: analyze
ANALYZE_OPTIONS ?= --fast --verbose
ANALYZE_ARGS ?= --fast --verbose
analyze:
go run github.com/golangci/golangci-lint/cmd/golangci-lint@$(LINTER_VERSION) run $(ANALYZE_OPTIONS) ./...

go run github.com/golangci/golangci-lint/cmd/golangci-lint@$(LINTER_VERSION) run $(ANALYZE_ARGS) ./...

#----------------------------------------------------------------------------------
# Ginkgo Tests
Expand Down Expand Up @@ -237,7 +234,7 @@ run-kube-e2e-tests: test
#----------------------------------------------------------------------------------
# Go Tests
#----------------------------------------------------------------------------------
GO_TEST_ENV ?=
GO_TEST_ENV ?=
# Testings flags: https://pkg.go.dev/cmd/go#hdr-Testing_flags
# The default timeout for a suite is 10 minutes, but this can be overridden by setting the -timeout flag. Currently set
# to 25 minutes based on the time it takes to run the longest test setup (k8s_gw_test).
Expand Down Expand Up @@ -378,7 +375,6 @@ generated-code-cleanup: getter-check mod-tidy update-licenses fmt ## Executes th
generate-changelog: ## Generate a changelog entry
@./devel/tools/changelog.sh


#----------------------------------------------------------------------------------
# Generate CRD Reference Documentation
#
Expand Down Expand Up @@ -521,7 +517,6 @@ discovery-distroless-docker: $(DISCOVERY_OUTPUT_DIR)/discovery-linux-$(GOARCH) $
--build-arg BASE_IMAGE=$(GLOO_DISTROLESS_BASE_IMAGE) \
-t $(IMAGE_REGISTRY)/discovery:$(VERSION)-distroless $(QUAY_EXPIRATION_LABEL)


#----------------------------------------------------------------------------------
# Gloo
#----------------------------------------------------------------------------------
Expand Down Expand Up @@ -804,6 +799,8 @@ VERSION := $(shell echo $(TAGGED_VERSION) | cut -c 2-)
LDFLAGS := "-X github.com/solo-io/gloo/pkg/version.Version=$(VERSION)"
endif

export VERSION

# controller variable for the "Publish Artifacts" section. Defines which targets exist. Possible Values: NONE, RELEASE, PULL_REQUEST
PUBLISH_CONTEXT ?= NONE
# specify which bucket to upload helm chart to
Expand Down Expand Up @@ -858,6 +855,12 @@ publish-helm-chart: generate-helm-files
done
endif # Publish Artifact Targets

GORELEASER_ARGS ?= --snapshot --clean
GORELEASER ?= go run github.com/goreleaser/goreleaser/v2@v2.5.1
.PHONY: release
release: ## Create a release using goreleaser
$(GORELEASER) release $(GORELEASER_ARGS)

#----------------------------------------------------------------------------------
# Docker
#----------------------------------------------------------------------------------
Expand Down

0 comments on commit 7b07d89

Please sign in to comment.