Skip to content

Commit

Permalink
fix(docker): requiring docker >20 for --build-context support (#207)
Browse files Browse the repository at this point in the history
* fix(docker): requiring docker >20 for --build-context support

looks like even if buildx is installed in older docker versions,
--build-context arg is not supported

cant find release docs for this doc so just going by local version
experiments

* fix: wrong space in COPY --chmod docker statement
  • Loading branch information
miki725 authored Feb 19, 2024
1 parent 99bdc08 commit cb4f3bf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 5 additions & 7 deletions src/docker_base.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand All @@ -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" &
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cb4f3bf

Please sign in to comment.