5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-09-19 16:09:36 +00:00

Merge pull request #226 from neilalexander/imprint

Imprint version number onto builds
This commit is contained in:
Arceliar 2018-12-07 17:37:20 -06:00 committed by GitHub
commit caa7b739af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 63 additions and 5 deletions

View File

@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- New macOS .pkgs built automatically by CircleCI
- Add Docker support
- Add `-json` command line flag for generating and normalising configuration in plain JSON
- Build name and version numbers are now imprinted onto the build, accessible through `yggdrasil -version` and `yggdrasilctl getSelf`
### Changed
- Switched to Chord DHT (instead of Kademlia, although protocol-compatible)

View File

@ -1 +0,0 @@
0.2

5
build
View File

@ -14,10 +14,11 @@ go get -d -v yggdrasil
for file in *.go ; do
echo "Building: $file"
#go build $@ $file
IMPRINT="-X yggdrasil.buildName=$(sh contrib/semver/name.sh) -X yggdrasil.buildVersion=$(sh contrib/semver/version.sh)"
if [ $DEBUG ]; then
go build -tags debug -v $file
go build -ldflags="$IMPRINT" -tags debug -v $file
else
go build -ldflags="-s -w" -v $file
go build -ldflags="$IMPRINT -s -w" -v $file
fi
if [ $UPX ]; then
upx --brute ${file%.go}

View File

@ -1,7 +1,16 @@
#!/bin/sh
# Get the branch name, removing any "/" characters from pull requests
BRANCH=$(git symbolic-ref --short HEAD | tr -d "/" 2>/dev/null)
# Get the current branch name
BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null)
# Complain if the git history is not available
if [ $? != 0 ]; then
printf "unknown"
exit -1
fi
# Remove "/" characters from the branch name if present
BRANCH=$(echo $BRANCH | tr -d "/")
# Check if the branch name is not master
if [ "$BRANCH" = "master" ]; then

View File

@ -16,6 +16,12 @@ PATCH=$(git rev-list $TAG..master --count --merges --grep="from $DEVELOPBRANCH"
if [ $? != 0 ]; then
PATCH=$(git rev-list HEAD --count 2>/dev/null)
# Complain if the git history is not available
if [ $? != 0 ]; then
printf 'unknown'
exit -1
fi
printf 'v0.0.%d' "$PATCH"
exit -1
fi

View File

@ -556,6 +556,8 @@ func (a *admin) getData_getSelf() *admin_nodeInfo {
table := a.core.switchTable.table.Load().(lookupTable)
coords := table.self.getCoords()
self := admin_nodeInfo{
{"build_name", GetBuildName()},
{"build_version", GetBuildVersion()},
{"box_pub_key", hex.EncodeToString(a.core.boxPub[:])},
{"ip", a.core.GetAddress().String()},
{"subnet", a.core.GetSubnet().String()},

View File

@ -12,6 +12,9 @@ import (
"yggdrasil/defaults"
)
var buildName string
var buildVersion string
// The Core object represents the Yggdrasil node. You should create a Core
// object for each Yggdrasil node you plan to run.
type Core struct {
@ -59,12 +62,38 @@ func (c *Core) init(bpub *boxPubKey,
c.tun.init(c)
}
// Get the current build name. This is usually injected if built from git,
// or returns "unknown" otherwise.
func GetBuildName() string {
if buildName == "" {
return "unknown"
}
return buildName
}
// Get the current build version. This is usually injected if built from git,
// or returns "unknown" otherwise.
func GetBuildVersion() string {
if buildVersion == "" {
return "unknown"
}
return buildVersion
}
// Starts up Yggdrasil using the provided NodeConfig, and outputs debug logging
// through the provided log.Logger. The started stack will include TCP and UDP
// sockets, a multicast discovery socket, an admin socket, router, switch and
// DHT node.
func (c *Core) Start(nc *config.NodeConfig, log *log.Logger) error {
c.log = log
if buildName != "" {
c.log.Println("Build name:", buildName)
}
if buildVersion != "" {
c.log.Println("Build version:", buildVersion)
}
c.log.Println("Starting up...")
var boxPub boxPubKey

View File

@ -100,10 +100,15 @@ func main() {
normaliseconf := flag.Bool("normaliseconf", false, "use in combination with either -useconf or -useconffile, outputs your configuration normalised")
confjson := flag.Bool("json", false, "print configuration from -genconf or -normaliseconf as JSON instead of HJSON")
autoconf := flag.Bool("autoconf", false, "automatic mode (dynamic IP, peer with IPv6 neighbors)")
version := flag.Bool("version", false, "prints the version of this build")
flag.Parse()
var cfg *nodeConfig
switch {
case *version:
fmt.Println("Build name:", yggdrasil.GetBuildName())
fmt.Println("Build version:", yggdrasil.GetBuildVersion())
os.Exit(0)
case *autoconf:
// Use an autoconf-generated config, this will give us random keys and
// port numbers, and will use an automatically selected TUN/TAP interface.

View File

@ -181,6 +181,12 @@ func main() {
}
case "getself":
for k, v := range res["self"].(map[string]interface{}) {
if buildname, ok := v.(map[string]interface{})["build_name"].(string); ok {
fmt.Println("Build name:", buildname)
}
if buildversion, ok := v.(map[string]interface{})["build_version"].(string); ok {
fmt.Println("Build version:", buildversion)
}
fmt.Println("IPv6 address:", k)
if subnet, ok := v.(map[string]interface{})["subnet"].(string); ok {
fmt.Println("IPv6 subnet:", subnet)