Skip to content

Commit

Permalink
fix(container): wrong image ID when deploying external image locally
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed Mar 22, 2019
1 parent 9c19132 commit a12682c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
19 changes: 13 additions & 6 deletions garden-service/src/plugins/container/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
31 changes: 31 additions & 0 deletions garden-service/test/unit/src/plugins/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a12682c

Please sign in to comment.