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: fix output handling for push #2330

Merged
merged 1 commit into from
Mar 12, 2024

Conversation

crazy-max
Copy link
Member

@crazy-max crazy-max commented Mar 10, 2024

fixes #2325

This is a regression from #2302 where override for --push was changed to *.output=type=registry but should be kept with *.push=true as there is a special handling to only set push=true if type=image or type=registry is already defined for a target. This PR puts back this behavior.

The --load case is also not properly handled in v0.13.0 as it doesn't append but overrides the outputs (was the same in v0.12). For backward compat, we can keep this behavior for this patch but in follow-up we should handle --load the same way as --push.

Here is the repro:

target "foo" {
  output = [ "type=local,dest=out" ]
}

target "bar" {
}

v0.12

$ docker buildx bake --push --print foo bar
Output
{
  "group": {
    "default": {
      "targets": [
        "foo",
        "bar"
      ]
    }
  },
  "target": {
    "bar": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "output": [
        "type=image,push=true"
      ]
    },
    "foo": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "output": [
        "type=local,dest=out"
      ]
    }
  }
}
$ docker buildx bake --load --print foo bar
Output
{
  "group": {
    "default": {
      "targets": [
        "foo",
        "bar"
      ]
    }
  },
  "target": {
    "bar": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "output": [
        "type=docker"
      ]
    },
    "foo": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "output": [
        "type=docker"
      ]
    }
  }
}
$ docker buildx bake --push --load --print foo bar
ERROR: push and load may not be set together at the moment

With this PR

$ docker buildx bake --push --print foo bar
Output
{
  "group": {
    "default": {
      "targets": [
        "foo",
        "bar"
      ]
    }
  },
  "target": {
    "bar": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "output": [
        "type=image,push=true"
      ]
    },
    "foo": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "output": [
        "type=local,dest=out"
      ]
    }
  }
}
$ docker buildx bake --load --print foo bar
Output
{
  "group": {
    "default": {
      "targets": [
        "foo",
        "bar"
      ]
    }
  },
  "target": {
    "bar": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "output": [
        "type=docker"
      ]
    },
    "foo": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "output": [
        "type=docker"
      ]
    }
  }
}
$ docker buildx bake --push --load --print foo bar
Output
{
  "group": {
    "default": {
      "targets": [
        "foo",
        "bar"
      ]
    }
  },
  "target": {
    "bar": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "output": [
        "type=docker"
      ]
    },
    "foo": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "output": [
        "type=docker"
      ]
    }
  }
}

@crazy-max crazy-max added this to the v0.13.1 milestone Mar 10, 2024
@crazy-max crazy-max marked this pull request as ready for review March 11, 2024 08:01
@davhdavh
Copy link

Thanks for the quick fixing

@crazy-max crazy-max force-pushed the fix-bake-load-push branch 3 times, most recently from 5af9738 to 6538d50 Compare March 12, 2024 12:10
@crazy-max crazy-max changed the title bake: fix output handling for push and load bake: fix output handling for push Mar 12, 2024
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
}`),
}
ctx = context.TODO()
m, _, err = ReadTargets(ctx, []File{fp}, []string{"foo", "bar"}, []string{"*.push=true"}, nil)
Copy link
Member

Choose a reason for hiding this comment

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

Do we have a similar test already for load ? Or was the behavior different as I can see it uses type=docker

Copy link
Member Author

@crazy-max crazy-max Mar 12, 2024

Choose a reason for hiding this comment

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

We don't currently have a *.load override with bake so either v0.12, v0.13 overrides the outputs atm. See me note in PR description about --load case with bake. I can open a PR with this enhancement so we have a consistent behavior with build. This was my previous attempt, see 5af9738 but would not be backward compat unfortunately.

@tonistiigi tonistiigi merged commit df4b133 into docker:master Mar 12, 2024
63 checks passed
@crazy-max crazy-max deleted the fix-bake-load-push branch March 12, 2024 16:42
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.

[0.13] bake: changed behavior in output configuration
3 participants