Skip to content

Commit

Permalink
feat: Integrate Goreleaser (#85)
Browse files Browse the repository at this point in the history
* goreleaser: init

* goreleaser: add support for windows and darwin targets

* build: use goreleaser for builds in make and Dockerfile

* build: revert to using go build for local builds

* ci: add release workflow

* build: optimise builds for production

* ci: combine release into a single step
  • Loading branch information
turtleDev authored Jul 6, 2024
1 parent a9f57c7 commit 50e7b09
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 17 deletions.
20 changes: 9 additions & 11 deletions .github/workflows/package.yaml → .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- "v*.*.*"

jobs:
docker:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -24,13 +24,11 @@ jobs:
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and Push
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: |
docker.pkg.github.com/${{ github.repository }}/raccoon:latest
docker.pkg.github.com/${{ github.repository }}/raccoon:${{ steps.get_version.outputs.version-without-v }}
raystack/raccoon:latest
raystack/raccoon:${{ steps.get_version.outputs.version-without-v }}
- name: setup docker
uses: docker-practice/actions-setup-docker@master
- name: release the project
env:
GITHUB_TOKEN: ${{ secrets.GO_RELEASER_TOKEN }}
run: |
BUILD_CMD='git config --global --add safe.directory /build/src && cd /build/src && goreleaser release --clean'
echo $BUILD_CMD | docker run -e GITHUB_TOKEN="${GITHUB_TOKEN}" -i --entrypoint /bin/bash -v "$PWD/:/build/src" goreleaser/goreleaser-cross:v1.22.4
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ raccoon
.temp
node_modules
__debug.*

dist/
107 changes: 107 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

version: 2

project_name: raccoon

release:
prerelease: auto

before:
hooks:
- go mod tidy

changelog:
use: github
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
- "^build:"


builds:
- id: "raccoon"
main: ./
flags: [-trimpath]
ldflags:
- -s -w
- -X github.com/raystack/raccoon/config.Version={{.Tag}}
- -X github.com/raystack/raccoon/config.BuildCommit={{.FullCommit}}
- -X github.com/raystack/raccoon/config.BuildDate={{.Date}}
goos:
- darwin
- linux
- windows
goarch:
- amd64
- arm64
ignore:
# confluent-kafka-go doesn't support arm64 on windows
# https://github.com/confluentinc/confluent-kafka-go/blob/master/kafka/librdkafka_vendor/README.md
- goos: windows
goarch: arm64
env:
- CGO_ENABLED=1
- >-
{{- if eq .Os "darwin" }}
{{- if eq .Arch "amd64" }}CC=x86_64-apple-darwin21.1-clang{{- end }}
{{- if eq .Arch "arm64" }}CC=aarch64-apple-darwin21.1-clang{{- end }}
{{- end }}
{{- if eq .Os "linux" }}
{{- if eq .Arch "amd64" }}CC=x86_64-linux-gnu-gcc{{- end}}
{{- if eq .Arch "arm64" }}CC=aarch64-linux-gnu-gcc{{- end }}
{{- end}}
{{- if eq .Os "windows" }}
{{- if eq .Arch "amd64" }}CC=x86_64-w64-mingw32-gcc{{- end }}
{{- end}}
archives:
- id: "archives"
format_overrides:
- goos: windows
format: zip

dockers:
- id: dockerhub
image_templates:
- "docker.io/raystack/{{.ProjectName}}:latest"
- "docker.io/raystack/{{.ProjectName}}:{{ .Version }}"
- "docker.io/raystack/{{.ProjectName}}:{{ .Tag }}-amd64"

nfpms:
- maintainer: Raystack
description: Scalable event ingestion tool.
homepage: https://github.com/raystack/raccoon
license: Apache 2.0
formats:
- deb
- rpm
- apk

scoops:
- homepage: "https://github.com/raystack/raccoon"
description: "Scalable event ingestion tool"
license: Apache 2.0
repository:
owner: raystack
name: scoop-bucket

brews:
- name: raccoon
homepage: "https://github.com/raystack/raccoon"
description: "Scalable event ingestion tool"
repository:
owner: raystack
name: homebrew-tap
license: "Apache 2.0"
directory: Formula
dependencies:
- name: git
install: |-
bin.install "raccoon"
commit_author:
name: Ravi Suhag
email: [email protected]
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN PROTOC_ZIP=protoc-3.17.3-linux-x86_64.zip && \
unzip -o $PROTOC_ZIP -d /usr/local 'include/*' && \
rm -f $PROTOC_ZIP
COPY . .
RUN make build
RUN make build


FROM debian:bookworm-slim
Expand Down
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
NAME="github.com/raystack/raccoon"
COMMIT := $(shell git rev-parse --short HEAD)
TAG := "$(shell git rev-list --tags --max-count=1)"
VERSION := "$(shell git describe --tags ${TAG})-next"
VERSION := "$(shell git describe --tags ${TAG})"
BUILD_DIR=dist
PROTON_COMMIT := "ccbf219312db35a934361ebad895cb40145ca235"
BUILD_FLAGS=-trimpath
LD_FLAGS=-ldflags "-s -w -X ${NAME}/config.Version=${VERSION}"

.PHONY: all build clean test tidy vet proto setup format generate

Expand Down Expand Up @@ -32,18 +34,21 @@ setup: ## Install required dependencies
@echo "> Installing dependencies..."
go mod tidy
go install github.com/bufbuild/buf/cmd/[email protected]
go install github.com/goreleaser/goreleaser/v2@latest
go install github.com/golangci/golangci-lint/cmd/[email protected]

config: ## Generate the sample config file
@echo "Initializing sample server config..."
@cp .env.sample .env

build: ## Build the raccoon binary
@echo "Building racccoon version ${VERSION}..."
go build
@echo "Building raccoon version ${VERSION}..."
go build ${BUILD_FLAGS} ${LD_FLAGS} ${NAME}
@echo "Build complete"

install:
@echo "Installing Guardian to ${GOBIN}..."
@echo "Installing Raccoon to ${GOBIN}..."
go install ${BUILD_FLAGS} ${LD_FLAGS} ${NAME}
@go install

test: ## Run the tests
Expand Down
2 changes: 2 additions & 0 deletions app/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app
import (
"context"

"github.com/raystack/raccoon/config"
"github.com/raystack/raccoon/logger"
)

Expand All @@ -14,6 +15,7 @@ func Run() error {
//@TODO - init config

//start server
logger.Infof("Raccoon %s", config.Version)
StartServer(ctx, cancel)
logger.Info("App.Run --> Complete")
<-ctx.Done()
Expand Down
3 changes: 3 additions & 0 deletions config/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package config

var Version, BuildCommit, BuildDate string
1 change: 0 additions & 1 deletion version.txt

This file was deleted.

0 comments on commit 50e7b09

Please sign in to comment.