CI: Include build commit or tag in binary

This commit is contained in:
nemunaire 2021-10-31 19:30:04 +01:00
parent ed1dcdd4b4
commit deb66f4279
2 changed files with 154 additions and 14 deletions

View File

@ -52,14 +52,30 @@ steps:
event: event:
- tag - tag
- name: backend - name: backend-commit
image: golang:alpine image: golang:alpine
commands: commands:
- sed -i '/yarn --offline build/d' ui/assets.go - sed -i '/yarn --offline build/d' ui/assets.go
- go generate -v - go generate -v
- go build -v -tags netgo -ldflags '-w' -o happydns-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH} - go build -v -tags netgo -ldflags '-w -X main.version="${DRONE_BRANCH}-${DRONE_COMMIT}" -X main.build=${DRONE_BUILD_NUMBER}' -o happydns-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH}
environment: environment:
CGO_ENABLED: 0 CGO_ENABLED: 0
when:
event:
exclude:
- tag
- name: backend-tag
image: golang:alpine
commands:
- sed -i '/yarn --offline build/d' ui/assets.go
- go generate -v
- go build -v -tags netgo -ldflags '-w -X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}' -o happydns-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH}
environment:
CGO_ENABLED: 0
when:
event:
- tag
- name: vet - name: vet
image: golang:alpine image: golang:alpine
@ -103,14 +119,30 @@ steps:
event: event:
- tag - tag
- name: build macOS - name: build-commit macOS
image: golang:alpine image: golang:alpine
commands: commands:
- go build -v -tags netgo -ldflags '-w' -o happydns-darwin-${DRONE_STAGE_ARCH} - go build -v -tags netgo -ldflags '-w -X main.version="${DRONE_BRANCH}-${DRONE_COMMIT}" -X main.build=${DRONE_BUILD_NUMBER}' -o happydns-darwin-${DRONE_STAGE_ARCH}
environment: environment:
CGO_ENABLED: 0 CGO_ENABLED: 0
GOOS: darwin GOOS: darwin
GOARCH: amd64 GOARCH: amd64
when:
event:
exclude:
- tag
- name: build-tag macOS
image: golang:alpine
commands:
- go build -v -tags netgo -ldflags '-w -X main.version="${DRONE_TAG##v}" -X main.build=${DRONE_BUILD_NUMBER}' -o happydns-darwin-${DRONE_STAGE_ARCH}
environment:
CGO_ENABLED: 0
GOOS: darwin
GOARCH: amd64
when:
event:
- tag
- name: deploy macOS - name: deploy macOS
image: appleboy/drone-scp image: appleboy/drone-scp
@ -157,6 +189,12 @@ steps:
password: password:
from_secret: docker_password from_secret: docker_password
trigger:
event:
- cron
- push
- tag
--- ---
kind: pipeline kind: pipeline
type: docker type: docker
@ -175,15 +213,32 @@ steps:
- yarn --cwd ui install - yarn --cwd ui install
- yarn --cwd ui --offline build - yarn --cwd ui --offline build
- name: backend - name: backend-commit
image: golang:alpine image: golang:alpine
commands: commands:
- sed -i '/yarn --offline build/d' ui/assets.go - sed -i '/yarn --offline build/d' ui/assets.go
- go generate -v - go generate -v
- go build -v -tags netgo -ldflags '-w' -o happydns-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH} - go build -v -tags netgo -ldflags '-w -X main.version="${DRONE_BRANCH}-${DRONE_COMMIT}" -X main.build=${DRONE_BUILD_NUMBER}' -o happydns-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH}
- ln happydns-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH} happydns - ln happydns-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH} happydns
environment: environment:
CGO_ENABLED: 0 CGO_ENABLED: 0
when:
event:
exclude:
- tag
- name: backend-tag
image: golang:alpine
commands:
- sed -i '/yarn --offline build/d' ui/assets.go
- go generate -v
- go build -v -tags netgo -ldflags '-w -X main.version="${DRONE_TAG##v}" -X main.build=${DRONE_BUILD_NUMBER}' -o happydns-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH}
- ln happydns-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH} happydns
environment:
CGO_ENABLED: 0
when:
event:
- tag
- name: deploy - name: deploy
image: appleboy/drone-scp image: appleboy/drone-scp
@ -219,14 +274,30 @@ steps:
event: event:
- tag - tag
- name: build macOS - name: build-commit macOS
image: golang:alpine image: golang:alpine
commands: commands:
- go build -v -tags netgo -ldflags '-w' -o happydns-darwin-${DRONE_STAGE_ARCH} - go build -v -tags netgo -ldflags '-w -X main.version="${DRONE_BRANCH}-${DRONE_COMMIT}" -X main.build=${DRONE_BUILD_NUMBER}' -o happydns-darwin-${DRONE_STAGE_ARCH}
environment: environment:
CGO_ENABLED: 0 CGO_ENABLED: 0
GOOS: darwin GOOS: darwin
GOARCH: arm64 GOARCH: arm64
when:
event:
exclude:
- tag
- name: build-tag macOS
image: golang:alpine
commands:
- go build -v -tags netgo -ldflags '-w -X main.version="${DRONE_TAG##v}" -X main.build=${DRONE_BUILD_NUMBER}' -o happydns-darwin-${DRONE_STAGE_ARCH}
environment:
CGO_ENABLED: 0
GOOS: darwin
GOARCH: arm64
when:
event:
- tag
- name: deploy macOS - name: deploy macOS
image: appleboy/drone-scp image: appleboy/drone-scp
@ -274,6 +345,12 @@ steps:
password: password:
from_secret: docker_password from_secret: docker_password
trigger:
event:
- cron
- push
- tag
--- ---
kind: pipeline kind: pipeline
type: docker type: docker
@ -292,16 +369,34 @@ steps:
- yarn --cwd ui install - yarn --cwd ui install
- yarn --cwd ui --offline build - yarn --cwd ui --offline build
- name: backend armel - name: backend-commit armel
image: golang:alpine image: golang:alpine
commands: commands:
- apk --no-cache add build-base - apk --no-cache add build-base
- sed -i '/yarn --offline build/d' ui/assets.go - sed -i '/yarn --offline build/d' ui/assets.go
- go generate -v - go generate -v
- go build -v -tags netgo -ldflags '-w' -o happydns-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH}el - go build -v -tags netgo -ldflags '-w -X main.version="${DRONE_BRANCH}-${DRONE_COMMIT}" -X main.build=${DRONE_BUILD_NUMBER}' -o happydns-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH}el
environment: environment:
CGO_ENABLED: 0 CGO_ENABLED: 0
GOARM: 5 GOARM: 5
when:
event:
exclude:
- tag
- name: backend-tag armel
image: golang:alpine
commands:
- apk --no-cache add build-base
- sed -i '/yarn --offline build/d' ui/assets.go
- go generate -v
- go build -v -tags netgo -ldflags '-w -X main.version="${DRONE_TAG##v}" -X main.build=${DRONE_BUILD_NUMBER}' -o happydns-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH}el
environment:
CGO_ENABLED: 0
GOARM: 5
when:
event:
- tag
- name: deploy armel - name: deploy armel
image: appleboy/drone-scp image: appleboy/drone-scp
@ -337,14 +432,30 @@ steps:
event: event:
- tag - tag
- name: backend armhf - name: backend-commit armhf
image: golang:alpine image: golang:alpine
commands: commands:
- apk --no-cache add build-base - apk --no-cache add build-base
- go build -v -tags netgo -ldflags '-w' -o happydns-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH}hf - go build -v -tags netgo -ldflags '-w -X main.version="${DRONE_BRANCH}-${DRONE_COMMIT}" -X main.build=${DRONE_BUILD_NUMBER}' -o happydns-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH}hf
environment: environment:
CGO_ENABLED: 0 CGO_ENABLED: 0
GOARM: 6 GOARM: 6
when:
event:
exclude:
- tag
- name: backend-tag armhf
image: golang:alpine
commands:
- apk --no-cache add build-base
- go build -v -tags netgo -ldflags '-w -X main.version="${DRONE_TAG##v}" -X main.build=${DRONE_BUILD_NUMBER}' -o happydns-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH}hf
environment:
CGO_ENABLED: 0
GOARM: 6
when:
event:
- tag
- name: deploy armhf - name: deploy armhf
image: appleboy/drone-scp image: appleboy/drone-scp
@ -380,15 +491,32 @@ steps:
event: event:
- tag - tag
- name: backend armv7 - name: backend-commit armv7
image: golang:alpine image: golang:alpine
commands: commands:
- apk --no-cache add build-base - apk --no-cache add build-base
- go build -v -tags netgo -ldflags '-w' -o happydns-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH}v7 - go build -v -tags netgo -ldflags '-w -X main.version="${DRONE_BRANCH}-${DRONE_COMMIT}" -X main.build=${DRONE_BUILD_NUMBER}' -o happydns-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH}v7
- ln happydns-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH}v7 happydns - ln happydns-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH}v7 happydns
environment: environment:
CGO_ENABLED: 0 CGO_ENABLED: 0
GOARM: 7 GOARM: 7
when:
event:
exclude:
- tag
- name: backend-tag armv7
image: golang:alpine
commands:
- apk --no-cache add build-base
- go build -v -tags netgo -ldflags '-w -X main.version="${DRONE_TAG##v}" -X main.build=${DRONE_BUILD_NUMBER}' -o happydns-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH}v7
- ln happydns-${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH}v7 happydns
environment:
CGO_ENABLED: 0
GOARM: 7
when:
event:
- tag
- name: deploy armv7 - name: deploy armv7
image: appleboy/drone-scp image: appleboy/drone-scp
@ -436,6 +564,12 @@ steps:
password: password:
from_secret: docker_password from_secret: docker_password
trigger:
event:
- cron
- push
- tag
--- ---
kind: pipeline kind: pipeline
name: docker-manifest name: docker-manifest
@ -454,6 +588,7 @@ steps:
trigger: trigger:
event: event:
- cron
- push - push
- tag - tag

View File

@ -51,9 +51,14 @@ import (
_ "git.happydns.org/happydns/storage/leveldb" _ "git.happydns.org/happydns/storage/leveldb"
) )
var (
Version = "custom-build"
)
func main() { func main() {
var err error var err error
log.Println("This is happyDNS", Version)
rand.Seed(time.Now().UTC().UnixNano()) rand.Seed(time.Now().UTC().UnixNano())
// Load and parse options // Load and parse options