mirror of
				https://github.com/juanfont/headscale.git
				synced 2025-10-28 10:51:44 +01:00 
			
		
		
		
	add git hash to binary, print on startup (#2415)
* add git hash to binary, print on startup Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com> * update changelog Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com> --------- Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
		
							parent
							
								
									1d65865425
								
							
						
					
					
						commit
						3bf7d5a9c9
					
				| @ -27,7 +27,9 @@ builds: | ||||
|     flags: | ||||
|       - -mod=readonly | ||||
|     ldflags: | ||||
|       - -s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=v{{.Version}} | ||||
|       - -s -w | ||||
|       - -X github.com/juanfont/headscale/hscontrol/types.Version={{ .Version }} | ||||
|       - -X github.com/juanfont/headscale/hscontrol/types.GitCommitHash={{ .Commit }} | ||||
|     tags: | ||||
|       - ts2019 | ||||
| 
 | ||||
|  | ||||
| @ -37,6 +37,8 @@ | ||||
|   [#2396](https://github.com/juanfont/headscale/pull/2396) | ||||
| - Rehaul HTTP errors, return better status code and errors to users | ||||
|   [#2398](https://github.com/juanfont/headscale/pull/2398) | ||||
| - Print headscale version and commit on server startup | ||||
|   [#2415](https://github.com/juanfont/headscale/pull/2415) | ||||
| 
 | ||||
| ## 0.24.3 (2025-02-07) | ||||
| 
 | ||||
|  | ||||
| @ -18,7 +18,7 @@ RUN go mod download | ||||
| 
 | ||||
| COPY . . | ||||
| 
 | ||||
| RUN CGO_ENABLED=0 GOOS=linux go install -ldflags="-s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=$VERSION" -a ./cmd/headscale && test -e /go/bin/headscale | ||||
| RUN CGO_ENABLED=0 GOOS=linux go install -a ./cmd/headscale && test -e /go/bin/headscale | ||||
| 
 | ||||
| # Need to reset the entrypoint or everything will run as a busybox script | ||||
| ENTRYPOINT [] | ||||
|  | ||||
| @ -66,18 +66,18 @@ func initConfig() { | ||||
| 	disableUpdateCheck := viper.GetBool("disable_check_updates") | ||||
| 	if !disableUpdateCheck && !machineOutput { | ||||
| 		if (runtime.GOOS == "linux" || runtime.GOOS == "darwin") && | ||||
| 			Version != "dev" { | ||||
| 			types.Version != "dev" { | ||||
| 			githubTag := &latest.GithubTag{ | ||||
| 				Owner:      "juanfont", | ||||
| 				Repository: "headscale", | ||||
| 			} | ||||
| 			res, err := latest.Check(githubTag, Version) | ||||
| 			res, err := latest.Check(githubTag, types.Version) | ||||
| 			if err == nil && res.Outdated { | ||||
| 				//nolint
 | ||||
| 				log.Warn().Msgf( | ||||
| 					"An updated version of Headscale has been found (%s vs. your current %s). Check it out https://github.com/juanfont/headscale/releases\n", | ||||
| 					res.Current, | ||||
| 					Version, | ||||
| 					types.Version, | ||||
| 				) | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| @ -1,11 +1,10 @@ | ||||
| package cli | ||||
| 
 | ||||
| import ( | ||||
| 	"github.com/juanfont/headscale/hscontrol/types" | ||||
| 	"github.com/spf13/cobra" | ||||
| ) | ||||
| 
 | ||||
| var Version = "dev" | ||||
| 
 | ||||
| func init() { | ||||
| 	rootCmd.AddCommand(versionCmd) | ||||
| } | ||||
| @ -16,6 +15,9 @@ var versionCmd = &cobra.Command{ | ||||
| 	Long:  "The version of headscale.", | ||||
| 	Run: func(cmd *cobra.Command, args []string) { | ||||
| 		output, _ := cmd.Flags().GetString("output") | ||||
| 		SuccessOutput(map[string]string{"version": Version}, Version, output) | ||||
| 		SuccessOutput(map[string]string{ | ||||
| 			"version": types.Version, | ||||
| 			"commit":  types.GitCommitHash, | ||||
| 		}, types.Version, output) | ||||
| 	}, | ||||
| } | ||||
|  | ||||
| @ -30,7 +30,7 @@ latestTag=$(git describe --tags `git rev-list --tags --max-count=1`) | ||||
| 
 | ||||
| git checkout $latestTag | ||||
| 
 | ||||
| go build -ldflags="-s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=$latestTag" github.com/juanfont/headscale | ||||
| go build -ldflags="-s -w -X github.com/juanfont/headscale/hscontrol/types.Version=$latestTag" -X github.com/juanfont/headscale/hscontrol/types.GitCommitHash=HASH" github.com/juanfont/headscale | ||||
| 
 | ||||
| # make it executable | ||||
| chmod a+x headscale | ||||
|  | ||||
							
								
								
									
										15
									
								
								flake.nix
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								flake.nix
									
									
									
									
									
								
							| @ -12,17 +12,15 @@ | ||||
|     flake-utils, | ||||
|     ... | ||||
|   }: let | ||||
|     headscaleVersion = | ||||
|       if (self ? shortRev) | ||||
|       then self.shortRev | ||||
|       else "dev"; | ||||
|     headscaleVersion = self.shortRev or self.dirtyShortRev; | ||||
|     commitHash = self.rev or self.dirtyRev; | ||||
|   in | ||||
|     { | ||||
|       overlay = _: prev: let | ||||
|         pkgs = nixpkgs.legacyPackages.${prev.system}; | ||||
|         buildGo = pkgs.buildGo123Module; | ||||
|       in { | ||||
|         headscale = buildGo rec { | ||||
|         headscale = buildGo { | ||||
|           pname = "headscale"; | ||||
|           version = headscaleVersion; | ||||
|           src = pkgs.lib.cleanSource self; | ||||
| @ -36,7 +34,12 @@ | ||||
| 
 | ||||
|           subPackages = ["cmd/headscale"]; | ||||
| 
 | ||||
|           ldflags = ["-s" "-w" "-X github.com/juanfont/headscale/cmd/headscale/cli.Version=v${version}"]; | ||||
|           ldflags = [ | ||||
|             "-s" | ||||
|             "-w" | ||||
|             "-X github.com/juanfont/headscale/hscontrol/types.Version=${headscaleVersion}" | ||||
|             "-X github.com/juanfont/headscale/hscontrol/types.GitCommitHash=${commitHash}" | ||||
|           ]; | ||||
|         }; | ||||
| 
 | ||||
|         protoc-gen-grpc-gateway = buildGo rec { | ||||
|  | ||||
| @ -566,8 +566,8 @@ func (h *Headscale) Serve() error { | ||||
| 		spew.Dump(h.cfg) | ||||
| 	} | ||||
| 
 | ||||
| 	log.Info().Str("version", types.Version).Str("commit", types.GitCommitHash).Msg("Starting Headscale") | ||||
| 	log.Info(). | ||||
| 		Caller(). | ||||
| 		Str("minimum_version", capver.TailscaleVersion(capver.MinSupportedCapabilityVersion)). | ||||
| 		Msg("Clients with a lower minimum version will be rejected") | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										4
									
								
								hscontrol/types/version.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								hscontrol/types/version.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,4 @@ | ||||
| package types | ||||
| 
 | ||||
| var Version = "dev" | ||||
| var GitCommitHash = "dev" | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user