Skip to content

Commit 527b580

Browse files
authored
Add build flag to enable TS2019 (#928)
1 parent c31328a commit 527b580

11 files changed

+51
-12
lines changed

.goreleaser.yml

+8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ builds:
2020
- -mod=readonly
2121
ldflags:
2222
- -s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=v{{.Version}}
23+
tags:
24+
- ts2019
2325

2426
- id: darwin-arm64
2527
main: ./cmd/headscale/headscale.go
@@ -34,6 +36,8 @@ builds:
3436
- -mod=readonly
3537
ldflags:
3638
- -s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=v{{.Version}}
39+
tags:
40+
- ts2019
3741

3842
- id: linux-amd64
3943
mod_timestamp: "{{ .CommitTimestamp }}"
@@ -46,6 +50,8 @@ builds:
4650
main: ./cmd/headscale/headscale.go
4751
ldflags:
4852
- -s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=v{{.Version}}
53+
tags:
54+
- ts2019
4955

5056
- id: linux-arm64
5157
mod_timestamp: "{{ .CommitTimestamp }}"
@@ -58,6 +64,8 @@ builds:
5864
main: ./cmd/headscale/headscale.go
5965
ldflags:
6066
- -s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=v{{.Version}}
67+
tags:
68+
- ts2019
6169

6270
archives:
6371
- id: golang-cross

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- Remove `ip_prefix` configuration option and warning [#899](https://github.com/juanfont/headscale/pull/899)
2525
- Add `dns_config.override_local_dns` option [#905](https://github.com/juanfont/headscale/pull/905)
2626
- Fix some DNS config issues [#660](https://github.com/juanfont/headscale/issues/660)
27+
- Make it possible to disable TS2019 with build flag [#928](https://github.com/juanfont/headscale/pull/928)
2728

2829
## 0.16.4 (2022-08-21)
2930

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ RUN go mod download
99

1010
COPY . .
1111

12-
RUN CGO_ENABLED=0 GOOS=linux go install -ldflags="-s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=$VERSION" -a ./cmd/headscale
12+
RUN CGO_ENABLED=0 GOOS=linux go install -tags ts2019 -ldflags="-s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=$VERSION" -a ./cmd/headscale
1313
RUN strip /go/bin/headscale
1414
RUN test -e /go/bin/headscale
1515

Dockerfile.debug

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ RUN go mod download
99

1010
COPY . .
1111

12-
RUN CGO_ENABLED=0 GOOS=linux go install -ldflags="-s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=$VERSION" -a ./cmd/headscale
12+
RUN CGO_ENABLED=0 GOOS=linux go install -tags ts2019 -ldflags="-s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=$VERSION" -a ./cmd/headscale
1313
RUN test -e /go/bin/headscale
1414

1515
# Debug image

Makefile

+8-6
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@ ifeq ($(filter $(GOOS), openbsd netbsd soloaris plan9), )
1010
else
1111
endif
1212

13+
TAGS = -tags ts2019
14+
1315
# GO_SOURCES = $(wildcard *.go)
1416
# PROTO_SOURCES = $(wildcard **/*.proto)
1517
GO_SOURCES = $(call rwildcard,,*.go)
1618
PROTO_SOURCES = $(call rwildcard,,*.proto)
1719

1820

1921
build:
20-
GOOS=$(GOOS) CGO_ENABLED=0 go build -trimpath $(pieflags) -mod=readonly -ldflags "-s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=$(version)" cmd/headscale/headscale.go
22+
nix build
2123

2224
dev: lint test build
2325

2426
test:
25-
@go test -short -coverprofile=coverage.out ./...
27+
@go test $(TAGS) -short -coverprofile=coverage.out ./...
2628

2729
test_integration: test_integration_cli test_integration_derp test_integration_oidc test_integration_v2_general
2830

@@ -34,7 +36,7 @@ test_integration_cli:
3436
-v ~/.cache/hs-integration-go:/go \
3537
-v $$PWD:$$PWD -w $$PWD \
3638
-v /var/run/docker.sock:/var/run/docker.sock golang:1 \
37-
go test -failfast -timeout 30m -count=1 -run IntegrationCLI ./...
39+
go test $(TAGS) -failfast -timeout 30m -count=1 -run IntegrationCLI ./...
3840

3941
test_integration_derp:
4042
docker network rm $$(docker network ls --filter name=headscale --quiet) || true
@@ -44,7 +46,7 @@ test_integration_derp:
4446
-v ~/.cache/hs-integration-go:/go \
4547
-v $$PWD:$$PWD -w $$PWD \
4648
-v /var/run/docker.sock:/var/run/docker.sock golang:1 \
47-
go test -failfast -timeout 30m -count=1 -run IntegrationDERP ./...
49+
go test $(TAGS) -failfast -timeout 30m -count=1 -run IntegrationDERP ./...
4850

4951
test_integration_oidc:
5052
docker network rm $$(docker network ls --filter name=headscale --quiet) || true
@@ -54,7 +56,7 @@ test_integration_oidc:
5456
-v ~/.cache/hs-integration-go:/go \
5557
-v $$PWD:$$PWD -w $$PWD \
5658
-v /var/run/docker.sock:/var/run/docker.sock golang:1 \
57-
go test -failfast -timeout 30m -count=1 -run IntegrationOIDC ./...
59+
go test $(TAGS) -failfast -timeout 30m -count=1 -run IntegrationOIDC ./...
5860

5961
test_integration_v2_general:
6062
docker run \
@@ -64,7 +66,7 @@ test_integration_v2_general:
6466
-v $$PWD:$$PWD -w $$PWD/integration \
6567
-v /var/run/docker.sock:/var/run/docker.sock \
6668
golang:1 \
67-
go test ./... -timeout 60m -parallel 6
69+
go test $(TAGS) -failfast ./... -timeout 60m -parallel 6
6870

6971
coverprofile_func:
7072
go tool cover -func=coverage.out

app.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,8 @@ func (h *Headscale) createRouter(grpcMux *runtime.ServeMux) *mux.Router {
454454
router.HandleFunc("/health", h.HealthHandler).Methods(http.MethodGet)
455455
router.HandleFunc("/key", h.KeyHandler).Methods(http.MethodGet)
456456
router.HandleFunc("/register/{nkey}", h.RegisterWebAPI).Methods(http.MethodGet)
457-
router.HandleFunc("/machine/{mkey}/map", h.PollNetMapHandler).
458-
Methods(http.MethodPost)
459-
router.HandleFunc("/machine/{mkey}", h.RegistrationHandler).Methods(http.MethodPost)
457+
h.addLegacyHandlers(router)
458+
460459
router.HandleFunc("/oidc/register/{nkey}", h.RegisterOIDC).Methods(http.MethodGet)
461460
router.HandleFunc("/oidc/callback", h.OIDCCallback).Methods(http.MethodGet)
462461
router.HandleFunc("/apple", h.AppleConfigMessage).Methods(http.MethodGet)

flake.nix

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
version = headscaleVersion;
2727
src = pkgs.lib.cleanSource self;
2828

29+
tags = ["ts2019"];
30+
2931
# Only run unit tests when testing a build
3032
checkFlags = ["-short"];
3133

@@ -135,7 +137,7 @@
135137
buildInputs = devDeps;
136138

137139
shellHook = ''
138-
export GOFLAGS=-tags="integration,integration_general,integration_oidc,integration_cli,integration_derp"
140+
export GOFLAGS=-tags="ts2019"
139141
'';
140142
};
141143

handler_legacy.go

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//go:build ts2019
2+
3+
package headscale
4+
5+
import (
6+
"net/http"
7+
8+
"github.com/gorilla/mux"
9+
)
10+
11+
func (h *Headscale) addLegacyHandlers(router *mux.Router) {
12+
router.HandleFunc("/machine/{mkey}/map", h.PollNetMapHandler).
13+
Methods(http.MethodPost)
14+
router.HandleFunc("/machine/{mkey}", h.RegistrationHandler).Methods(http.MethodPost)
15+
}

handler_placeholder.go

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//go:build !ts2019
2+
3+
package headscale
4+
5+
import "github.com/gorilla/mux"
6+
7+
func (h *Headscale) addLegacyHandlers(router *mux.Router) {
8+
}

protocol_legacy.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build ts2019
2+
13
package headscale
24

35
import (

protocol_legacy_poll.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build ts2019
2+
13
package headscale
24

35
import (

0 commit comments

Comments
 (0)