buildx icon indicating copy to clipboard operation
buildx copied to clipboard

Bake: Define project name and support COMPOSE_PROJECT_NAME in Yaml

Open ciaranmcnulty opened this issue 3 years ago • 1 comments

The compose spec section about project names says:

[the project name] MUST be exposed for interpolation and environment variable resolution as COMPOSE_PROJECT_NAME

This would be pretty handy for one of my projects (to use as a tagging prefix)

Bake doesn't really have a way to define or compute the project name that I can see (I guess as it's not used for anything?) but it' suffice for me to read it from the name: top level element

name: foo

services:
  myservice:
    build:
      x-bake:
        tags:
          - "${COMPOSE_PROJECT_NAME}"

Would be:

"target": {
    "myservice": {
      "context": ".",
      "dockerfile": "Dockerfile",
      "tags": [
        "foo"
      ]
    }
  }

ciaranmcnulty avatar Jun 12 '22 08:06 ciaranmcnulty

Note that compose doesn't do this correctly yet

ciaranmcnulty avatar Jun 12 '22 08:06 ciaranmcnulty

Is buildx not meant to match the features of docker and compose in order to extend them? I can't seem to get this working via buildx from a Dockerfile: FROM baseimg-${project}:latest AS stage2-app

Because project (in compose build args:) and compose_project_name don't register for buildx. Is there another way to do env var aware multi-layer builds with buildx. I would love to use compose, however I can't because of this: https://github.com/docker/buildx/issues/175 Which suggests the only real work around is using buildx (via sudo docker buildx create --driver-opt network=). It is a game of cat and mouse with build-time networking!

dm17 avatar Apr 21 '23 03:04 dm17