From 0f89a72e01a9bcde298d36fbc2e8e59a9c28c22c Mon Sep 17 00:00:00 2001 From: Dhia Ayachi Date: Mon, 25 Apr 2022 11:58:29 -0400 Subject: [PATCH] try to read license from env and mapped to container (#12854) --- .../libs/node/consul-container.go | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/integration/consul-container/libs/node/consul-container.go b/test/integration/consul-container/libs/node/consul-container.go index ae3d1a81a6..bf5b99421e 100644 --- a/test/integration/consul-container/libs/node/consul-container.go +++ b/test/integration/consul-container/libs/node/consul-container.go @@ -31,6 +31,10 @@ type consulContainerNode struct { // NewConsulContainer starts a Consul node in a container with the given config. func NewConsulContainer(ctx context.Context, config Config) (Node, error) { + license, err := readLicense() + if err != nil { + return nil, err + } name := utils.RandName("consul-") tmpDir, err := ioutils.TempDir("", name) if err != nil { @@ -59,6 +63,7 @@ func NewConsulContainer(ctx context.Context, config Config) (Node, error) { Mounts: testcontainers.ContainerMounts{testcontainers.ContainerMount{Source: testcontainers.DockerBindMountSource{HostPath: configFile}, Target: "/consul/config/config.hcl"}}, Cmd: config.Cmd, SkipReaper: skipReaper, + Env: map[string]string{"CONSUL_LICENSE": license}, } container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ ContainerRequest: req, @@ -127,3 +132,18 @@ func isRYUKDisabled() bool { } return skipReaper } + +func readLicense() (string, error) { + license := os.Getenv("CONSUL_LICENSE") + if license == "" { + licensePath := os.Getenv("CONSUL_LICENSE_PATH") + if licensePath != "" { + licenseBytes, err := os.ReadFile(licensePath) + if err != nil { + return "", err + } + license = string(licenseBytes) + } + } + return license, nil +}