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

Support tag task name for 'tags' #205

Merged
merged 9 commits into from
Jan 7, 2019
Merged

Conversation

devkanro
Copy link
Contributor

@devkanro devkanro commented Oct 17, 2018

Description

This PR make 'tags' more powerful, you can use new 'tag' DSL to give the tag a task name.
There are some samples:

docker {
    name 'fake-service-name'
    tag 'withTaskName', 'fake-service-name:2.0'
    tag 'newImageName', 'new-image:latest'
}

It will generate tag tasks with name dockerTagWithTaskName and dockerTagNewImageName, and push tasks with name dockerPushWithTaskName and dockerPushNewImageName.

With task name, we can build some diff name image of one image, push to diff repo host.

Note

'tags' DSL can resolve the tag name auto, but 'tag' can not. It means you must specify the image name for 'tag' DSL.

There are some sample:
Tag with just new version:
name: old-name:test
tags dsl: tags 'latest'
tag dsl: tag 'latest', 'docker-name:latest'
image result name: docker-name:latest

Tag with new name:
name: old-name:test
tags dsl: tags 'newName@docker-name:latest'
tag dsl: tag 'newName', 'docker-name:latest'
image result name: docker-name:latest

Tag with new repo host:
name: old-name:test
tag: newName@host:port/repo/docker-name:latest
tags: newName', 'host:port/repo/docker-name:latest'
image result name: host:port/repo/docker-name:latest

Note:
Notice that tag must have a task name if you want to replace the repo or image name for 'tags' DSL

New tasks

dockerTagsPush
Pushes all tagged Docker images to configured Docker Hub.

dockerTagsPush= dockerPush<Tag1>+ dockerPush<Tag2> + ... + dockerPush<Tagn>

dockerAllPush
Pushes all tagged Docker images and named Docker image to configured Docker Hub.

dockerAllPush = dockerTagsPush + dockerPush

Solved issues

#195 Allow dockerPush to target multiple repositories
Use dockerPush<Tag> to diff repositories

docker {
    name 'repository1.foo.com/bar:lastest'
    tag 'repository2', 'repository2.foo.com/bar:lastest'
}

Run this command:

./gradle dockerPushRepository2

#181 Pushing just the defined tags
Use dockerTagsPush task can solve this issue

docker {
    name 'repository1.foo.com/bar:lastest'
    tag 'tag1', 'bar:v1'
    tag 'tag2', 'bar:v2'
}

Run this command:

./gradle dockerTagsPush

#95 Make push task depend on push tasks for each tag if tags are present
Use dockerTagsPush and dockerPush can solve this issue/PR without change behavior of dockerPush

docker {
    name 'repository1.foo.com/bar:lastest'
    tag 'tag1', 'bar:v1'
    tag 'tag2', 'bar:v2'
}

Run this command:

./gradle dockerPush
./gradle dockerTagsPush

#149 dockerPush doesn't generate (and thus push) all Tags
#94 Ability to easily push all tags for an image
#209 Docker tag should support full retagging

Test sample

There are some sample which used in test:

name tag result
v1 latest v1:latest
v1:1 latest v1:latest
host/v1 latest host/v1:latest
host/v1:1 latest host/v1:latest
host:port/v1 latest host:port/v1:latest
host:port/v1:1 latest host:port/v1:latest
v1 name@latest v1:latest
v1:1 name@latest v1:latest
host/v1 name@latest host/v1:latest
host/v1:1 name@latest host/v1:latest
host:port/v1 name@latest host:port/v1:latest
host:port/v1:1 name@latest host:port/v1:latest
v1 name@v2:latest v2:latest
v1:1 name@v2:latest v2:latest
host/v1 name@v2:latest v2:latest
host/v1:1 name@v2:latest v2:latest
host:port/v1 name@v2:latest v2:latest
host:port/v1:1 name@v2:latest v2:latest
v1 name@host/v2 host/v2
v1:1 name@host/v2 host/v2
host/v1 name@host/v2 host/v2
host/v1:1 name@host/v2 host/v2
host:port/v1 name@host/v2 host/v2
host:port/v1:1 name@host/v2 host/v2
v1 name@host/v2:2 host/v2:2
v1:1 name@host/v2:2 host/v2:2
host/v1 name@host/v2:2 host/v2:2
host/v1:1 name@host/v2:2 host/v2:2
host:port/v1 name@host/v2:2 host/v2:2
host:port/v1:1 name@host/v2:2 host/v2:2
v1 name@host:port/v2:2 host:port/v2:2
v1:1 name@host:port/v2:2 host:port/v2:2
host/v1 name@host:port/v2:2 host:port/v2:2
host/v1:1 name@host:port/v2:2 host:port/v2:2
host:port/v1 name@host:port/v2:2 host:port/v2:2
host:port/v1:1 name@host:port/v2:2 host:port/v2:2

@devkanro devkanro requested a review from a team as a code owner October 17, 2018 12:04
@palantirtech
Copy link
Member

Thanks for your interest in palantir/gradle-docker, @higankanshi! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request.

@devkanro
Copy link
Contributor Author

devkanro commented Oct 30, 2018

Any update here? @pkoenig10
Not just me, there are still many people who really need this feature.

@devkanro
Copy link
Contributor Author

devkanro commented Dec 21, 2018

@uschi2000 @pkoenig10
Could you review this PR? I really need this feature.
if it still no reply for me, I have to publish my fork to plugin repositories.

@uschi2000
Copy link
Contributor

Hej @higankanshi , sorry this slipped through the cracks. I'll take a look now.

@devkanro
Copy link
Contributor Author

@uschi2000 Thanks for your time.

@uschi2000
Copy link
Contributor

Thinking about this change a bit, I wonder if we should take a harder break and rectify some of the config birth defects, in particular the asymmetry between image name and image tags. Should they really be the same thing, and thus naturally allow for multiple hosts etc?
Something like

docker {
  imageName repo:port/foo:1.0
  imageName otherRepo/foo:latest, myTaskName
  ..
}

My rationale is that while your proposed is clearly something we should do (in order to fix all those issues), the implementation makes the config language pretty complicated (as witnessed by constraints like Notice that tag must have a task name if you want replace the repo or image name).

Thoughts?

@devkanro
Copy link
Contributor Author

devkanro commented Dec 22, 2018

@uschi2000
We can use the tag command of docker to set repo host for docker, like this:

docker tag httpd fedora/httpd:version1.0
docker tag httpd:test fedora/httpd:version1.0.test

So, i think that tag can be include a repo host, new image name.
But use the @ for marking task name, I think it can be more better, like your example

docker {
  tag 'repo:port/foo:1.0' // Invalid tag, because we can get a valid name for this tag
  tag 'foo:latest' // Maybe can make a dockerFooLatest task ?
  tag 'latest' // Maybe we should not support version only for defined a tag
  tag 'otherRepo/foo:latest', myTaskName // Good, a custom name
}

But if we do this, it would be a breaking change for this plugin...
We should seriously weigh for it.

Using @ for backward compatible
or
Using new dsl for better semantics

@pkoenig10
Copy link
Member

I agree with @uschi2000.

It's seems odd to me that tag in this plugin is interpreted differently than arguments to the docker tag. Namely, we try to merge the name and the tag fields to compute an argument for docker tag.

I think we still need the name field to provide a primary identifier for the created image that can be used by other tasks. But the name and tag fields would be interpreted identically. The only difference being that the name tag is applied at build time, while the tag tags are applied in a separate task.

Providing custom task names seems like a step in the right direction, since it seems hopeless for us to try and derive task names if given tags which may or may not contain a registry, repository, image name, and/or tag.

@devkanro
Copy link
Contributor Author

devkanro commented Dec 23, 2018

@pkoenig10
Yes, you are right.

How do you think about using @ for marking task name?
I am using this for backward compatible, you do not have to change your existing config for this change.

@uschi2000
Copy link
Contributor

@pkoenig10 if you want to do the DSL break, then we'd also have to think about excavating our internal repos to get them towards the new config. should be relatively simple, but just flagging.

@pkoenig10
Copy link
Member

Ideally I'd like to avoid a DSL break here. Using @ for marking task name seems like a reasonable approach. This should be safe since @ cannot be used in tag names.

It looks like the primary blocker to supporting the better DSL is the tags method that takes a variable number of tags. Maybe as part of this change we should also deprecate this method.

Eventually it would be good to push everyone to the better DSL. This probably will take a couple of steps:

  1. Support using @ for marking task names and deprecated the varargs tags method
  2. [break] Remove the varargs tags method, replace it with a two arg (tag, taskName) tags method

And then optionally, to remove custom syntax from this plugin:
3. [break] Remove support for using @ to mark task names. This break will fail loudly since @ cannot be used in tag names.

@devkanro
Copy link
Contributor Author

OK, got it, I will change my PR later

@devkanro
Copy link
Contributor Author

devkanro commented Dec 28, 2018

@uschi2000 @pkoenig10
I have added the 'tag' DSL and marked the 'tags' DSL as deprecated.

docker {
  tag 'newTag', 'repo:port/foo:1.0' 
}

However, it doesn't resolve image name for the tag. If you want to retag the version, you must specify the image name too.
This limit due to the design of docker's tag command, it just makes them as same.

docker {
  tag 'latest', 'latest'  // Invalid tag, it must be "tag 'latest', 'name:latest' "
}

Copy link
Member

@pkoenig10 pkoenig10 left a comment

Choose a reason for hiding this comment

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

Design looks good, couple of implementation comments

Copy link
Member

@pkoenig10 pkoenig10 left a comment

Choose a reason for hiding this comment

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

LGTM, couple of minor comments

readme.md Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
readme.md Outdated Show resolved Hide resolved
@devkanro
Copy link
Contributor Author

devkanro commented Jan 4, 2019

Fixed

@pkoenig10 pkoenig10 merged commit 64853c1 into palantir:develop Jan 7, 2019
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.

None yet

4 participants