Skip to content

Commit

Permalink
add flavour, version command, fix version source
Browse files Browse the repository at this point in the history
- make makefile single source of truth for version
- trigger the flow in the tests
  • Loading branch information
ph4r05 committed May 23, 2024
1 parent 9ce86fc commit 6c3868f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
config.yml
keymaster.spec
27 changes: 21 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ endif
BINARY=keymaster

# These are the values we want to pass for Version and BuildTime
VERSION=1.15.3
VERSION?=1.15.3
DEFAULT_HOST?=
DEFAULT_LDFLAGS=-X main.Version=${VERSION}
VERSION_FLAVOUR?=
EXTRA_LDFLAGS?=
PRINTVERSION=${VERSION}
ifneq ($(VERSION_FLAVOUR),)
PRINTVERSION=${VERSION}-${VERSION_FLAVOUR}
endif
DEFAULT_LDFLAGS=-X main.Version=${PRINTVERSION} ${EXTRA_LDFLAGS}
CLIENT_LDFLAGS=${DEFAULT_LDFLAGS} -X main.defaultHost=${DEFAULT_HOST}
#BUILD_TIME=`date +%FT%T%z`

Expand All @@ -39,16 +45,25 @@ all: install-client
cd cmd/keymaster-unlocker; go install -ldflags "${DEFAULT_LDFLAGS}"
cd cmd/keymaster-eventmond; go install -ldflags "${DEFAULT_LDFLAGS}"

build: cmd/keymasterd/binData.go
build: prebuild
go build ${EXTRA_BUILD_FLAGS} -ldflags "${CLIENT_LDFLAGS}" -o $(OUTPUT_DIR) ./...

cmd/keymasterd/binData.go:
-go-bindata -fs -o cmd/keymasterd/binData.go -prefix cmd/keymasterd/data cmd/keymasterd/data/...

install-client: cmd/keymasterd/binData.go
keymaster.spec:
ifeq ($(OS), Windows_NT)
powershell -Command "Get-Content keymaster.spec.tpl | ForEach-Object { \$$_.Replace('{{VERSION}}', '$(VERSION)') } | Set-Content keymaster.spec"
else
sed 's/{{VERSION}}/$(VERSION)/g' keymaster.spec.tpl > keymaster.spec;
endif

prebuild: keymaster.spec cmd/keymasterd/binData.go

install-client: prebuild
cd cmd/keymaster; go install ${EXTRA_BUILD_FLAGS} -ldflags "${CLIENT_LDFLAGS}"

build-client: cmd/keymasterd/binData.go
build-client: prebuild
go build -ldflags "${CLIENT_LDFLAGS}" -o $(OUTPUT_DIR) $(CLIENT_DEST)

win-client: client-test
Expand All @@ -64,7 +79,7 @@ clean:
rm -f bin/*
rm -f keymaster-*.tar.gz

${BINARY}-${VERSION}.tar.gz:
${BINARY}-${VERSION}.tar.gz: prebuild
mkdir ${BINARY}-${VERSION}
rsync -av --exclude="config.yml" --exclude="*.pem" --exclude="*.out" lib/ ${BINARY}-${VERSION}/lib/
rsync -av --exclude="config.yml" --exclude="*.pem" --exclude="*.out" --exclude="*.key" cmd/ ${BINARY}-${VERSION}/cmd/
Expand Down
7 changes: 6 additions & 1 deletion cmd/keymaster/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ var (
"If true, use the smart round-robin dialer")
webauthBrowser = flag.String("webauthBrowser", "",
"Browser command to use for webauth")

printVersion = flag.Bool("version", false,
"Print version and exit")
FilePrefix = "keymaster"
)

Expand Down Expand Up @@ -496,6 +497,10 @@ func main() {
flag.Usage = Usage
flag.Parse()
logger := cmdlogger.New()
if *printVersion {
fmt.Println(Version)
return
}
rootCAs, err := maybeGetRootCas(*rootCAFilename, logger)
if err != nil {
logger.Fatal(err)
Expand Down
10 changes: 10 additions & 0 deletions cmd/keymaster/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,13 @@ func TestInsertSSHCertIntoAgentORWriteToFilesystem(t *testing.T) {
// TODO: on linux/macos create agent + unix socket and pass that

}

func TestMainPrintVersion(t *testing.T) {
os.Args = []string{"cmd", "-version"}
done := make(chan struct{})
go func() {
main()
close(done)
}()
<-done
}
4 changes: 1 addition & 3 deletions keymaster.spec → keymaster.spec.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: keymaster
Version: 1.15.3
Version: {{VERSION}}
Release: 1%{?dist}
Summary: Short term access certificate generator and client

Expand Down Expand Up @@ -74,5 +74,3 @@ systemctl daemon-reload
%config(noreplace) %{_datarootdir}/keymasterd/customization_data/web_resources/*
%config(noreplace) %{_datarootdir}/keymasterd/customization_data/templates/*
%changelog


0 comments on commit 6c3868f

Please sign in to comment.