Write headcsale config file from code, not depend on directory

Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
Kristoffer Dalby 2022-11-02 09:55:48 +01:00 committed by Juan Font
parent 43731cad2e
commit 947e961a3a

View file

@ -52,24 +52,14 @@ func New(
hostname := fmt.Sprintf("hs-%s", hash) hostname := fmt.Sprintf("hs-%s", hash)
portProto := fmt.Sprintf("%d/tcp", port) portProto := fmt.Sprintf("%d/tcp", port)
currentPath, err := os.Getwd()
if err != nil {
return nil, fmt.Errorf("could not determine current path: %w", err)
}
integrationConfigPath := path.Join(currentPath, "..", "integration_test", "etc")
runOptions := &dockertest.RunOptions{ runOptions := &dockertest.RunOptions{
Name: hostname, Name: hostname,
// TODO(kradalby): Do something clever here, can we ditch the config repo?
// Always generate the config from code?
Mounts: []string{
fmt.Sprintf("%s:/etc/headscale", integrationConfigPath),
},
ExposedPorts: []string{portProto}, ExposedPorts: []string{portProto},
// TODO(kradalby): WHY do we need to bind these now that we run fully in docker? Networks: []*dockertest.Network{network},
Networks: []*dockertest.Network{network}, // Cmd: []string{"headscale", "serve"},
Cmd: []string{"headscale", "serve"}, // TODO(kradalby): Get rid of this hack, we currently need to give us some
// to inject the headscale configuration further down.
Entrypoint: []string{"/bin/bash", "-c", "/bin/sleep 3 ; headscale serve"},
} }
// dockertest isnt very good at handling containers that has already // dockertest isnt very good at handling containers that has already
@ -92,14 +82,21 @@ func New(
} }
log.Printf("Created %s container\n", hostname) log.Printf("Created %s container\n", hostname)
return &HeadscaleInContainer{ hsic := &HeadscaleInContainer{
hostname: hostname, hostname: hostname,
port: port, port: port,
pool: pool, pool: pool,
container: container, container: container,
network: network, network: network,
}, nil }
err = hsic.WriteFile("/etc/headscale/config.yaml", []byte(DefaultConfigYAML()))
if err != nil {
return nil, fmt.Errorf("failed to write headscale config to container: %w", err)
}
return hsic, nil
} }
func (t *HeadscaleInContainer) Shutdown() error { func (t *HeadscaleInContainer) Shutdown() error {