Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
LDFLAGS := -ldflags="-s -w -X main.version=$(VERSION)"

.PHONY: build build-osx build-linux test clean docker-image

build: build-osx build-linux

build-osx:
@mkdir -p build
GOOS=darwin GOARCH=arm64 go build -o build/tsidp-server-darwin-arm64-$(shell date +%Y-%m-%d)-$(shell git rev-parse --short=5 HEAD) ./tsidp-server.go
GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -o build/tsidp-server-darwin-arm64-$(shell date +%Y-%m-%d)-$(shell git rev-parse --short=5 HEAD) ./tsidp-server.go

build-linux:
@mkdir -p build
GOOS=linux GOARCH=amd64 go build -o build/tsidp-server-linux-amd64-$(shell date +%Y-%m-%d)-$(shell git rev-parse --short=5 HEAD) ./tsidp-server.go
GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o build/tsidp-server-linux-amd64-$(shell date +%Y-%m-%d)-$(shell git rev-parse --short=5 HEAD) ./tsidp-server.go

docker-image:
docker build -t tsidp:latest .
Expand Down
8 changes: 8 additions & 0 deletions tsidp-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ import (
"tailscale.com/version"
)

// version is set at build time via -ldflags "-X main.version=..."
var version = "dev"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given this imports Tailscale.com/version ... is this more a buildVersion?


// Command line flags
var (
flagPort = flag.Int("port", envIntOr("TSIDP_PORT", 443), "port to listen on")
Expand All @@ -57,6 +60,11 @@ var (
func main() {
ctx := context.Background()

if len(os.Args) == 2 && os.Args[1] == "--version" {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only handles the exact invocation tsidp-server --version. It silently ignores:

  • tsidp-server -version (single dash, which flag accepts for any flag)
  • tsidp-server --version --port 443 (version mixed with other flags)

The idiomatic Go approach is to register it as a proper flag:
flagVersion = flag.Bool("version", false, "print version and exit")
Then after flag.Parse(), check *flagVersion. This integrates naturally with -help output too — right now --version doesn't appear in tsidp-server --help.

fmt.Println(version)
os.Exit(0)
}

flag.Parse()
switch *flagLogLevel {
case "debug":
Expand Down