Skip to content

Commit

Permalink
fix(container): respect include field when checking for Dockerfile
Browse files Browse the repository at this point in the history
Previously, when using multiple container modules in one garden.yml,
it would be impossible to have one of them use a remote image if any
of the others had a Dockerfile in the same directory.
  • Loading branch information
edvald committed Jul 23, 2019
1 parent 61bf65f commit 0df7a8d
Show file tree
Hide file tree
Showing 5 changed files with 1,082 additions and 986 deletions.
17 changes: 7 additions & 10 deletions garden-service/src/plugins/container/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { pathExists } from "fs-extra"
import { join } from "path"
import * as semver from "semver"
import { ConfigurationError, RuntimeError } from "../../exceptions"
Expand All @@ -23,13 +22,6 @@ interface ParsedImageId {
tag?: string
}

function getDockerfilePath(basePath: string, dockerfile?: string) {
if (dockerfile) {
return join(basePath, dockerfile)
}
return join(basePath, "Dockerfile")
}

// TODO: This is done to make it easy to stub when testing.
// We should come up with a better way than exporting this object.
const helpers = {
Expand Down Expand Up @@ -271,10 +263,11 @@ const helpers = {
}
},

async hasDockerfile(moduleConfig: ContainerModuleConfig) {
async hasDockerfile(module: ContainerModule): Promise<Boolean> {
// If we explicitly set a Dockerfile, we take that to mean you want it to be built.
// If the file turns out to be missing, this will come up in the build handler.
return moduleConfig.spec.dockerfile || pathExists(helpers.getDockerfileSourcePath(moduleConfig))
const dockerfileSourcePath = helpers.getDockerfileSourcePath(module)
return !!module.spec.dockerfile || module.version.files.includes(dockerfileSourcePath)
},

getDockerfileBuildPath(module: ContainerModule) {
Expand All @@ -292,3 +285,7 @@ export const containerHelpers = helpers
function fixDockerVersionString(v: string) {
return semver.coerce(v.replace(/\.0([\d]+)/g, ".$1"))!
}

function getDockerfilePath(basePath: string, dockerfile = "Dockerfile") {
return join(basePath, dockerfile)
}
7 changes: 0 additions & 7 deletions garden-service/src/plugins/maven-container/maven-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,6 @@ export async function configureMavenContainerModule(params: ConfigureModuleParam

const configured = await configureContainerModule({ ...params, moduleConfig: containerConfig })

const hasOwnDockerfile = await containerHelpers.hasDockerfile(moduleConfig)

if (!hasOwnDockerfile) {
// Set the default Dockerfile provided by the plugin
configured.spec.dockerfile = "maven-container.Dockerfile"
}

return {
...configured,
spec: {
Expand Down
Loading

0 comments on commit 0df7a8d

Please sign in to comment.