Skip to content

Commit

Permalink
Integrate goreleaser into repo (#10459)
Browse files Browse the repository at this point in the history
Signed-off-by: timflannagan <[email protected]>
  • Loading branch information
timflannagan authored Jan 17, 2025
1 parent 2fc8b35 commit f96c684
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 31 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Release
on:
workflow_dispatch:
push:
tags:
- 'v*'
pull_request:
branches:
- main

env:
# IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
IMAGE_REGISTRY: quay.io/solo-io

permissions:
contents: 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/pull/* ]]; then
VERSION="pr-$(echo "${GITHUB_REF}" | sed -E 's|refs/pull/([^/]+)/?.*|\1|')"
else
VERSION="$(git describe --tags --always)"
fi
echo "VERSION=${VERSION}"
echo "GORELEASER_ARGS=${GORELEASER_ARGS}"
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 }}
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.GLOO_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.GLOO_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.GLOO_IMAGE_REPO }}:{{ .Env.VERSION }}"
image_templates:
- *amd_image
- *arm_image
changelog:
disable: false
release:
prerelease: "auto"
mode: "replace"
53 changes: 28 additions & 25 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,7 @@ 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 ?= quay.io/solo-io

# Kind of a hack to make sure _output exists
z := $(shell mkdir -p $(OUTPUT_DIR))
Expand All @@ -49,9 +47,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 +124,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 +175,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 All @@ -202,7 +198,7 @@ GINKGO_USER_FLAGS ?=

.PHONY: test
test: ## Run all tests, or only run the test package at {TEST_PKG} if it is specified
$(GINKGO_ENV) go run github.com/onsi/ginkgo/v2/ginkgo -ldflags=$(LDFLAGS) \
$(GINKGO_ENV) go run github.com/onsi/ginkgo/v2/ginkgo -ldflags='$(LDFLAGS)' \
$(GINKGO_FLAGS) $(GINKGO_REPORT_FLAGS) $(GINKGO_USER_FLAGS) \
$(TEST_PKG)

Expand Down Expand Up @@ -237,7 +233,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 All @@ -251,7 +247,7 @@ GO_TEST_USER_ARGS ?=
.PHONY: go-test
go-test: ## Run all tests, or only run the test package at {TEST_PKG} if it is specified
go-test: clean-bug-report clean-test-logs $(BUG_REPORT_DIR) $(TEST_LOG_DIR) # Ensure the bug_report dir is reset before each invocation
@$(GO_TEST_ENV) go test -ldflags=$(LDFLAGS) \
@$(GO_TEST_ENV) go test -ldflags='$(LDFLAGS)' \
$(GO_TEST_ARGS) $(GO_TEST_USER_ARGS) \
$(TEST_PKG) > $(TEST_LOG_DIR)/go-test 2>&1; \
RESULT=$$?; \
Expand Down Expand Up @@ -378,7 +374,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 @@ -428,7 +423,7 @@ DISCOVERY_SOURCES=$(call get_sources,$(DISCOVERY_DIR))
DISCOVERY_OUTPUT_DIR=$(OUTPUT_DIR)/$(DISCOVERY_DIR)

$(DISCOVERY_OUTPUT_DIR)/discovery-linux-$(GOARCH): $(DISCOVERY_SOURCES)
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ $(DISCOVERY_DIR)/cmd/main.go
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags='$(LDFLAGS)' -gcflags='$(GCFLAGS)' -o $@ $(DISCOVERY_DIR)/cmd/main.go

.PHONY: discovery
discovery: $(DISCOVERY_OUTPUT_DIR)/discovery-linux-$(GOARCH)
Expand All @@ -453,7 +448,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 All @@ -465,11 +459,12 @@ GLOO_SOURCES=$(call get_sources,$(GLOO_DIR))
EDGE_GATEWAY_SOURCES=$(call get_sources,$(EDGE_GATEWAY_DIR))
K8S_GATEWAY_SOURCES=$(call get_sources,$(K8S_GATEWAY_DIR))
GLOO_OUTPUT_DIR=$(OUTPUT_DIR)/$(GLOO_DIR)
export GLOO_IMAGE_REPO ?= gloo

# We include the files in EDGE_GATEWAY_DIR and K8S_GATEWAY_DIR as dependencies to the gloo build
# so changes in those directories cause the make target to rebuild
$(GLOO_OUTPUT_DIR)/gloo-linux-$(GOARCH): $(GLOO_SOURCES) $(EDGE_GATEWAY_SOURCES) $(K8S_GATEWAY_SOURCES)
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ $(GLOO_DIR)/cmd/main.go
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags='$(LDFLAGS)' -gcflags='$(GCFLAGS)' -o $@ $(GLOO_DIR)/cmd/main.go

.PHONY: gloo
gloo: $(GLOO_OUTPUT_DIR)/gloo-linux-$(GOARCH)
Expand All @@ -482,7 +477,7 @@ gloo-docker: $(GLOO_OUTPUT_DIR)/gloo-linux-$(GOARCH) $(GLOO_OUTPUT_DIR)/Dockerfi
docker buildx build --load $(PLATFORM) $(GLOO_OUTPUT_DIR) -f $(GLOO_OUTPUT_DIR)/Dockerfile.gloo \
--build-arg GOARCH=$(GOARCH) \
--build-arg ENVOY_IMAGE=$(ENVOY_GLOO_IMAGE) \
-t $(IMAGE_REGISTRY)/gloo:$(VERSION) $(QUAY_EXPIRATION_LABEL)
-t $(IMAGE_REGISTRY)/$(GLOO_IMAGE_REPO):$(VERSION) $(QUAY_EXPIRATION_LABEL)

$(GLOO_OUTPUT_DIR)/Dockerfile.gloo.distroless: $(GLOO_DIR)/cmd/Dockerfile.distroless
cp $< $@
Expand All @@ -494,7 +489,7 @@ gloo-distroless-docker: $(GLOO_OUTPUT_DIR)/gloo-linux-$(GOARCH) $(GLOO_OUTPUT_DI
--build-arg GOARCH=$(GOARCH) \
--build-arg ENVOY_IMAGE=$(ENVOY_GLOO_IMAGE) \
--build-arg BASE_IMAGE=$(GLOO_DISTROLESS_BASE_WITH_UTILS_IMAGE) \
-t $(IMAGE_REGISTRY)/gloo:$(VERSION)-distroless $(QUAY_EXPIRATION_LABEL)
-t $(IMAGE_REGISTRY)/$(GLOO_IMAGE_REPO):$(VERSION)-distroless $(QUAY_EXPIRATION_LABEL)

#----------------------------------------------------------------------------------
# Gloo with race detection enabled.
Expand Down Expand Up @@ -554,7 +549,7 @@ SDS_SOURCES=$(call get_sources,$(SDS_DIR))
SDS_OUTPUT_DIR=$(OUTPUT_DIR)/$(SDS_DIR)

$(SDS_OUTPUT_DIR)/sds-linux-$(GOARCH): $(SDS_SOURCES)
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ $(SDS_DIR)/cmd/main.go
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags='$(LDFLAGS)' -gcflags='$(GCFLAGS)' -o $@ $(SDS_DIR)/cmd/main.go

.PHONY: sds
sds: $(SDS_OUTPUT_DIR)/sds-linux-$(GOARCH)
Expand Down Expand Up @@ -588,7 +583,7 @@ ENVOYINIT_SOURCES=$(call get_sources,$(ENVOYINIT_DIR))
ENVOYINIT_OUTPUT_DIR=$(OUTPUT_DIR)/$(ENVOYINIT_DIR)

$(ENVOYINIT_OUTPUT_DIR)/envoyinit-linux-$(GOARCH): $(ENVOYINIT_SOURCES)
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ $(ENVOYINIT_DIR)/main.go
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags='$(LDFLAGS)' -gcflags='$(GCFLAGS)' -o $@ $(ENVOYINIT_DIR)/main.go

.PHONY: envoyinit
envoyinit: $(ENVOYINIT_OUTPUT_DIR)/envoyinit-linux-$(GOARCH)
Expand Down Expand Up @@ -627,7 +622,7 @@ CERTGEN_SOURCES=$(call get_sources,$(CERTGEN_DIR))
CERTGEN_OUTPUT_DIR=$(OUTPUT_DIR)/$(CERTGEN_DIR)

$(CERTGEN_OUTPUT_DIR)/certgen-linux-$(GOARCH): $(CERTGEN_SOURCES)
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ $(CERTGEN_DIR)/main.go
$(GO_BUILD_FLAGS) GOOS=linux go build -ldflags='$(LDFLAGS)' -gcflags='$(GCFLAGS)' -o $@ $(CERTGEN_DIR)/main.go

.PHONY: certgen
certgen: $(CERTGEN_OUTPUT_DIR)/certgen-linux-$(GOARCH)
Expand Down Expand Up @@ -736,6 +731,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 @@ -790,6 +787,12 @@ publish-helm-chart: generate-helm-files
done
endif # Publish Artifact Targets

GORELEASER_ARGS ?= --snapshot --clean
GORELEASER ?= go run github.com/goreleaser/goreleaser/[email protected]
.PHONY: release
release: ## Create a release using goreleaser
$(GORELEASER) release $(GORELEASER_ARGS)

#----------------------------------------------------------------------------------
# Docker
#----------------------------------------------------------------------------------
Expand Down Expand Up @@ -1058,12 +1061,12 @@ CONFORMANCE_ARGS := -gateway-class=gloo-gateway $(CONFORMANCE_SUPPORTED_FEATURES

.PHONY: conformance ## Run the conformance test suite
conformance: $(TEST_ASSET_DIR)/conformance/conformance_test.go
go test -mod=mod -ldflags=$(LDFLAGS) -tags conformance -test.v $(TEST_ASSET_DIR)/conformance/... -args $(CONFORMANCE_ARGS)
go test -mod=mod -ldflags='$(LDFLAGS)' -tags conformance -test.v $(TEST_ASSET_DIR)/conformance/... -args $(CONFORMANCE_ARGS)

# Run only the specified conformance test. The name must correspond to the ShortName of one of the k8s gateway api
# conformance tests.
conformance-%: $(TEST_ASSET_DIR)/conformance/conformance_test.go
go test -mod=mod -ldflags=$(LDFLAGS) -tags conformance -test.v $(TEST_ASSET_DIR)/conformance/... -args $(CONFORMANCE_ARGS) \
go test -mod=mod -ldflags='$(LDFLAGS)' -tags conformance -test.v $(TEST_ASSET_DIR)/conformance/... -args $(CONFORMANCE_ARGS) \
-run-test=$*

#----------------------------------------------------------------------------------
Expand Down
12 changes: 6 additions & 6 deletions Makefile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
CLI_DIR=projects/gloo/cli

$(OUTPUT_DIR)/glooctl: $(SOURCES)
GO111MODULE=on go build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ $(CLI_DIR)/cmd/main.go $(STDERR_SILENCE_REDIRECT)
GO111MODULE=on go build -ldflags='$(LDFLAGS)' -gcflags='$(GCFLAGS)' -o $@ $(CLI_DIR)/cmd/main.go $(STDERR_SILENCE_REDIRECT)

$(OUTPUT_DIR)/glooctl-linux-amd64: $(SOURCES)
$(GO_BUILD_FLAGS) GOOS=linux GOARCH=amd64 go build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ $(CLI_DIR)/cmd/main.go $(STDERR_SILENCE_REDIRECT)
$(GO_BUILD_FLAGS) GOOS=linux GOARCH=amd64 go build -ldflags='$(LDFLAGS)' -gcflags='$(GCFLAGS)' -o $@ $(CLI_DIR)/cmd/main.go $(STDERR_SILENCE_REDIRECT)
$(OUTPUT_DIR)/glooctl-linux-arm64: $(SOURCES)
$(GO_BUILD_FLAGS) GOOS=linux GOARCH=arm64 go build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ $(CLI_DIR)/cmd/main.go $(STDERR_SILENCE_REDIRECT)
$(GO_BUILD_FLAGS) GOOS=linux GOARCH=arm64 go build -ldflags='$(LDFLAGS)' -gcflags='$(GCFLAGS)' -o $@ $(CLI_DIR)/cmd/main.go $(STDERR_SILENCE_REDIRECT)
$(OUTPUT_DIR)/glooctl-darwin-amd64: $(SOURCES)
$(GO_BUILD_FLAGS) GOOS=darwin GOARCH=amd64 go build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ $(CLI_DIR)/cmd/main.go $(STDERR_SILENCE_REDIRECT)
$(GO_BUILD_FLAGS) GOOS=darwin GOARCH=amd64 go build -ldflags='$(LDFLAGS)' -gcflags='$(GCFLAGS)' -o $@ $(CLI_DIR)/cmd/main.go $(STDERR_SILENCE_REDIRECT)
$(OUTPUT_DIR)/glooctl-darwin-arm64: $(SOURCES)
$(GO_BUILD_FLAGS) GOOS=darwin GOARCH=arm64 go build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ $(CLI_DIR)/cmd/main.go $(STDERR_SILENCE_REDIRECT)
$(GO_BUILD_FLAGS) GOOS=darwin GOARCH=arm64 go build -ldflags='$(LDFLAGS)' -gcflags='$(GCFLAGS)' -o $@ $(CLI_DIR)/cmd/main.go $(STDERR_SILENCE_REDIRECT)

$(OUTPUT_DIR)/glooctl-windows-$(GOARCH).exe: $(SOURCES)
$(GO_BUILD_FLAGS) GOOS=windows GOARCH=$(GOARCH) go build -ldflags=$(LDFLAGS) -gcflags=$(GCFLAGS) -o $@ $(CLI_DIR)/cmd/main.go $(STDERR_SILENCE_REDIRECT)
$(GO_BUILD_FLAGS) GOOS=windows GOARCH=$(GOARCH) go build -ldflags='$(LDFLAGS)' -gcflags='$(GCFLAGS)' -o $@ $(CLI_DIR)/cmd/main.go $(STDERR_SILENCE_REDIRECT)


.PHONY: glooctl
Expand Down

0 comments on commit f96c684

Please sign in to comment.