-
Notifications
You must be signed in to change notification settings - Fork 111
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
Return image name and id from dockerPush and dockerBuildAndPush #117
Return image name and id from dockerPush and dockerBuildAndPush #117
Conversation
The `dockerPush` task now returns the SHA of the image.
`dockerPush` and `dockerBuild` now returns a map with the name and id of the image.
Thanks for the PR! I would like to understand the use case better. |
@marcuslonnberg Hej Markus! Since Not a sbt-docker expert so this is just my understanding how it was supposed to work. |
Ok, I see what you mean, I'll fix that. |
Adding a new class for the return value from 'dockerPush'
If I understand it correctly I think that one could currently use the plugin like this to achieve the same result: myTask := {
val imageId = dockerBuildAndPush.value
val imageNames = (imageNames in docker).value
// usage of imageId and imageNames
...
} |
Here is how I understand it. The image id in docker parlance is the randomly generated ID assigned to images in Docker v1, it's still there and printed when running docker build. The SHA is a digest that is computed based on the image content to be able to verify the content. The docker build function in sbt-docker returns either the image id or the digest, depending on the output. This digest is however not the same digest returned from the push operation. The push operation modifies the image before uploading it. This SHA returned from docker push is the on you later can use to pull the image. The PR also uses a Does that make sense? |
Thanks for the explanation! Now I see what you are out after. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall!
A few comments regarding the digest parsing.
@@ -44,5 +47,20 @@ object DockerPush { | |||
val process = Process(command) | |||
val exitValue = process ! processLog | |||
if (exitValue != 0) sys.error("Failed to push") | |||
|
|||
val PushedImageId = ".* sha256:([0-9a-f]+) .*".r |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it is the image digest that is matched, the name of the constant should reflect that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes!
@@ -44,5 +47,20 @@ object DockerPush { | |||
val process = Process(command) | |||
val exitValue = process ! processLog | |||
if (exitValue != 0) sys.error("Failed to push") | |||
|
|||
val PushedImageId = ".* sha256:([0-9a-f]+) .*".r |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that Docker documentation refers to the digest with sha256:
as a prefix. Shouldn't it therefore be included here in the ImageDigest
output?
Documentation for ImageDigest
should then be updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think so, we can do something like this:
/**
* The image digest, the format of the digest is `algorithm:hex-string`
* @param digest A digest of the image, as a string.
* @param algorithm The algorithm used to produce the digest.
*/
final case class ImageDigest(digest: String, algorithm: String = "sha256") {
override def toString = s"$algorithm:$digest"
}
Co-authored-by: Marcus Lönnberg <github@lonnberg.nu>
val imageId = lines.collect { | ||
case PushedImageDigestSha256(digest) => ImageDigest("sha256", digest) | ||
}.lastOption | ||
|
||
imageId match { | ||
case Some(id) => | ||
imageName -> id | ||
case None => | ||
throw new DockerPushException("Could not parse Docker image id") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block refers to "image id" at some places can we update this to refer to "image digest" instead?
After this it can be merged
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!
@marcuslonnberg Is it possible to cut a new release when merged? We have our own fork now and that is less than ideal ... |
This PR fixes issue #108
In short, the PR changes the return types of
dockerBuildAndPush
anddockerPush
to return aMap[String,ImageId]
instead.This information is very useful for post build/push operations.