diff --git a/garden-service/src/plugins/container/helpers.ts b/garden-service/src/plugins/container/helpers.ts index c631eb4aaa..2c762cf10f 100644 --- a/garden-service/src/plugins/container/helpers.ts +++ b/garden-service/src/plugins/container/helpers.ts @@ -104,12 +104,19 @@ export const containerHelpers = { * set as the tag. */ async getDeploymentImageId(module: ContainerModule, registryConfig?: ContainerRegistryConfig) { - const imageName = await containerHelpers.getDeploymentImageName(module, registryConfig) - - return containerHelpers.unparseImageId({ - repository: imageName, - tag: module.version.versionString, - }) + if (await containerHelpers.hasDockerfile(module)) { + // If building, return the deployment image name, with the current module version. + const imageName = await containerHelpers.getDeploymentImageName(module, registryConfig) + + return containerHelpers.unparseImageId({ + repository: imageName, + tag: module.version.versionString, + }) + } else { + // Otherwise, return the configured image ID. + // Note: This will always be set here, otherwise validation will have failed already. + return module.spec.image! + } }, parseImageId(imageId: string): ParsedImageId { diff --git a/garden-service/test/unit/src/plugins/container.ts b/garden-service/test/unit/src/plugins/container.ts index bb620d80bf..e6c94436ea 100644 --- a/garden-service/test/unit/src/plugins/container.ts +++ b/garden-service/test/unit/src/plugins/container.ts @@ -116,6 +116,37 @@ describe("plugins.container", () => { }) }) + describe("getDeploymentImageId", () => { + it("should return module name with module version if there is a Dockerfile and no image name set", async () => { + const config = cloneDeep(baseConfig) + const module = await getTestModule(config) + + td.replace(containerHelpers, "hasDockerfile", async () => true) + + expect(await containerHelpers.getDeploymentImageId(module)).to.equal("test:1234") + }) + + it("should return image name with module version if there is a Dockerfile and image name is set", async () => { + const config = cloneDeep(baseConfig) + config.spec.image = "some/image:1.1" + const module = await getTestModule(config) + + td.replace(containerHelpers, "hasDockerfile", async () => true) + + expect(await containerHelpers.getDeploymentImageId(module)).to.equal("some/image:1234") + }) + + it("should return configured image tag if there is no Dockerfile", async () => { + const config = cloneDeep(baseConfig) + config.spec.image = "some/image:1.1" + const module = await getTestModule(config) + + td.replace(containerHelpers, "hasDockerfile", async () => false) + + expect(await containerHelpers.getDeploymentImageId(module)).to.equal("some/image:1.1") + }) + }) + describe("getDockerfilePathFromModule", () => { it("should return the absolute default Dockerfile path", async () => { const module = await getTestModule(baseConfig)