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

Docker exporter - specify multiple tags during build #797

Closed
opopops opened this issue Jan 24, 2019 · 21 comments · Fixed by #889
Closed

Docker exporter - specify multiple tags during build #797

opopops opened this issue Jan 24, 2019 · 21 comments · Fixed by #889

Comments

@opopops
Copy link

opopops commented Jan 24, 2019

Hi,

Is it possible to specify more than one name during docker build like docker cli does:

docker build -t name:tag1 -t name:tag2

@tonistiigi
Copy link
Member

It's not available atm but should be easy to add if there is a need.

@FernandoMiguel
Copy link
Collaborator

I have the occasional need for this.
Saves me doing tag afterwards.

@hpandeycodeit
Copy link
Contributor

@tonistiigi I would like to work on this request. Where should I be starting with this? any pointers?

@tonistiigi
Copy link
Member

The image exporter supports multiple names with a comma separated list, added in #561. @hpandeycodeit You could add the same support to oci exporter (docker and oci variant share the implementation). Split the name into an array like in #561 , and modify https://github.com/moby/buildkit/blob/master/exporter/oci/export.go#L198 to take an array of names instead of a single one.

@thaJeztah
Copy link
Member

@tonistiigi wondering; will it be possible to specify multiple targets? (Think I wrote a proposal for that somewhere); ie, tag multiple targets (stages)?

@tonistiigi
Copy link
Member

@thaJeztah No, multiple builds for multiple targets. This issue is about tags.

@anthonyraymond
Copy link

I'd like that too

@sethpollack
Copy link

@tonistiigi What is the correct syntax for this? I tried:

--output type=image,name=username/image:tag1,username/image:tag2

And I get:

error: invalid value username/image:tag2

@AkihiroSuda
Copy link
Member

Probably you need to quote the string

@sethpollack
Copy link

No that doesn't help, seems like this only works with the old --exporter syntax.

@AkihiroSuda AkihiroSuda reopened this Jan 6, 2020
@sethpollack
Copy link

I think the issue is that --output uses a csv reader

csvReader := csv.NewReader(strings.NewReader(s))

@tonistiigi
Copy link
Member

Because of the csv reader you need to quote the values with commas and make sure your shell does not interpret them.

@thaJeztah
Copy link
Member

^^ for the CSV, the quotes should be around the names=xx,xx,xx because that's a single "field" in the CSV, so;

--output type=image,"name=username/image:tag1,username/image:tag2"

(possibly with escaping the quote if needed to take the shell into account, as mentioned above)

@jauninb
Copy link

jauninb commented Feb 3, 2020

@thaJeztah @tonistiigi I am facing the same issue that @sethpollack have.
It works using the deprecated --exporter-opt but not using --output
Do you have a working example ?

@giulioprovasi
Copy link

I found out that the right syntax (in master branch) is the following:

--output type=image,name=username/image:tag1,name=username/image:tag2,push=true

@voron
Copy link

voron commented May 3, 2020

@giulioprovasi 2'nd name just overrides 1'st name, this is not what we need.

--output type=image,"name=username/image:tag1,username/image:tag2"

as specified by @thaJeztah, works for me as expected. I have to escape quotes as mentioned, my Gitlab-CI script part is following

--output type=image,\"name=$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA,$CI_REGISTRY_IMAGE:${IMG_TAG}\",push=true

@cheald
Copy link

cheald commented Feb 6, 2022

This doesn't seem to work any longer, using:

--output type=image,name=\"registry.local/project:test,registry.local/project:test2\",push=true

I get "error: parse error on line 1, column 16: bare " in non-quoted-field"

Using:

--output type=image,name="registry.local/project:test,registry.local/project:test2",push=true

I get "error: invalid value registry.local/project:test"

What's the right way to do this now?

@tonistiigi
Copy link
Member

Your quotes are in the wrong place. \"name=foo,bar\"

@cmdjulian
Copy link
Contributor

cmdjulian commented May 22, 2023

I have the same error and I don't get why.

export OUTPUT=$(printf 'type=image,\"name=%s\",buildinfo-attrs=true,push=%s' "$IMAGES" "$PUSH")
buildctl-daemonless.sh build \
      --progress=plain \
      --frontend="$DOCKER_FRONTEND" \
      --opt "filename=$DOCKERFILE_PATH" \
      --local "context=$DOCKER_CONTEXT" \
      --local "dockerfile=$DOCKERFILE_DIR" \
      --output $OUTPUT \
      $BUILDKIT_ARGS

error: parse error on line 1, column 13: bare " in non-quoted-field

Any ideas?

echo $OUTPUT

# returns
type=image,\"name=registry.gitlab.com/foo:latest,registry.gitlab.com/bar:latest\",buildinfo-attrs=true,push=true

this works:

--output type=image,\"name=$IMAGES\",buildinfo-attrs=true,push=$PUSH

@devmittal02
Copy link

@cmdjulian were you able to fix the above issue?

@cmdjulian
Copy link
Contributor

Yes I did:

export OUTPUT='type=image,"name='"$IMAGES"'",buildinfo-attrs=true,push='"$PUSH"

This works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.