diff --git a/CHANGELOG.md b/CHANGELOG.md index d84aa402..0e27e1ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,9 @@ As a result other commands such as `exec` do not interact with the backup service. [#191](https://github.com/crashappsec/chalk/pull/191) +- Fixing docker build attempting to use `--build-context` + on older docker versions which did not support that flag. + [#207](https://github.com/crashappsec/chalk/pull/207) ## 0.3.2 diff --git a/src/docker_base.nim b/src/docker_base.nim index 1a6361bd..4bb3de52 100644 --- a/src/docker_base.nim +++ b/src/docker_base.nim @@ -101,7 +101,7 @@ template hasBuildx*(): bool = template supportsBuildContextFlag*(): bool = # https://github.com/docker/buildx/releases/tag/v0.8.0 - getBuildXVersion() >= parseVersion("0.8") + getDockerVersion() >= parseVersion("21") and getBuildXVersion() >= parseVersion("0.8") template supportsCopyChmod*(): bool = # > the --chmod option requires BuildKit. @@ -149,6 +149,8 @@ proc makeFileAvailableToDocker*(ctx: DockerInvocation, if hasUser and chmod == "": chmod = "0444" + let chmodstr = if chmod == "": "" else: "--chmod=" & chmod & " " + if move: trace("Making file available to docker via move: " & loc) else: @@ -158,10 +160,6 @@ proc makeFileAvailableToDocker*(ctx: DockerInvocation, once: trace("Docker injection method: --build-context") - var chmodstr = "" - if chmod != "": - chmodstr = "--chmod=" & chmod & " " - ctx.newCmdLine.add("--build-context") ctx.newCmdLine.add("chalkexedir" & $(contextCounter) & "=" & dir & "") ctx.addedInstructions.add("COPY " & chmodstr & "--from=chalkexedir" & @@ -198,8 +196,8 @@ proc makeFileAvailableToDocker*(ctx: DockerInvocation, copyFile(loc, dstLoc) trace("Copied " & loc & " to " & dstLoc) - if chmod != "" and supportsCopyChmod(): - ctx.addedInstructions.add("COPY --chmod= " & chmod & + if chmodstr != "" and supportsCopyChmod(): + ctx.addedInstructions.add("COPY " & chmodstr & file & " " & " /" & newname) elif chmod != "": # TODO detect user from base image if possible but thats not