From 9f90962d92f3a5301479e5555194722df501511e Mon Sep 17 00:00:00 2001 From: Tobias Trabelsi Date: Wed, 8 Nov 2023 21:10:47 +0100 Subject: [PATCH] made version configurable as well and remove "" from agent config --- internal/config/config.go | 1 + internal/hetzner/hetzneragent.go | 6 +++--- internal/hetzner/hetzneragent_test.go | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 40bd59e..09befec 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -17,6 +17,7 @@ type Config = struct { WoodpeckerGrpc string `default:"" env:"WOODPECKER_AUTOSCALER_WOODPECKER_GRPC"` WoodpeckerAgentSecret string `default:"" env:"WOODPECKER_AUTOSCALER_WOODPECKER_AGENT_SECRET"` WoodpeckerApiToken string `default:"" env:"WOODPECKER_AUTOSCALER_WOODPECKER_API_TOKEN"` + WoodpeckerAgentVersion string `default:"latest" env:"WOODPECKER_AUTOSCALER_WOODPECKER_AGENT_VERSION"` HcloudToken string `default:"" env:"WOODPECKER_AUTOSCALER_HCLOUD_TOKEN"` HcloudInstanceType string `default:"cpx21" env:"WOODPECKER_AUTOSCALER_HCLOUD_INSTANCE_TYPE"` HcloudRegion string `default:"" env:"WOODPECKER_AUTOSCALER_HCLOUD_REGION"` diff --git a/internal/hetzner/hetzneragent.go b/internal/hetzner/hetzneragent.go index acff7aa..07d3f61 100644 --- a/internal/hetzner/hetzneragent.go +++ b/internal/hetzner/hetzneragent.go @@ -47,11 +47,11 @@ func generateConfig(cfg *config.Config, name string) (string, error) { "WOODPECKER_SERVER": fmt.Sprintf("%s", cfg.WoodpeckerGrpc), "WOODPECKER_GRPC_SECURE": true, "WOODPECKER_AGENT_SECRET": fmt.Sprintf("%s", cfg.WoodpeckerAgentSecret), - "WOODPECKER_FILTER_LABELS": fmt.Sprintf(`"%s"`, cfg.WoodpeckerLabelSelector), - "WOODPECKER_HOSTNAME": fmt.Sprintf(`"%s"`, name), + "WOODPECKER_FILTER_LABELS": fmt.Sprintf("%s", cfg.WoodpeckerLabelSelector), + "WOODPECKER_HOSTNAME": fmt.Sprintf("%s", name), } config := UserDataConfig{ - Image: "woodpeckerci/woodpecker-agent:latest", + Image: fmt.Sprintf("woodpeckerci/woodpecker-agent:%s", cfg.WoodpeckerAgentVersion), EnvConfig: envConfig, } tmpl, err := template.New("userdata").Parse(USER_DATA_TEMPLATE) diff --git a/internal/hetzner/hetzneragent_test.go b/internal/hetzner/hetzneragent_test.go index c0d5977..5be20d2 100644 --- a/internal/hetzner/hetzneragent_test.go +++ b/internal/hetzner/hetzneragent_test.go @@ -16,6 +16,7 @@ func TestGenerateUserData(t *testing.T) { WoodpeckerGrpc: "grpc-test.woodpecker.test.tld:443", WoodpeckerAgentSecret: "Geheim1!", WoodpeckerApiToken: "VeryGeheim1!", + WoodpeckerAgentVersion: "latest", HcloudToken: "EvenMoreGeheim1!", HcloudInstanceType: "cpx21", HcloudRegion: "eu-central", @@ -37,9 +38,9 @@ write_files: - /var/run/docker.sock:/var/run/docker.sock environment: - WOODPECKER_AGENT_SECRET=Geheim1! - - WOODPECKER_FILTER_LABELS="uploadfilter24.eu/instance-role=WoodpeckerTest" + - WOODPECKER_FILTER_LABELS=uploadfilter24.eu/instance-role=WoodpeckerTest - WOODPECKER_GRPC_SECURE=true - - WOODPECKER_HOSTNAME="test-instance" + - WOODPECKER_HOSTNAME=test-instance - WOODPECKER_SERVER=grpc-test.woodpecker.test.tld:443 path: /root/docker-compose.yml runcmd: