diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..d14f118 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,38 @@ +--- +kind: pipeline +type: docker +name: Build and publish + +platform: + os: linux + arch: amd64 + +steps: +- name: Build + image: golang + commands: + - make build + +- name: Create release files + image: golang + commands: + - make release + when: + event: tag + +- name: Upload release files + image: plugins/github-release + settings: + api_key: + from_secret: GHCR_UPLOAD_TOKEN + files: release/* + checksum: + - sha512 + draft: true + when: + event: tag +--- +kind: signature +hmac: e35934cf1ba5c663aec6e5cd3204912446cc3b98c7a05d85fbf20d0429577df2 + +... diff --git a/Makefile b/Makefile index 221ef79..956b9e7 100644 --- a/Makefile +++ b/Makefile @@ -2,19 +2,62 @@ PROJECT_NAME=$(shell basename $(CURDIR)) +APPLICATION_NAME := traefik-etcd-advertiser +VERSION := $(shell git describe --tags HEAD 2>/dev/null || echo $(DRONE_TAG)) +# PLATFORMS := darwin/amd64 darwin/arm64 linux/amd64 linux/arm linux/arm64 windows/amd64 +PLATFORMS := darwin/arm64 linux/amd64 + ## build: build the application -build: +build: install export GO111MODULE="auto"; \ - go mod download; \ - go mod vendor; \ - CGO_ENABLED=0 go build -a -ldflags '-s' -installsuffix cgo -o main main.go + go mod download; \ + go mod vendor; \ + CGO_ENABLED=0 go build -a -ldflags '-s' -installsuffix cgo -o main main.go + + +release: install-vendor + @for platform in $(PLATFORMS); do \ + GOOS=$$(echo $$platform | cut -d'/' -f1); \ + GOARCH=$$(echo $$platform | cut -d'/' -f2); \ + os=$$GOOS; \ + if [ "$$os" = "darwin" ]; then \ + os="macOS"; \ + fi; \ + output_name="$(APPLICATION_NAME)-$(VERSION)-$$os-$$GOARCH"; \ + if [ "$$os" = "windows" ]; then \ + output_name+=".exe"; \ + fi; \ + echo "Building release/$$output_name..."; \ + env GO11MODULE="auto" CGO_ENABLED=0 \ + GOOS=$$GOOS GOARCH=$$GOARCH go build \ + -ldflags "-w -s -X main.Version=$(VERSION)" \ + -o release/$$output_name; \ + if [ $$? -ne 0 ]; then \ + echo 'An error has occurred! Aborting.'; \ + exit 1; \ + fi; \ + cd release > /dev/null; \ + if [ "$$os" = "windows" ]; then \ + zip "$$output_name.zip" "$$output_name"; \ + rm "$$output_name"; \ + else \ + chmod a+x "$$output_name"; \ + tar -czf "$$output_name.tar" "$$output_name"; \ + rm "$$output_name"; \ + fi; \ + cd ..; \ + done ## install: fetches go modules install: - export GO111MODULE="on"; \ + export go111module="on"; \ go mod tidy; \ go mod download \ +install-vendor: install + export go111module="on"; \ + go mod vendor + ## server: runs the server with -race server: export GO111MODULE="on"; \