diff --git a/garden-service/src/plugins/container/helpers.ts b/garden-service/src/plugins/container/helpers.ts index 0bcafac786..7d313d3b57 100644 --- a/garden-service/src/plugins/container/helpers.ts +++ b/garden-service/src/plugins/container/helpers.ts @@ -10,7 +10,7 @@ import { pathExists } from "fs-extra" import { join } from "path" import * as semver from "semver" import { ConfigurationError, RuntimeError } from "../../exceptions" -import { splitFirst, spawn } from "../../util/util" +import { splitFirst, spawn, splitLast } from "../../util/util" import { ModuleConfig } from "../../config/module" import { ContainerModule, ContainerRegistryConfig, defaultTag, defaultNamespace, ContainerModuleConfig } from "./config" @@ -127,7 +127,13 @@ const helpers = { }, parseImageId(imageId: string): ParsedImageId { - let [name, tag] = imageId.split(":") + let [name, tag] = splitLast(imageId, ":") + + if (name === "") { + name = tag + tag = defaultTag + } + const parts = name.length > 0 ? name.split("/") : [] if (!tag) { diff --git a/garden-service/test/unit/src/plugins/container.ts b/garden-service/test/unit/src/plugins/container.ts index 068fc4bd0f..292032bbc8 100644 --- a/garden-service/test/unit/src/plugins/container.ts +++ b/garden-service/test/unit/src/plugins/container.ts @@ -283,6 +283,15 @@ describe("plugins.container", () => { }) }) + it("should correctly parse an id with a host with a port, and namespace", () => { + expect(helpers.parseImageId("localhost:5000/namespace/image:tag")).to.eql({ + host: "localhost:5000", + namespace: "namespace", + repository: "image", + tag: "tag", + }) + }) + it("should correctly parse an id with a host and multi-level namespace", () => { expect(helpers.parseImageId("my-host.com/a/b/c/d/image:tag")).to.eql({ host: "my-host.com", diff --git a/garden-service/test/unit/src/util/util.ts b/garden-service/test/unit/src/util/util.ts index 0712831a39..f6c3f555a7 100644 --- a/garden-service/test/unit/src/util/util.ts +++ b/garden-service/test/unit/src/util/util.ts @@ -4,8 +4,10 @@ import { getEnvVarName, deepOmitUndefined, deepFilter, + splitLast, } from "../../../../src/util/util" import { expectError } from "../../../helpers" +import { splitFirst } from "../../../../src/util/util" describe("util", () => { describe("getEnvVarName", () => { @@ -118,4 +120,24 @@ describe("util", () => { expect(deepOmitUndefined(obj)).to.eql({ a: 1, b: 2, c: [{ d: 3 }] }) }) }) + + describe("splitFirst", () => { + it("should split string on first occurrence of given delimiter", () => { + expect(splitFirst("foo:bar:boo", ":")).to.eql(["foo", "bar:boo"]) + }) + + it("should return the whole string as first element when no delimiter is found in string", () => { + expect(splitFirst("foo", ":")).to.eql(["foo", ""]) + }) + }) + + describe("splitLast", () => { + it("should split string on last occurrence of given delimiter", () => { + expect(splitLast("foo:bar:boo", ":")).to.eql(["foo:bar", "boo"]) + }) + + it("should return the whole string as last element when no delimiter is found in string", () => { + expect(splitLast("foo", ":")).to.eql(["", "foo"]) + }) + }) })