-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: variable replacement support for lagoon.base.image label (#378)
* Adds ability to specify tags in refreshimages * removes println * refactor: just use one tag with variable replacement * test: add test with lagoon and docker-compose files --------- Co-authored-by: Blaize Kaye <[email protected]> Co-authored-by: shreddedbacon <[email protected]>
- Loading branch information
1 parent
d039fc9
commit b899eb6
Showing
6 changed files
with
234 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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://[email protected]/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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
internal/testdata/basic/docker-compose.forcebaseimagepull-2.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |