Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bake: allow BAKE_CMD_CONTEXT builtin var #671

Merged
merged 1 commit into from
Jul 13, 2021

Conversation

tonistiigi
Copy link
Member

fix #641

Allows accessing the main context for bake command from bake
file that has been imported remotely.

# docker buildx bake "git://github.com/docker/cli" --print
{
  "target": {
    "binary": {
      "context": "git:/github.com/docker/cli",
      "dockerfile": "Dockerfile",
      "args": {
        "BASE_VARIANT": "alpine",
        "GO_STRIP": "",
        "VERSION": ""
      },
      "target": "binary",
      "platforms": [
        "local"
      ],
      "output": [
        "build"
      ]
    }
  }
}

/tmp/a # touch foo bar
/tmp/a # docker buildx bake "git://github.com/tonistiigi/buildx#remote-test"
...
 > [4/4] RUN ls -l && stop:
#9 0.207 total 0
#9 0.207 -rw-r--r--    1 root     root             0 Jul 13 03:39 bar
#9 0.207 -rw-r--r--    1 root     root             0 Jul 13 03:39 foo
#9 0.207 /bin/sh: stop: not found


 # docker buildx bake "git://github.com/tonistiigi/buildx#remote-test" "git://github.com/docker/cli"
...
#8 0.232 -rw-r--r--    1 root     root          1893 Jul 13 03:58 poule.yml
#8 0.232 drwxr-xr-x    7 root     root          4096 Jul 13 03:58 scripts
#8 0.232 drwxr-xr-x    3 root     root          4096 Jul 13 03:58 service
#8 0.232 drwxr-xr-x    2 root     root          4096 Jul 13 03:58 templates
#8 0.232 drwxr-xr-x   11 root     root          4096 Jul 13 03:58 vendor
#8 0.232 -rwxr-xr-x    1 root     root         10123 Jul 13 03:58 vendor.conf
#8 0.232 /bin/sh: stop: not found

#   docker buildx bake "git://github.com/tonistiigi/buildx#remote-test" "https://ftp.gnu.org/gnu/binutils/binutils-2.36.tar.gz"
...
 > [4/4] RUN ls -l && stop:
#8 0.250 total 4
#8 0.251 drwxrwxrwx   19 root     root          4096 Jul 13 04:00 binutils-2.36
#8 0.251 /bin/sh: stop: not found

Signed-off-by: Tonis Tiigi tonistiigi@gmail.com

Allows accessing the main context for bake command from bake
file that has been imported remotely.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
@tonistiigi
Copy link
Member Author

This also fixed the issue where remote URLs were used in bake targets. Previously the values always passed path.Clean that corrupted the url.

Copy link
Member

@crazy-max crazy-max left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tonistiigi LGTM. In a follow-up, we could reserve variables starting with BAKE_ as we discussed.

@tonistiigi tonistiigi merged commit 6e3a319 into docker:master Jul 13, 2021
@@ -526,6 +527,12 @@ func updateContext(t *build.Inputs, inp *Input) {
t.ContextPath = inp.URL
return
}
if strings.HasPrefix(t.ContextPath, "cwd://") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document cwd protocol

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it is a good idea. I don't want users to write it in the bake file. If they do then they break the remote URL case. They should use the variable and this should be the internal behavior of the variable. We should be able to change that to workdir:// for example and no old files should be broken.

We should document the builtin var, and also more docs for vars/attrs in general.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they break the remote URL

Ah yes right

We should document the builtin var, and also more docs for vars/attrs in general.

👍

@crazy-max crazy-max mentioned this pull request Jul 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bake: local context not supported with remote git bake definition
2 participants