Skip to content

Commit a12682c

Browse files
committed
fix(container): wrong image ID when deploying external image locally
1 parent 9c19132 commit a12682c

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

garden-service/src/plugins/container/helpers.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,19 @@ export const containerHelpers = {
104104
* set as the tag.
105105
*/
106106
async getDeploymentImageId(module: ContainerModule, registryConfig?: ContainerRegistryConfig) {
107-
const imageName = await containerHelpers.getDeploymentImageName(module, registryConfig)
108-
109-
return containerHelpers.unparseImageId({
110-
repository: imageName,
111-
tag: module.version.versionString,
112-
})
107+
if (await containerHelpers.hasDockerfile(module)) {
108+
// If building, return the deployment image name, with the current module version.
109+
const imageName = await containerHelpers.getDeploymentImageName(module, registryConfig)
110+
111+
return containerHelpers.unparseImageId({
112+
repository: imageName,
113+
tag: module.version.versionString,
114+
})
115+
} else {
116+
// Otherwise, return the configured image ID.
117+
// Note: This will always be set here, otherwise validation will have failed already.
118+
return module.spec.image!
119+
}
113120
},
114121

115122
parseImageId(imageId: string): ParsedImageId {

garden-service/test/unit/src/plugins/container.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,37 @@ describe("plugins.container", () => {
116116
})
117117
})
118118

119+
describe("getDeploymentImageId", () => {
120+
it("should return module name with module version if there is a Dockerfile and no image name set", async () => {
121+
const config = cloneDeep(baseConfig)
122+
const module = await getTestModule(config)
123+
124+
td.replace(containerHelpers, "hasDockerfile", async () => true)
125+
126+
expect(await containerHelpers.getDeploymentImageId(module)).to.equal("test:1234")
127+
})
128+
129+
it("should return image name with module version if there is a Dockerfile and image name is set", async () => {
130+
const config = cloneDeep(baseConfig)
131+
config.spec.image = "some/image:1.1"
132+
const module = await getTestModule(config)
133+
134+
td.replace(containerHelpers, "hasDockerfile", async () => true)
135+
136+
expect(await containerHelpers.getDeploymentImageId(module)).to.equal("some/image:1234")
137+
})
138+
139+
it("should return configured image tag if there is no Dockerfile", async () => {
140+
const config = cloneDeep(baseConfig)
141+
config.spec.image = "some/image:1.1"
142+
const module = await getTestModule(config)
143+
144+
td.replace(containerHelpers, "hasDockerfile", async () => false)
145+
146+
expect(await containerHelpers.getDeploymentImageId(module)).to.equal("some/image:1.1")
147+
})
148+
})
149+
119150
describe("getDockerfilePathFromModule", () => {
120151
it("should return the absolute default Dockerfile path", async () => {
121152
const module = await getTestModule(baseConfig)

0 commit comments

Comments
 (0)