From b02abbb11666580f98ec4ce47e88b4751dacbd8d Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Tue, 8 Oct 2024 15:59:13 +1100 Subject: [PATCH] test: add test with lagoon and docker-compose files --- cmd/identify_imagebuild_test.go | 62 ++++++++++++++++++- .../docker-compose.forcebaseimagepull-2.yml | 23 +++++++ .../basic/lagoon.forcebaseimagepull-2.yml | 10 +++ 3 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 internal/testdata/basic/docker-compose.forcebaseimagepull-2.yml create mode 100644 internal/testdata/basic/lagoon.forcebaseimagepull-2.yml diff --git a/cmd/identify_imagebuild_test.go b/cmd/identify_imagebuild_test.go index 871ffc09..4c713f5e 100644 --- a/cmd/identify_imagebuild_test.go +++ b/cmd/identify_imagebuild_test.go @@ -5,6 +5,7 @@ import ( "os" "testing" + "github.com/andreyvit/diff" "github.com/uselagoon/build-deploy-tool/internal/dbaasclient" "github.com/uselagoon/build-deploy-tool/internal/generator" "github.com/uselagoon/build-deploy-tool/internal/helpers" @@ -752,6 +753,61 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { }, }, }, + { + name: "test12 Force Pull Base Images with variable replacement", + args: testdata.GetSeedData( + testdata.TestData{ + Namespace: "example-project-main", + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "internal/testdata/basic/lagoon.forcebaseimagepull-2.yml", + ProjectVariables: []lagoon.EnvironmentVariable{ + { + Name: "BASE_IMAGE_TAG", + Value: "my-tag", + Scope: "build", + }, + { + Name: "BASE_IMAGE_REPO", + Value: "my-repo", + Scope: "build", + }, + }, + }, true), + want: imageBuild{ + BuildKit: helpers.BoolPtr(true), + BuildArguments: map[string]string{ + "BASE_IMAGE_TAG": "my-tag", + "BASE_IMAGE_REPO": "my-repo", + "LAGOON_BUILD_NAME": "lagoon-build-abcdefg", + "LAGOON_PROJECT": "example-project", + "LAGOON_ENVIRONMENT": "main", + "LAGOON_ENVIRONMENT_TYPE": "production", + "LAGOON_BUILD_TYPE": "branch", + "LAGOON_GIT_SOURCE_REPOSITORY": "ssh://git@example.com/lagoon-demo.git", + "LAGOON_KUBERNETES": "remote-cluster1", + "LAGOON_GIT_SHA": "abcdefg123456", + "LAGOON_GIT_BRANCH": "main", + "NODE_IMAGE": "example-project-main-node", + "LAGOON_SSH_PRIVATE_KEY": "-----BEGIN OPENSSH PRIVATE KEY-----\nthisisafakekey\n-----END OPENSSH PRIVATE KEY-----", + }, + ForcePullImages: []string{ + "registry.com/my-repo/imagename:my-tag", + }, + Images: []imageBuilds{ + { + Name: "node", + ImageBuild: generator.ImageBuild{ + BuildImage: "harbor.example/example-project/main/node:latest", + Context: "internal/testdata/basic/docker", + DockerFile: "basic.dockerfile", + TemporaryImage: "example-project-main-node", + }, + }, + }, + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -788,10 +844,10 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { t.Errorf("%v", err) } - oJ, _ := json.Marshal(out) - wJ, _ := json.Marshal(tt.want) + oJ, _ := json.MarshalIndent(out, "", " ") + wJ, _ := json.MarshalIndent(tt.want, "", " ") if string(oJ) != string(wJ) { - t.Errorf("returned output %v doesn't match want %v", string(oJ), string(wJ)) + t.Errorf("ImageBuildConfigurationIdentification() = \n%v", diff.LineDiff(string(oJ), string(wJ))) } t.Cleanup(func() { helpers.UnsetEnvVars(tt.vars) diff --git a/internal/testdata/basic/docker-compose.forcebaseimagepull-2.yml b/internal/testdata/basic/docker-compose.forcebaseimagepull-2.yml new file mode 100644 index 00000000..ba74b5a5 --- /dev/null +++ b/internal/testdata/basic/docker-compose.forcebaseimagepull-2.yml @@ -0,0 +1,23 @@ +version: '2' +services: + node: + networks: + - amazeeio-network + - default + build: + context: internal/testdata/basic/docker + dockerfile: basic.dockerfile + labels: + lagoon.type: basic + lagoon.service.usecomposeports: true + lagoon.base.image: registry.com/${BASE_IMAGE_REPO:-namespace}/imagename:${BASE_IMAGE_TAG:-latest} + volumes: + - .:/app:delegated + ports: + - '1234' + - '8191' + - '9001/udp' + +networks: + amazeeio-network: + external: true \ No newline at end of file diff --git a/internal/testdata/basic/lagoon.forcebaseimagepull-2.yml b/internal/testdata/basic/lagoon.forcebaseimagepull-2.yml new file mode 100644 index 00000000..b9ee74ac --- /dev/null +++ b/internal/testdata/basic/lagoon.forcebaseimagepull-2.yml @@ -0,0 +1,10 @@ +docker-compose-yaml: internal/testdata/basic/docker-compose.forcebaseimagepull-2.yml + +environment_variables: + git_sha: "true" + +environments: + main: + routes: + - node: + - example.com