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: print default group #720

Merged
merged 1 commit into from Aug 12, 2021
Merged

Conversation

crazy-max
Copy link
Member

Fixes #183

services:
  addon:
    build:
      context: .
      dockerfile: ./Dockerfile
      args:
        CT_ECR: foo
        CT_TAG: bar
    image: ct-addon:bar
    environment:
      - NODE_ENV=test
      - AWS_ACCESS_KEY_ID=dummy
      - AWS_SECRET_ACCESS_KEY=dummy

  aws:
    build:
      dockerfile: ./aws.Dockerfile
      args:
        CT_ECR: foo
        CT_TAG: bar
    image: ct-fake-aws:bar
$ docker buildx bake --print
{
  "group": {
    "default": [
      "aws",
      "addon"
    ]
  },
  "target": {
    "addon": {
      "context": ".",
      "dockerfile": "./Dockerfile",
      "args": {
        "CT_ECR": "foo",
        "CT_TAG": "bar"
      },
      "tags": [
        "ct-addon:bar"
      ]
    },
    "aws": {
      "context": "../../../tools/mock_servers/fake_aws",
      "dockerfile": "./Dockerfile",
      "args": {
        "CT_ECR": "foo",
        "CT_TAG": "bar"
      },
      "tags": [
        "ct-fake-aws:bar"
      ]
    }
  }
}
$ docker buildx bake addon --print
{
  "target": {
    "addon": {
      "context": ".",
      "dockerfile": "./Dockerfile",
      "args": {
        "CT_ECR": "foo",
        "CT_TAG": "bar"
      },
      "tags": [
        "ct-addon:bar"
      ]
    }
  }
}

Signed-off-by: CrazyMax crazy-max@users.noreply.github.com

@tonistiigi
Copy link
Member

I think the point of this should be that the resulting json is usable as a bake file. That means that for buildx bake addon the output should be "default": ["addon"]. Still not quite sure if this should be opt-in (or maybe opt-out) for some cases it is not needed (or when you want to combine the output with another file then this is blocking).

@crazy-max
Copy link
Member Author

crazy-max commented Aug 11, 2021

@tonistiigi

I think the point of this should be that the resulting json is usable as a bake file. That means that for buildx bake addon the output should be "default": ["addon"].

Ok, I changed the behavior to also print the default group if targets are specified.

Still not quite sure if this should be opt-in (or maybe opt-out) for some cases it is not needed (or when you want to combine the output with another file then this is blocking).

I think it's ok even if combined but yes opt-out sgtm.

// docker-bake.hcl
group "default" {
  targets = ["image"]
}

target "image" {
  inherits = ["image"]
  output = ["type=docker"]
}
# docker-compose.yaml
services:
  addon:
    build:
      context: .
      dockerfile: ./Dockerfile
      args:
        CT_ECR: foo
        CT_TAG: bar
    image: ct-addon:bar
    environment:
      - NODE_ENV=test
      - AWS_ACCESS_KEY_ID=dummy
      - AWS_SECRET_ACCESS_KEY=dummy

  aws:
    build:
      dockerfile: ./aws.Dockerfile
      args:
        CT_ECR: foo
        CT_TAG: bar
    image: ct-fake-aws:bar
$ docker buildx bake -f docker-compose.yml -f docker-bake.hcl --print
{
  "group": {
    "default": [
      "image"
    ]
  },
  "target": {
    "image": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "output": [
        "type=docker"
      ]
    }
  }
}
$ docker buildx bake -f docker-compose.yml -f docker-bake.hcl addon --print
{
  "group": {
    "default": [
      "addon"
    ]
  },
  "target": {
    "addon": {
      "context": ".",
      "dockerfile": "./Dockerfile",
      "args": {
        "CT_ECR": "foo",
        "CT_TAG": "bar"
      },
      "tags": [
        "ct-addon:bar"
      ]
    }
  }
}
$ docker buildx bake -f docker-compose.yml -f docker-bake.hcl addon aws --print
{
  "group": {
    "default": [
      "addon",
      "aws"
    ]
  },
  "target": {
    "addon": {
      "context": ".",
      "dockerfile": "./Dockerfile",
      "args": {
        "CT_ECR": "foo",
        "CT_TAG": "bar"
      },
      "tags": [
        "ct-addon:bar"
      ]
    },
    "aws": {
      "context": ".",
      "dockerfile": "./aws.Dockerfile",
      "args": {
        "CT_ECR": "foo",
        "CT_TAG": "bar"
      },
      "tags": [
        "ct-fake-aws:bar"
      ]
    }
  }
}
$ docker buildx bake -f docker-compose.yml -f docker-bake.hcl addon aws image --print
{
  "group": {
    "default": [
      "addon",
      "aws",
      "image"
    ]
  },
  "target": {
    "addon": {
      "context": ".",
      "dockerfile": "./Dockerfile",
      "args": {
        "CT_ECR": "foo",
        "CT_TAG": "bar"
      },
      "tags": [
        "ct-addon:bar"
      ]
    },
    "aws": {
      "context": ".",
      "dockerfile": "./aws.Dockerfile",
      "args": {
        "CT_ECR": "foo",
        "CT_TAG": "bar"
      },
      "tags": [
        "ct-fake-aws:bar"
      ]
    },
    "image": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "output": [
        "type=docker"
      ]
    }
  }
}

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
@crazy-max crazy-max changed the title bake: print default group if none is specified bake: print default group Aug 12, 2021
@tonistiigi tonistiigi merged commit 3594851 into docker:master Aug 12, 2021
@crazy-max crazy-max deleted the default-group branch August 12, 2021 19:26
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.

docker buildx bake --print does not output default targets
2 participants