From dfc03a61240a742420eff2639ba7ddcc09080fdf Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Wed, 2 Nov 2022 09:53:55 +0100 Subject: [PATCH] Ditch stupid distroless image for debug/test Signed-off-by: Kristoffer Dalby --- Dockerfile.debug | 2 +- integration/hsic/config.go | 122 +++++++++++++++++++++++++++++++++++++ integration/hsic/hsic.go | 2 +- 3 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 integration/hsic/config.go diff --git a/Dockerfile.debug b/Dockerfile.debug index ef849185..a6003c64 100644 --- a/Dockerfile.debug +++ b/Dockerfile.debug @@ -13,7 +13,7 @@ RUN CGO_ENABLED=0 GOOS=linux go install -ldflags="-s -w -X github.com/juanfont/h RUN test -e /go/bin/headscale # Debug image -FROM gcr.io/distroless/base-debian11:debug +FROM docker.io/golang:1.19.0-bullseye COPY --from=build /go/bin/headscale /bin/headscale ENV TZ UTC diff --git a/integration/hsic/config.go b/integration/hsic/config.go new file mode 100644 index 00000000..73ff495f --- /dev/null +++ b/integration/hsic/config.go @@ -0,0 +1,122 @@ +package hsic + +import ( + "net/netip" + "net/url" + "os" + "path" + "time" + + "github.com/juanfont/headscale" + "github.com/rs/zerolog" + "tailscale.com/tailcfg" + "tailscale.com/types/dnstype" +) + +const ( + defaultEphemeralNodeInactivityTimeout = time.Second * 30 + defaultNodeUpdateCheckInterval = time.Second * 10 +) + +func DefaultConfig() headscale.Config { + derpMap, _ := url.Parse("https://controlplane.tailscale.com/derpmap/default") + + config := headscale.Config{ + Log: headscale.LogConfig{ + Level: zerolog.TraceLevel, + }, + ACL: headscale.GetACLConfig(), + DBtype: "sqlite3", + EphemeralNodeInactivityTimeout: defaultEphemeralNodeInactivityTimeout, + NodeUpdateCheckInterval: defaultNodeUpdateCheckInterval, + IPPrefixes: []netip.Prefix{ + netip.MustParsePrefix("fd7a:115c:a1e0::/48"), + netip.MustParsePrefix("100.64.0.0/10"), + }, + DNSConfig: &tailcfg.DNSConfig{ + Proxied: true, + Nameservers: []netip.Addr{ + netip.MustParseAddr("127.0.0.11"), + netip.MustParseAddr("1.1.1.1"), + }, + Resolvers: []*dnstype.Resolver{ + { + Addr: "127.0.0.11", + }, + { + Addr: "1.1.1.1", + }, + }, + }, + BaseDomain: "headscale.net", + + DBpath: "/tmp/integration_test_db.sqlite3", + + PrivateKeyPath: "/tmp/integration_private.key", + NoisePrivateKeyPath: "/tmp/noise_integration_private.key", + Addr: "0.0.0.0:8080", + MetricsAddr: "127.0.0.1:9090", + ServerURL: "http://headscale:8080", + + DERP: headscale.DERPConfig{ + URLs: []url.URL{ + *derpMap, + }, + AutoUpdate: false, + UpdateFrequency: 1 * time.Minute, + }, + } + + return config +} + +// TODO: Reuse the actual configuration object above. +func DefaultConfigYAML() string { + yaml := ` +log: + level: trace +acl_policy_path: "" +db_type: sqlite3 +db_path: /tmp/integration_test_db.sqlite3 +ephemeral_node_inactivity_timeout: 30m +node_update_check_interval: 10s +ip_prefixes: + - fd7a:115c:a1e0::/48 + - 100.64.0.0/10 +dns_config: + base_domain: headscale.net + magic_dns: true + domains: [] + nameservers: + - 127.0.0.11 + - 1.1.1.1 +private_key_path: /tmp/private.key +noise: + private_key_path: /tmp/noise_private.key +listen_addr: 0.0.0.0:8080 +metrics_listen_addr: 127.0.0.1:9090 +server_url: http://headscale:8080 + +derp: + urls: + - https://controlplane.tailscale.com/derpmap/default + auto_update_enabled: false + update_frequency: 1m + ` + + return yaml +} + +func TempConfigPath(name string, config string) (string, error) { + tempDir, err := os.CreateTemp("", name) + if err != nil { + return "", err + } + + err = os.WriteFile(path.Join(tempDir.Name(), "config.yaml"), []byte(config), 0644) + if err != nil { + return "", err + } + + return tempDir.Name(), nil +} diff --git a/integration/hsic/hsic.go b/integration/hsic/hsic.go index 7db8233a..d8fda219 100644 --- a/integration/hsic/hsic.go +++ b/integration/hsic/hsic.go @@ -42,7 +42,7 @@ func New( } headscaleBuildOptions := &dockertest.BuildOptions{ - Dockerfile: "Dockerfile", + Dockerfile: "Dockerfile.debug", ContextDir: dockerContextPath, }