From 7654dc4e14abc6b724d4f200d72da911bca8a13e Mon Sep 17 00:00:00 2001 From: Jonathan Chappelow Date: Wed, 28 Feb 2024 15:12:41 -0600 Subject: [PATCH] test/integration: for TestLocalDevSetup / -dev, expose http ports --- .../package/docker/postgres.dockerfile | 0 test/integration/docker-compose.yml.template | 12 +++++------ test/integration/helper.go | 20 ++++++++++++++++++- test/integration/kwild_test.go | 1 + test/utils/compose.go | 4 ++++ 5 files changed, 30 insertions(+), 7 deletions(-) rename deployments/compose/postgres/Dockerfile => build/package/docker/postgres.dockerfile (100%) diff --git a/deployments/compose/postgres/Dockerfile b/build/package/docker/postgres.dockerfile similarity index 100% rename from deployments/compose/postgres/Dockerfile rename to build/package/docker/postgres.dockerfile diff --git a/test/integration/docker-compose.yml.template b/test/integration/docker-compose.yml.template index 8b658e729..c5fd2dc27 100644 --- a/test/integration/docker-compose.yml.template +++ b/test/integration/docker-compose.yml.template @@ -5,7 +5,7 @@ services: node0: image: kwild:latest ports: - - "8080" + - "{{with .ExposedHTTPPorts}}{{index . 0}}:{{end}}8080" - "50051" - "26656" - "26657" @@ -67,7 +67,7 @@ services: node1: image: kwild:latest ports: - - "8080" + - "{{with .ExposedHTTPPorts}}{{index . 1}}:{{end}}8080" - "50051" - "26656" - "26657" @@ -127,7 +127,7 @@ services: node2: image: kwild:latest ports: - - "8080" + - "{{with .ExposedHTTPPorts}}{{index . 2}}:{{end}}8080" - "50051" - "26656" - "26657" @@ -190,7 +190,7 @@ services: node3: image: kwild:latest ports: - - "8080" + - "{{with .ExposedHTTPPorts}}{{index . 3}}:{{end}}8080" - "50051" - "26656" - "26657" @@ -250,7 +250,7 @@ services: node4: image: kwild:latest ports: - - "8080" + - "{{with .ExposedHTTPPorts}}{{index . 4}}:{{end}}8080" - "50051" - "26656" - "26657" @@ -310,7 +310,7 @@ services: node5: image: kwild:latest ports: - - "8080" + - "{{with .ExposedHTTPPorts}}{{index . 5}}:{{end}}8080" - "50051" - "26656" - "26657" diff --git a/test/integration/helper.go b/test/integration/helper.go index f63498364..e7fa6c2d3 100644 --- a/test/integration/helper.go +++ b/test/integration/helper.go @@ -87,6 +87,7 @@ type IntTestConfig struct { DockerComposeOverrideFile string GanacheComposeFile string WithGanache bool + ExposedHTTPPorts bool WaitTimeout time.Duration LogLevel string @@ -177,6 +178,12 @@ func WithNonValidators(n int) HelperOpt { } } +func WithExposedHTTPPorts() HelperOpt { + return func(r *IntHelper) { + r.cfg.ExposedHTTPPorts = true + } +} + func WithJoinExpiry(expiry int64) HelperOpt { return func(r *IntHelper) { r.cfg.JoinExpiry = expiry @@ -512,11 +519,22 @@ func (r *IntHelper) prepareDockerCompose(ctx context.Context, tmpDir string) { // docker-compose file is to use envs in docker-compose.yml, but it doesn't work //r.updateEnv("KWIL_NETWORK", localNetworkName) + var exposedHTTPPorts []int + if r.cfg.ExposedHTTPPorts { + // Actually only need this as long as the number of nodes defined in + // the docker-compose.yml.template file. This is not related to + // NValidators and NNValidators. + for i := 0; i < 20; i++ { // more than enough, which is 6 presently + exposedHTTPPorts = append(exposedHTTPPorts, i+8080+1) + } + } + // here we generate a new docker-compose.yml file with the new network from template composeFile := filepath.Join(tmpDir, "docker-compose.yml") err = utils.CreateComposeFile(composeFile, "./docker-compose.yml.template", utils.ComposeConfig{ - Network: localNetworkName, + Network: localNetworkName, + ExposedHTTPPorts: exposedHTTPPorts, }) require.NoError(r.t, err, "failed to create docker compose file") diff --git a/test/integration/kwild_test.go b/test/integration/kwild_test.go index 7fcaa7274..5e937028c 100644 --- a/test/integration/kwild_test.go +++ b/test/integration/kwild_test.go @@ -45,6 +45,7 @@ func TestLocalDevSetup(t *testing.T) { integration.WithBlockInterval(time.Second), integration.WithValidators(4), integration.WithNonValidators(0), + integration.WithExposedHTTPPorts(), } helper := integration.NewIntHelper(t, opts...) diff --git a/test/utils/compose.go b/test/utils/compose.go index 47fcc3794..5c0a19a43 100644 --- a/test/utils/compose.go +++ b/test/utils/compose.go @@ -8,6 +8,10 @@ import ( type ComposeConfig struct { Network string + // ExposedHTTPPorts can be left empty to not expose any ports to the host, + // or set to the host ports to expose the http interface for each node. e.g. + // []int{8081, 8082, ...} + ExposedHTTPPorts []int } func genCompose(templateFile string, config ComposeConfig) (string, error) {