Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #129 from kshlm/prepare-for-releases
Browse files Browse the repository at this point in the history
Prepare GD2 for releases
  • Loading branch information
kshlm authored Sep 22, 2016
2 parents 0010123 + 5559375 commit 55ecabe
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 7 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
VERSION := $(shell bash ./scripts/pkg-version --full)
LDFLAGS := '-X github.com/gluster/glusterd2/gdctx.GlusterdVersion=$(VERSION)'

.PHONY: all build check check-go check-reqs install vendor-update verify

all: build
Expand All @@ -16,12 +19,12 @@ check-reqs:

glusterd2:
@echo Building GlusterD-2.0
@GO15VENDOREXPERIMENT=1 go build
@GO15VENDOREXPERIMENT=1 go build -ldflags $(LDFLAGS)
@echo

install: check vendor-update
@echo Building and installing GlusterD-2.0
@GO15VENDOREXPERIMENT=1 go install
@GO15VENDOREXPERIMENT=1 go install -ldflags $(LDFLAGS)
@echo Setting CAP_SYS_ADMIN for glusterd2 \(requires sudo\)
sudo setcap cap_sys_admin+ep $$GOPATH/bin/glusterd2
@echo
Expand Down
7 changes: 5 additions & 2 deletions gdctx/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ import (

// Various version constants that will be used by GD2
const (
MaxOpVersion = 40000
APIVersion = 1
MaxOpVersion = 40000
APIVersion = 1
)

var (
GlusterdVersion = "4.0-dev"
)

Expand Down
13 changes: 10 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@ import (
)

func main() {
log.WithField("pid", os.Getpid()).Info("GlusterD starting")

// Parse flags and set up logging before continuing
// Parse flags and handle version and logging before continuing
parseFlags()

showvers, _ := flag.CommandLine.GetBool("version")
if showvers {
dumpVersionInfo()
return
}

logLevel, _ := flag.CommandLine.GetString("loglevel")
initLog(logLevel, os.Stderr)

log.WithField("pid", os.Getpid()).Info("GlusterD starting")

// Read in config
confFile, _ := flag.CommandLine.GetString("config")
initConfig(confFile)
Expand Down
52 changes: 52 additions & 0 deletions scripts/pkg-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/sh

# To override version/release from git,
# create VERSION file containing text with version/release
# eg. v3.4.0-1
PKG_VERSION=`cat VERSION 2> /dev/null || git describe --tags --match "v[0-9]*"`

get_version()
{
# tags and output versions:
# - v3.4.0 => 3.4.0 (upstream clean)
# - v3.4.0-1 => 3.4.0 (downstream clean)
# - v3.4.0-2-g34e62f => 3.4.0 (upstream dirty)
# - v3.4.0-1-2-g34e62f => 3.4.0 (downstream dirty)
AWK_VERSION='
BEGIN { FS="-" }
/^v[0-9]/ {
sub(/^v/,"") ; print $1
}'

echo $PKG_VERSION | awk "$AWK_VERSION" | tr -cd '[:alnum:].'
}

get_release()
{
# tags and output releases:
# - v3.4.0 => 0 (upstream clean)
# - v3.4.0-1 => 1 (downstream clean)
# - v3.4.0-2-g34e62f1 => 2.git34e62f1 (upstream dirty)
# - v3.4.0-1-2-g34e62f1 => 1.2.git34e62f1 (downstream dirty)
AWK_RELEASE='
BEGIN { FS="-"; OFS="." }
/^v[0-9]/ {
if (NF == 1) print 0
else if (NF == 2) print $2
else if (NF == 3) print $2, "git" substr($3, 2)
else if (NF == 4) print $2, $3, "git" substr($4, 2)
}'

echo $PKG_VERSION | awk "$AWK_RELEASE" | tr -cd '[:alnum:].'
}

if test "x$1" = "x--full"; then
echo -n "v$(get_version)-$(get_release)"
elif test "x$1" = "x--version"; then
get_version
elif test "x$1" = "x--release"; then
get_release
else
echo "usage: $0 [--full|--version|--release]"
exit 1
fi
18 changes: 18 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"fmt"

"github.com/gluster/glusterd2/gdctx"

flag "github.com/spf13/pflag"
)

func init() {
//Register the `--version` flag
flag.Bool("version", false, "Show the version information")
}

func dumpVersionInfo() {
fmt.Println(gdctx.GlusterdVersion)
}

0 comments on commit 55ecabe

Please sign in to comment.