Skip to content

Commit

Permalink
Merge pull request #100 from tcolgate/goreleaser
Browse files Browse the repository at this point in the history
Switch release to goreleaser
  • Loading branch information
sysboy authored Jan 25, 2024
2 parents a692f41 + 2b976bf commit 48fc00a
Show file tree
Hide file tree
Showing 6 changed files with 1,585 additions and 195 deletions.
107 changes: 107 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
snapshot:
name_template: '{{ incminor .Version }}-prerelease'

builds:
- main: .
binary: exporter_exporter
id: "exporter_exporter"
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- windows
goarch:
- amd64
- arm64
goarm:
- "6"
- "7"
mod_timestamp: '{{ .CommitTimestamp }}'
flags:
- -trimpath
ldflags:
- -s -w -X main.Version={{.Version}} -X main.Revision={{.FullCommit}} -X main.BuildDate={{.Date}} -X main.Branch={{.Branch}} -X main.BuildUser={{.Env.USER}}

archives:
- id: exporter_exporter
builds:
- exporter_exporter
name_template: 'exporter_exporter_{{ .Version }}_{{ title .Os }}_{{ if eq .Arch "amd64" }}x86_64{{ else }}{{ .Arch }}{{ end }}{{ if .Arm }}v{{ .Arm }}{{ end }}'

checksum:
name_template: 'checksums.txt'
release:
header: |-
exporter_exporter {{ .Version }}
---------------------
kos:
- repository: "docker.io/qubitproducts/exporter_exporter"
tags:
- '{{.Version}}'
- latest
bare: true
platforms:
- linux/amd64
- linux/arm64

nfpms:
- package_name: expexp
bindir: /usr/local/bin
file_name_template: "{{ .ConventionalFileName }}"
vendor: QubitProducts
homepage: https://github.com/QubitProducts/exporter_exporter
maintainer: [email protected]

# Your app's description.
description: |-
Exporter that proxies other prometheus exporters
license: Apache 2.0

formats:
- deb

contents:
- src: exporter_exporter.conf
dst: /etc/init/exporter_exporter
packager: deb
file_info:
mode: 0644
- src: exporter_exporter.defaults
dst: /etc/default/exporter_exporter
packager: deb
type: "config"
file_info:
mode: 0644
- src: expexp.yaml
dst: /etc/exporter_exporter.yaml
packager: deb
type: "config"
file_info:
mode: 0644

changelog:
sort: asc
groups:
- title: Features
regexp: 'feat(?:\(.+?\))?!?:'
order: 5
- title: Enhancements
regexp: 'enhancement(?:\(.+?\))?!?:'
order: 10
- title: Bug fixes
regexp: 'fix(?:\(.+?\))?!?:'
order: 15
- title: Documentation
regexp: 'docs(?:\(.+?\))?!?:'
order: 20
- title: Chores
regexp: 'chore(?:\(.+?\))?!?:'
order: 25
- title: Others
order: 100


148 changes: 6 additions & 142 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,35 +1,10 @@
GITHUB_ORG = QubitProducts
GITHUB_REPO = exporter_exporter
VERSION = 0.5.0

DOCKER_REGISTRY = qubitproducts
DOCKER_NAME = exporter_exporter
DOCKER_IMAGE = $(DOCKER_REGISTRY)/$(DOCKER_NAME):$(VERSION)
DOCKER_IMAGE_LATEST = $(DOCKER_REGISTRY)/$(DOCKER_NAME):latest

SHELL := /usr/bin/env bash
GO := go
FIRST_GOPATH := $(firstword $(subst :, ,$(GOPATH)))
FILES = $(shell find . -name '*.go' | grep -v vendor)
PREFIX ?= $(shell pwd)
BIN_DIR ?= $(shell pwd)

PACKAGE_TARGET = deb
PACKAGE_NAME = expexp
PACKAGE_VERSION = $(VERSION)
PACKAGE_REVISION = 3
PACKAGE_ARCH = amd64
PACKAGE_MAINTAINER = [email protected]
PACKAGE_FILE = $(PACKAGE_NAME)_$(PACKAGE_VERSION)-$(PACKAGE_REVISION)_$(PACKAGE_ARCH).$(PACKAGE_TARGET)
BINNAME = exporter_exporter

PWD := $(shell pwd)
all: build

all: package
clean:
rm -f $(PACKAGE_FILE)
rm -rf dist
rm -rf build

.PHONY: test
test:
Expand All @@ -52,126 +27,15 @@ vet:
echo ">> vetting code"
$(GO) vet $(pkgs)

.PHONY: prepare-package clean-package package
prepare-package: clean-package build/$(BINNAME)-$(VERSION).linux-amd64/$(BINNAME)
mkdir -p dist/usr/local/bin
mkdir -p dist/etc/init
mkdir -p dist/etc/default
mkdir -p dist/etc/exporter_exporter.d/
install -m755 build/$(BINNAME)-$(VERSION).linux-amd64/$(BINNAME) dist/usr/local/bin/$(BINNAME)
install -m644 $(BINNAME).conf dist/etc/init/$(BINNAME).conf
install -m644 $(BINNAME).defaults dist/etc/default/$(BINNAME)
install -m644 expexp.yaml dist/etc/exporter_exporter.yaml
touch dist/etc/exporter_exporter.d/.dir

clean-package:
rm -rf dist

.PHONY: AUTHORS
AUTHORS:
# There's only so much credit I need.
git log --format='%aN <%aE>' | grep -v Tristan\ Colgate\ | sort -u > AUTHORS

$(PACKAGE_FILE): prepare-package
cd dist && \
fpm \
-f \
-t $(PACKAGE_TARGET) \
-m $(PACKAGE_MAINTAINER) \
-n $(PACKAGE_NAME) \
-a $(PACKAGE_ARCH) \
-v $(PACKAGE_VERSION) \
--iteration $(PACKAGE_REVISION) \
--config-files /etc/$(BINNAME).yaml \
--config-files /etc/init/$(BINNAME).conf \
--config-files /etc/default/$(BINNAME) \
-s dir \
-p ../$(PACKAGE_FILE) \
.

.PHONY: build-docker release-docker
build-docker:
docker build -t $(DOCKER_IMAGE) .

release-docker: build-docker
docker push $(DOCKER_IMAGE)
docker tag $(DOCKER_IMAGE) $(DOCKER_IMAGE_LATEST)
docker push $(DOCKER_IMAGE_LATEST)

LDFLAGS = -X main.Version=$(VERSION) \
-X main.Branch=$(BRANCH) \
-X main.Revision=$(REVISION) \
-X main.BuildUser=$(BUILDUSER) \
-X main.BuildDate=$(BUILDDATE)

build/$(BINNAME)-$(VERSION).windows-amd64/$(BINNAME).exe: $(SRCS)
@GOOS=windows GOARCH=amd64 $(GO) build \
-ldflags "$(LDFLAGS)" \
-o $@ \
.

build/$(BINNAME)-$(VERSION).windows-amd64.zip: build/exporter_exporter-$(VERSION).windows-amd64/$(BINNAME).exe
zip -j $@ $<

build/$(BINNAME)-$(VERSION).%-arm64/$(BINNAME): $(SRCS)
GOOS=$* GOARCH=arm64 $(GO) build \
-ldflags "$(LDFLAGS)" \
-o $@ \
.

build/$(BINNAME)-$(VERSION).%-amd64/$(BINNAME): $(SRCS)
GOOS=$* GOARCH=amd64 $(GO) build \
-ldflags "$(LDFLAGS)" \
-o $@ \
.

build/$(BINNAME)-$(VERSION).%-arm64.tar.gz: build/$(BINNAME)-$(VERSION).%-arm64/$(BINNAME)
cd build && \
tar cfzv $(BINNAME)-$(VERSION).$*-arm64.tar.gz $(BINNAME)-$(VERSION).$*-arm64

build/$(BINNAME)-$(VERSION).%-amd64.tar.gz: build/$(BINNAME)-$(VERSION).%-amd64/$(BINNAME)
cd build && \
tar cfzv $(BINNAME)-$(VERSION).$*-amd64.tar.gz $(BINNAME)-$(VERSION).$*-amd64

package: $(PACKAGE_FILE)

package-release: $(PACKAGE_FILE)
go run github.com/aktau/github-release upload \
-u $(GITHUB_ORG) \
-r $(GITHUB_REPO) \
--tag v$(VERSION) \
--name $(PACKAGE_FILE) \
--file $(PACKAGE_FILE)

release-windows: build/exporter_exporter-$(VERSION).windows-amd64.zip
go run github.com/aktau/github-release upload \
-u $(GITHUB_ORG) \
-r $(GITHUB_REPO) \
--tag v$(VERSION) \
--name exporter_exporter-$(VERSION).windows-amd64.zip \
-f ./build/exporter_exporter-$(VERSION).windows-amd64.zip

.PRECIOUS: \
build/exporter_exporter-$(VERSION).darwin-amd64.tar.gz \
build/exporter_exporter-$(VERSION).linux-arm64.tar.gz \
build/exporter_exporter-$(VERSION).linux-amd64.tar.gz \
build/exporter_exporter-$(VERSION).windows-amd64.zip


release-%: build/exporter_exporter-$(VERSION).%.tar.gz
go run github.com/aktau/github-release upload \
-u $(GITHUB_ORG) \
-r $(GITHUB_REPO) \
--tag v$(VERSION) \
--name exporter_exporter-$(VERSION).$*.tar.gz \
-f ./build/exporter_exporter-$(VERSION).$*.tar.gz
.PHONY: build
build: vet format test
go run github.com/goreleaser/goreleaser@latest release --snapshot --skip=publish --clean

.PHONY: release
release:
git tag v$(VERSION)
git push origin v$(VERSION)
go run github.com/aktau/github-release release \
-u $(GITHUB_ORG) \
-r $(GITHUB_REPO) \
--tag v$(VERSION) \
--name v$(VERSION)
make release-darwin-amd64 release-linux-amd64 release-linux-arm64 release-windows package-release release-docker
go run github.com/goreleaser/goreleaser@latest release
Loading

0 comments on commit 48fc00a

Please sign in to comment.