Skip to content

Commit

Permalink
Adds goreleaser support to deterministically build and release binari…
Browse files Browse the repository at this point in the history
…es (#3)

* Adds goreleaser support to deterministically build and release binaries

* Removes unused SNAPSHOT var

* Removes mac SSH_AUTH_SOCK overrides

* Adds comment to script
  • Loading branch information
bg451 authored Jan 19, 2024
1 parent bccf1ec commit b886a3c
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
project_name: chronosphere
before:
hooks:
- go mod tidy
builds:
- id: chronoctl
main: ./src/cmd/chronoctl/main.go
binary: chronoctl
env:
- CGO_ENABLED=0
ldflags: "{{ .Env.GO_BUILD_LDFLAGS }}"
goos:
- linux
- darwin
- windows
goarch:
- amd64
- arm64
archives:
- name_template: >-
{{ .Binary }}-{{ .Os }}{{- if eq .Os "darwin" }}-unsigned{{- end }}-{{ .Arch }}
format: binary
files:
- none*
blobs:
- provider: gs
bucket: chronosphere-release
folder: "{{.Version}}"
checksum:
name_template: "{{ .ProjectName}}-checksums.txt"
release:
disable: true
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ GO_BUILD_LDFLAGS_CMD := $(abspath ./build/go-build-ldflags.sh)
GO_BUILD_LDFLAGS := $(shell $(GO_BUILD_LDFLAGS_CMD))
GO_BUILD_COMMON_ENV := CGO_ENABLED=0

GO_RELEASER_WORKING_DIR := /go/src/github.com/chronosphere/chronoctl
GO_RELEASER_RELEASE_ARGS ?= --rm-dist

UNSTABLE_ENTITIES := link-templates,saved-trace-searches,dashboards,trace-tail-sampling-rules,services

.PHONY: clean-build
Expand Down Expand Up @@ -84,3 +87,19 @@ go-version-check:
# make sure you're running the right version of Go, otherwise builds/codegen/tests
# may have inconsistent results that are hard to debug.
go version | grep go1.21 || (echo "Error: you must be running go1.21.x" && exit 1)

.PHONY: release
release:
@echo "Releasing new version"
GO_BUILD_LDFLAGS="$(GO_BUILD_LDFLAGS)" \
GO_RELEASER_DOCKER_IMAGE=$(GO_RELEASER_DOCKER_IMAGE) \
GO_RELEASER_RELEASE_ARGS="$(GO_RELEASER_RELEASE_ARGS)" \
GO_RELEASER_WORKING_DIR=$(GO_RELEASER_WORKING_DIR) \
SSH_AUTH_SOCK=$(SSH_AUTH_SOCK) \
./scripts/run_goreleaser.sh ${GO_RELEASER_RELEASE_ARGS}

.PHONY: release-snapshot
release-snapshot:
@echo Building binaries with goreleaser
# --snapshot mode allows building artifacts w/o release tag present and w/ publishing mode disabled useful when we want to test whether we can build binaries, but not publish yet.
make release GO_RELEASER_RELEASE_ARGS="--snapshot --rm-dist --skip-publish"
43 changes: 43 additions & 0 deletions scripts/run_goreleaser.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

set -euo pipefail
set -x
[[ -z ${DEBUG:-} ]] || set -o xtrace

# get the absolute path of the chronoctl-core directory no matter where the
# script is called from.
DIR="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && cd .. && pwd -P)"

GITCONFIG_VOLUME=${GIT_CONFIG:-"${HOME}/.gitconfig"}
GCLOUD_CONFIG_DIR="${CLOUDSDK_CONFIG:-${HOME}/.config/gcloud}"
SSH_CONFIG_DIR_VOLUME="${HOME}/.ssh"
SSH_AUTH_SOCK_ENV_VAR="/ssh-agent"
SSH_AUTH_SOCK_VOLUME="${SSH_AUTH_SOCK}:/ssh-agent"

if [[ "${BUILDKITE:-}" == "true" ]]; then
GITCONFIG_VOLUME="/var/lib/buildkite-agent/.gitconfig"
SSH_CONFIG_DIR_VOLUME="/var/lib/buildkite-agent/.ssh"
fi


DOCKER_OPTS=(
-w "${GO_RELEASER_WORKING_DIR}"
-e "GITHUB_TOKEN" # Set by CI
-e "GO_BUILD_LDFLAGS"
-e "CGO_ENABLED=0"
-e "SSH_AUTH_SOCK=${SSH_AUTH_SOCK_ENV_VAR}"
-v "${SSH_AUTH_SOCK_VOLUME}"
-v "${SSH_CONFIG_DIR_VOLUME}:/root/.ssh"
-v "${GITCONFIG_VOLUME}:/root/.gitconfig"
-v "${DIR}:${GO_RELEASER_WORKING_DIR}"
)

if [[ "${BUILDKITE:-}" != "true" ]]; then
DOCKER_OPTS+=(-v "${GCLOUD_CONFIG_DIR}:/root/.config/gcloud")
fi

# Run go mod vendor outside of container to utilize local cache
go mod vendor

# N.B. The GO_RELEASER_DOCKER_IMAGE is expected to be set by CI.
docker run "${DOCKER_OPTS[@]}" "${GO_RELEASER_DOCKER_IMAGE}" release "$@"

0 comments on commit b886a3c

Please sign in to comment.