WIP: use gox for cross platform compiling

This commit is contained in:
Christoph Haas 2021-02-24 22:16:03 +01:00
parent 9b10d099b6
commit 4fe4d93e0d
4 changed files with 39 additions and 8 deletions

View File

@ -1,4 +1,33 @@
language: go language: go
sudo: false
go: go:
- 1.15.x - tip # Latest go version
before_install:
# gox simplifies building for multiple architectures
- go get github.com/mitchellh/gox
install:
- # skip
script:
- go get -t -v ./...
- diff -u <(echo -n) <(gofmt -d .)
- go vet $(go list ./... | grep -v /vendor/)
- gox -cgo -os="linux" -arch="amd64 arm arm64" -output="dist/{{.Dir}}_{{.OS}}_{{.Arch}}" -ldflags "-X main.Version=`git rev-parse --short HEAD`" -verbose ./...
deploy:
provider: releases
skip_cleanup: true # Important, otherwise the build output would be purged.
api_key:
# *encrypted* GitHub key, as the output of the Travis CI CLI tool
secure: TODO...
file:
- dist/wg-portal_linux_amd64
- dist/wg-portal_linux_arm64
- dist/wg-portal_linux_arm
- dist/wg-portal.env
- dist/wg-portal.service
on:
repo: h44z/wg-portal
tags: true # The deployment happens only if the commit has a tag.

View File

@ -10,15 +10,14 @@ IMAGE=h44z/wg-portal
all: dep build all: dep build
build: dep $(addsuffix -amd64,$(addprefix $(BUILDDIR)/,$(BINARIES))) build: dep
cp scripts/wg-portal.service $(BUILDDIR) mkdir -p $(BUILDDIR)
cp scripts/wg-portal.env $(BUILDDIR)
build-cross-plat: dep build $(addsuffix -arm,$(addprefix $(BUILDDIR)/,$(BINARIES))) $(addsuffix -arm64,$(addprefix $(BUILDDIR)/,$(BINARIES)))
cp scripts/wg-portal.service $(BUILDDIR) cp scripts/wg-portal.service $(BUILDDIR)
cp scripts/wg-portal.env $(BUILDDIR) cp scripts/wg-portal.env $(BUILDDIR)
gox -cgo -os="linux" -arch="amd64 arm arm64" -output="dist/{{.Dir}}_{{.OS}}_{{.Arch}}" -ldflags "-X main.Version=`git rev-parse --short HEAD`" -verbose ./...
dep: dep:
$(GOCMD) get github.com/mitchellh/gox
$(GOCMD) mod download $(GOCMD) mod download
validate: dep validate: dep

View File

@ -12,13 +12,15 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
var Version string = "unknown (local build)"
func main() { func main() {
_ = setupLogger(logrus.StandardLogger()) _ = setupLogger(logrus.StandardLogger())
c := make(chan os.Signal, 1) c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP) signal.Notify(c, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
logrus.Infof("Starting WireGuard Portal Server...") logrus.Infof("Starting WireGuard Portal Server [%s]...", Version)
// Context for clean shutdown // Context for clean shutdown
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())

1
go.mod
View File

@ -11,6 +11,7 @@ require (
github.com/jordan-wright/email v4.0.1-0.20200917010138-e1c00e156980+incompatible github.com/jordan-wright/email v4.0.1-0.20200917010138-e1c00e156980+incompatible
github.com/kelseyhightower/envconfig v1.4.0 github.com/kelseyhightower/envconfig v1.4.0
github.com/milosgajdos/tenus v0.0.3 github.com/milosgajdos/tenus v0.0.3
github.com/mitchellh/gox v1.0.1 // indirect
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.7.0 github.com/sirupsen/logrus v1.7.0
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e