mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-12-22 07:57:31 +00:00
Merge pull request #226 from neilalexander/imprint
Imprint version number onto builds
This commit is contained in:
commit
caa7b739af
@ -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
|
- New macOS .pkgs built automatically by CircleCI
|
||||||
- Add Docker support
|
- Add Docker support
|
||||||
- Add `-json` command line flag for generating and normalising configuration in plain JSON
|
- 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
|
### Changed
|
||||||
- Switched to Chord DHT (instead of Kademlia, although protocol-compatible)
|
- Switched to Chord DHT (instead of Kademlia, although protocol-compatible)
|
||||||
|
5
build
5
build
@ -14,10 +14,11 @@ go get -d -v yggdrasil
|
|||||||
for file in *.go ; do
|
for file in *.go ; do
|
||||||
echo "Building: $file"
|
echo "Building: $file"
|
||||||
#go build $@ $file
|
#go build $@ $file
|
||||||
|
IMPRINT="-X yggdrasil.buildName=$(sh contrib/semver/name.sh) -X yggdrasil.buildVersion=$(sh contrib/semver/version.sh)"
|
||||||
if [ $DEBUG ]; then
|
if [ $DEBUG ]; then
|
||||||
go build -tags debug -v $file
|
go build -ldflags="$IMPRINT" -tags debug -v $file
|
||||||
else
|
else
|
||||||
go build -ldflags="-s -w" -v $file
|
go build -ldflags="$IMPRINT -s -w" -v $file
|
||||||
fi
|
fi
|
||||||
if [ $UPX ]; then
|
if [ $UPX ]; then
|
||||||
upx --brute ${file%.go}
|
upx --brute ${file%.go}
|
||||||
|
@ -1,7 +1,16 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# Get the branch name, removing any "/" characters from pull requests
|
# Get the current branch name
|
||||||
BRANCH=$(git symbolic-ref --short HEAD | tr -d "/" 2>/dev/null)
|
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
|
# Check if the branch name is not master
|
||||||
if [ "$BRANCH" = "master" ]; then
|
if [ "$BRANCH" = "master" ]; then
|
||||||
|
@ -16,6 +16,12 @@ PATCH=$(git rev-list $TAG..master --count --merges --grep="from $DEVELOPBRANCH"
|
|||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
PATCH=$(git rev-list HEAD --count 2>/dev/null)
|
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"
|
printf 'v0.0.%d' "$PATCH"
|
||||||
exit -1
|
exit -1
|
||||||
fi
|
fi
|
||||||
|
@ -556,6 +556,8 @@ func (a *admin) getData_getSelf() *admin_nodeInfo {
|
|||||||
table := a.core.switchTable.table.Load().(lookupTable)
|
table := a.core.switchTable.table.Load().(lookupTable)
|
||||||
coords := table.self.getCoords()
|
coords := table.self.getCoords()
|
||||||
self := admin_nodeInfo{
|
self := admin_nodeInfo{
|
||||||
|
{"build_name", GetBuildName()},
|
||||||
|
{"build_version", GetBuildVersion()},
|
||||||
{"box_pub_key", hex.EncodeToString(a.core.boxPub[:])},
|
{"box_pub_key", hex.EncodeToString(a.core.boxPub[:])},
|
||||||
{"ip", a.core.GetAddress().String()},
|
{"ip", a.core.GetAddress().String()},
|
||||||
{"subnet", a.core.GetSubnet().String()},
|
{"subnet", a.core.GetSubnet().String()},
|
||||||
|
@ -12,6 +12,9 @@ import (
|
|||||||
"yggdrasil/defaults"
|
"yggdrasil/defaults"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var buildName string
|
||||||
|
var buildVersion string
|
||||||
|
|
||||||
// The Core object represents the Yggdrasil node. You should create a Core
|
// The Core object represents the Yggdrasil node. You should create a Core
|
||||||
// object for each Yggdrasil node you plan to run.
|
// object for each Yggdrasil node you plan to run.
|
||||||
type Core struct {
|
type Core struct {
|
||||||
@ -59,12 +62,38 @@ func (c *Core) init(bpub *boxPubKey,
|
|||||||
c.tun.init(c)
|
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
|
// Starts up Yggdrasil using the provided NodeConfig, and outputs debug logging
|
||||||
// through the provided log.Logger. The started stack will include TCP and UDP
|
// through the provided log.Logger. The started stack will include TCP and UDP
|
||||||
// sockets, a multicast discovery socket, an admin socket, router, switch and
|
// sockets, a multicast discovery socket, an admin socket, router, switch and
|
||||||
// DHT node.
|
// DHT node.
|
||||||
func (c *Core) Start(nc *config.NodeConfig, log *log.Logger) error {
|
func (c *Core) Start(nc *config.NodeConfig, log *log.Logger) error {
|
||||||
c.log = log
|
c.log = log
|
||||||
|
|
||||||
|
if buildName != "" {
|
||||||
|
c.log.Println("Build name:", buildName)
|
||||||
|
}
|
||||||
|
if buildVersion != "" {
|
||||||
|
c.log.Println("Build version:", buildVersion)
|
||||||
|
}
|
||||||
|
|
||||||
c.log.Println("Starting up...")
|
c.log.Println("Starting up...")
|
||||||
|
|
||||||
var boxPub boxPubKey
|
var boxPub boxPubKey
|
||||||
|
@ -100,10 +100,15 @@ func main() {
|
|||||||
normaliseconf := flag.Bool("normaliseconf", false, "use in combination with either -useconf or -useconffile, outputs your configuration normalised")
|
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")
|
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)")
|
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()
|
flag.Parse()
|
||||||
|
|
||||||
var cfg *nodeConfig
|
var cfg *nodeConfig
|
||||||
switch {
|
switch {
|
||||||
|
case *version:
|
||||||
|
fmt.Println("Build name:", yggdrasil.GetBuildName())
|
||||||
|
fmt.Println("Build version:", yggdrasil.GetBuildVersion())
|
||||||
|
os.Exit(0)
|
||||||
case *autoconf:
|
case *autoconf:
|
||||||
// Use an autoconf-generated config, this will give us random keys and
|
// Use an autoconf-generated config, this will give us random keys and
|
||||||
// port numbers, and will use an automatically selected TUN/TAP interface.
|
// port numbers, and will use an automatically selected TUN/TAP interface.
|
||||||
|
@ -181,6 +181,12 @@ func main() {
|
|||||||
}
|
}
|
||||||
case "getself":
|
case "getself":
|
||||||
for k, v := range res["self"].(map[string]interface{}) {
|
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)
|
fmt.Println("IPv6 address:", k)
|
||||||
if subnet, ok := v.(map[string]interface{})["subnet"].(string); ok {
|
if subnet, ok := v.(map[string]interface{})["subnet"].(string); ok {
|
||||||
fmt.Println("IPv6 subnet:", subnet)
|
fmt.Println("IPv6 subnet:", subnet)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user