drone ci config, releases go binary on github

This commit is contained in:
2025-01-18 17:43:18 +01:00
parent f4cbab188d
commit a43fa53721
2 changed files with 86 additions and 5 deletions

38
.drone.yml Normal file
View File

@@ -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
...

View File

@@ -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"; \