From ec81db5c11f3d78acbe5ad48bee621dc6445bb8b Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Thu, 3 Nov 2022 20:32:03 +0100 Subject: [PATCH 1/3] Add build flag to disable TS2019 This commit starts an experiment to disable TS2019 (we also call it legacy). The two main goals for this right now is: - Diasble TS2019, and verify that the integration test clients with the appropriate TS2021 support works as expected - Get an overview of how coupled the protocol code is, if this is easy, it will be easy to remove when the time comes. Also, users with "crazy" desires like only supporting the most modern protocol _can_ build this version. Signed-off-by: Kristoffer Dalby --- Makefile | 14 ++++++++------ app.go | 5 ++--- flake.nix | 2 ++ handler_legacy.go | 15 +++++++++++++++ handler_placeholder.go | 8 ++++++++ protocol_legacy.go | 2 ++ protocol_legacy_poll.go | 2 ++ 7 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 handler_legacy.go create mode 100644 handler_placeholder.go diff --git a/Makefile b/Makefile index df9f314004..6a42f54154 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,8 @@ ifeq ($(filter $(GOOS), openbsd netbsd soloaris plan9), ) else endif +TAGS = -tags "ts2019" + # GO_SOURCES = $(wildcard *.go) # PROTO_SOURCES = $(wildcard **/*.proto) GO_SOURCES = $(call rwildcard,,*.go) @@ -17,12 +19,12 @@ PROTO_SOURCES = $(call rwildcard,,*.proto) build: - 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 + nix build dev: lint test build test: - @go test -short -coverprofile=coverage.out ./... + @go test $(TAGS) -short -coverprofile=coverage.out ./... test_integration: test_integration_cli test_integration_derp test_integration_oidc test_integration_v2_general @@ -34,7 +36,7 @@ test_integration_cli: -v ~/.cache/hs-integration-go:/go \ -v $$PWD:$$PWD -w $$PWD \ -v /var/run/docker.sock:/var/run/docker.sock golang:1 \ - go test -failfast -timeout 30m -count=1 -run IntegrationCLI ./... + go test $(TAGS) -failfast -timeout 30m -count=1 -run IntegrationCLI ./... test_integration_derp: docker network rm $$(docker network ls --filter name=headscale --quiet) || true @@ -44,7 +46,7 @@ test_integration_derp: -v ~/.cache/hs-integration-go:/go \ -v $$PWD:$$PWD -w $$PWD \ -v /var/run/docker.sock:/var/run/docker.sock golang:1 \ - go test -failfast -timeout 30m -count=1 -run IntegrationDERP ./... + go test $(TAGS) -failfast -timeout 30m -count=1 -run IntegrationDERP ./... test_integration_oidc: docker network rm $$(docker network ls --filter name=headscale --quiet) || true @@ -54,7 +56,7 @@ test_integration_oidc: -v ~/.cache/hs-integration-go:/go \ -v $$PWD:$$PWD -w $$PWD \ -v /var/run/docker.sock:/var/run/docker.sock golang:1 \ - go test -failfast -timeout 30m -count=1 -run IntegrationOIDC ./... + go test $(TAGS) -failfast -timeout 30m -count=1 -run IntegrationOIDC ./... test_integration_v2_general: docker run \ @@ -64,7 +66,7 @@ test_integration_v2_general: -v $$PWD:$$PWD -w $$PWD/integration \ -v /var/run/docker.sock:/var/run/docker.sock \ golang:1 \ - go test ./... -timeout 60m -parallel 6 + go test $(TAGS) ./... -timeout 60m -parallel 6 coverprofile_func: go tool cover -func=coverage.out diff --git a/app.go b/app.go index 38807c72eb..bf97f8861d 100644 --- a/app.go +++ b/app.go @@ -454,9 +454,6 @@ func (h *Headscale) createRouter(grpcMux *runtime.ServeMux) *mux.Router { router.HandleFunc("/health", h.HealthHandler).Methods(http.MethodGet) router.HandleFunc("/key", h.KeyHandler).Methods(http.MethodGet) router.HandleFunc("/register/{nkey}", h.RegisterWebAPI).Methods(http.MethodGet) - router.HandleFunc("/machine/{mkey}/map", h.PollNetMapHandler). - Methods(http.MethodPost) - router.HandleFunc("/machine/{mkey}", h.RegistrationHandler).Methods(http.MethodPost) router.HandleFunc("/oidc/register/{nkey}", h.RegisterOIDC).Methods(http.MethodGet) router.HandleFunc("/oidc/callback", h.OIDCCallback).Methods(http.MethodGet) router.HandleFunc("/apple", h.AppleConfigMessage).Methods(http.MethodGet) @@ -469,6 +466,8 @@ func (h *Headscale) createRouter(grpcMux *runtime.ServeMux) *mux.Router { router.HandleFunc("/swagger/v1/openapiv2.json", SwaggerAPIv1). Methods(http.MethodGet) + h.addLegacyHandlers(router) + if h.cfg.DERP.ServerEnabled { router.HandleFunc("/derp", h.DERPHandler) router.HandleFunc("/derp/probe", h.DERPProbeHandler) diff --git a/flake.nix b/flake.nix index 7b6c7866d1..f351835a4c 100644 --- a/flake.nix +++ b/flake.nix @@ -26,6 +26,8 @@ version = headscaleVersion; src = pkgs.lib.cleanSource self; + tags = ["ts2019"]; + # Only run unit tests when testing a build checkFlags = ["-short"]; diff --git a/handler_legacy.go b/handler_legacy.go new file mode 100644 index 0000000000..8911d430c7 --- /dev/null +++ b/handler_legacy.go @@ -0,0 +1,15 @@ +//go:build ts2019 + +package headscale + +import ( + "net/http" + + "github.com/gorilla/mux" +) + +func (h *Headscale) addLegacyHandlers(router *mux.Router) { + router.HandleFunc("/machine/{mkey}/map", h.PollNetMapHandler). + Methods(http.MethodPost) + router.HandleFunc("/machine/{mkey}", h.RegistrationHandler).Methods(http.MethodPost) +} diff --git a/handler_placeholder.go b/handler_placeholder.go new file mode 100644 index 0000000000..25fe9c6530 --- /dev/null +++ b/handler_placeholder.go @@ -0,0 +1,8 @@ +//go:build !ts2019 + +package headscale + +import "github.com/gorilla/mux" + +func (h *Headscale) addLegacyHandlers(router *mux.Router) { +} diff --git a/protocol_legacy.go b/protocol_legacy.go index 4e75d12730..f636c175f4 100644 --- a/protocol_legacy.go +++ b/protocol_legacy.go @@ -1,3 +1,5 @@ +//go:build ts2019 + package headscale import ( diff --git a/protocol_legacy_poll.go b/protocol_legacy_poll.go index f27ee4e357..a8d9343a65 100644 --- a/protocol_legacy_poll.go +++ b/protocol_legacy_poll.go @@ -1,3 +1,5 @@ +//go:build ts2019 + package headscale import ( From c6e8067f7c100a6b2383569784bb169fb9d105d2 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Fri, 4 Nov 2022 08:21:46 +0100 Subject: [PATCH 2/3] Update changelog Signed-off-by: Kristoffer Dalby --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6836bf06e..8eafa7f5e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - Remove `ip_prefix` configuration option and warning [#899](https://github.com/juanfont/headscale/pull/899) - Add `dns_config.override_local_dns` option [#905](https://github.com/juanfont/headscale/pull/905) - Fix some DNS config issues [#660](https://github.com/juanfont/headscale/issues/660) +- Make it possible to disable TS2019 with build flag [#928](https://github.com/juanfont/headscale/pull/928) ## 0.16.4 (2022-08-21) From 2582ffa8e6b4bd52bf48d14097e18760b6dcb58d Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Fri, 4 Nov 2022 10:25:05 +0100 Subject: [PATCH 3/3] Update tags everywhere Signed-off-by: Kristoffer Dalby --- .goreleaser.yml | 8 ++++++++ Dockerfile | 2 +- Dockerfile.debug | 2 +- Makefile | 4 ++-- app.go | 4 ++-- flake.nix | 2 +- 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index e776b5a765..d4c12c88cc 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -20,6 +20,8 @@ builds: - -mod=readonly ldflags: - -s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=v{{.Version}} + tags: + - ts2019 - id: darwin-arm64 main: ./cmd/headscale/headscale.go @@ -34,6 +36,8 @@ builds: - -mod=readonly ldflags: - -s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=v{{.Version}} + tags: + - ts2019 - id: linux-amd64 mod_timestamp: "{{ .CommitTimestamp }}" @@ -46,6 +50,8 @@ builds: main: ./cmd/headscale/headscale.go ldflags: - -s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=v{{.Version}} + tags: + - ts2019 - id: linux-arm64 mod_timestamp: "{{ .CommitTimestamp }}" @@ -58,6 +64,8 @@ builds: main: ./cmd/headscale/headscale.go ldflags: - -s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=v{{.Version}} + tags: + - ts2019 archives: - id: golang-cross diff --git a/Dockerfile b/Dockerfile index 4a83c462f6..da2d07e039 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,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 +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 RUN strip /go/bin/headscale RUN test -e /go/bin/headscale diff --git a/Dockerfile.debug b/Dockerfile.debug index a6003c64f2..7fbaef612d 100644 --- a/Dockerfile.debug +++ b/Dockerfile.debug @@ -9,7 +9,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 +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 RUN test -e /go/bin/headscale # Debug image diff --git a/Makefile b/Makefile index 6a42f54154..455389427c 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ ifeq ($(filter $(GOOS), openbsd netbsd soloaris plan9), ) else endif -TAGS = -tags "ts2019" +TAGS = -tags ts2019 # GO_SOURCES = $(wildcard *.go) # PROTO_SOURCES = $(wildcard **/*.proto) @@ -66,7 +66,7 @@ test_integration_v2_general: -v $$PWD:$$PWD -w $$PWD/integration \ -v /var/run/docker.sock:/var/run/docker.sock \ golang:1 \ - go test $(TAGS) ./... -timeout 60m -parallel 6 + go test $(TAGS) -failfast ./... -timeout 60m -parallel 6 coverprofile_func: go tool cover -func=coverage.out diff --git a/app.go b/app.go index bf97f8861d..7a67e4a3a9 100644 --- a/app.go +++ b/app.go @@ -454,6 +454,8 @@ func (h *Headscale) createRouter(grpcMux *runtime.ServeMux) *mux.Router { router.HandleFunc("/health", h.HealthHandler).Methods(http.MethodGet) router.HandleFunc("/key", h.KeyHandler).Methods(http.MethodGet) router.HandleFunc("/register/{nkey}", h.RegisterWebAPI).Methods(http.MethodGet) + h.addLegacyHandlers(router) + router.HandleFunc("/oidc/register/{nkey}", h.RegisterOIDC).Methods(http.MethodGet) router.HandleFunc("/oidc/callback", h.OIDCCallback).Methods(http.MethodGet) router.HandleFunc("/apple", h.AppleConfigMessage).Methods(http.MethodGet) @@ -466,8 +468,6 @@ func (h *Headscale) createRouter(grpcMux *runtime.ServeMux) *mux.Router { router.HandleFunc("/swagger/v1/openapiv2.json", SwaggerAPIv1). Methods(http.MethodGet) - h.addLegacyHandlers(router) - if h.cfg.DERP.ServerEnabled { router.HandleFunc("/derp", h.DERPHandler) router.HandleFunc("/derp/probe", h.DERPProbeHandler) diff --git a/flake.nix b/flake.nix index f351835a4c..595c8dc622 100644 --- a/flake.nix +++ b/flake.nix @@ -137,7 +137,7 @@ buildInputs = devDeps; shellHook = '' - export GOFLAGS=-tags="integration,integration_general,integration_oidc,integration_cli,integration_derp" + export GOFLAGS=-tags="ts2019" ''; };