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 creation of Docker tags #654

Closed
az82 opened this issue Jul 18, 2018 · 10 comments
Closed

Support creation of Docker tags #654

az82 opened this issue Jul 18, 2018 · 10 comments

Comments

@az82
Copy link

az82 commented Jul 18, 2018

Description of the issue:
The Jib Gradle/Maven plugins should support the creation of Docker tags without building a new image. This is important for promotion workflows where an image gains new tags while being promoted through the stages.

Expected behavior:

Something like the command below creates a tag in the repository repo:

gradle jibTag --source "repo/img:$GIT_COMMIT" --target "repo/img:$GIT_TAG"
@chanseokoh
Copy link
Member

Thanks for the feedback.

Tags are just human-readable aliases for an image. Your image already exists in your repository, so it is just a matter of attaching another tag (alias) to your image in the repository. That said, although Jib could potentially add this feature, I feel this fairly trivial operation is actually out of scope of Jib and should be done at the repository side. For example, https://cloud.google.com/container-registry/docs/managing#tagging_images and https://docs.aws.amazon.com/AmazonECR/latest/userguide/retag-aws-cli.html.

@az82
Copy link
Author

az82 commented Jul 18, 2018

True indeed - The point would be to decrease the number of tools required to build and therefore make Jib more attractive. If this would be supported, more people could do without Docker, Gcloud or whatever in the build.

@coollog
Copy link
Contributor

coollog commented Jul 18, 2018

Hi @az82 , in Jib, you can actually push the same image with a different tag (just change the to.image field, or create profiles to use multiple tags). Even though it might seem like Jib is building a new image - it skips all the actual building and just creates a new manifest for the new tag. This is a benefit we get from the reproducibility aspect of Jib, where the image layers that were pushed in the first tag would get reused by the new tags.

@chanseokoh
Copy link
Member

@coollog that's a good point I missed.

@az82 so I believe you can call gradle jib --image=<MY IMAGE>, which will cover your use case nicely. I'll close this issue. Feel free to re-open if it doesn't work as you expected.

@gluehbirnenkopf
Copy link

I still see the point of delivering an image which was already built to Registry X, retag it and then push it to Registry Y.

I really went through a lot of docs now and it seems that jib only supports multiple tagging during the gradle build.

But in my case the build container which runs in kubernetes is just a temporary provisioned gradle Deamon. So let’s say t some stage my snapshot image from development needs to be tagged and delivered to some Registry Y, it’s simply not possible.

@chanseokoh
Copy link
Member

Hi @gluehbirnenkopf,

I still see the point of delivering an image which was already built to Registry X, retag it and then push it to Registry Y.

at some stage my snapshot image from development needs to be tagged and delivered to some Registry Y

Sorry, I didn't get it. Are you saying there is an already built and published image in Registry X and you simply want to "copy" that image to Registry Y, without running Gradle or Jib? Are you basically suggesting a separate CLI tool that'll do the copy?

@gluehbirnenkopf
Copy link

@chanseokoh
Yes, I "just" want to copy an image from registry X to registry Y, but also giving it a new version tag.
The Problem is that I cant simply run a second time jib, as the build infrastructure is dynamically provisioned for every CI build job. Which means JIB would always build new sources.

Example:
Image "registry-x.com/repo/app1:v1-snapshot" gets built with jib in CI to registry-x.
Image "registry-x.com/repo/app1:v1-snapshot" is then at some point of time deployed and tested. If this test is successfull it needs to be marked as a release version and needs to be delivered to the registry Y.

@gluehbirnenkopf
Copy link

If there would be a way to achieve this with jib, perfect! Otherwise I need to look in different toolings.

@coollog
Copy link
Contributor

coollog commented Feb 27, 2019

Hi @gluehbirnenkopf , this seems like a use case that is outside the scope of Jib, since Jib is intended to be just a container builder for Java.

For a standalone tool to copy remote images, I would recommend crane.

If you'd like to copy an image as part of your Gradle build, you could use Jib Core:

// Imports Jib Core as a library to use in this build script.
buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath 'com.google.cloud.tools:jib-core:0.1.1'
  }
}

import com.google.cloud.tools.jib.api.Jib
import com.google.cloud.tools.jib.api.Containerizer
import com.google.cloud.tools.jib.api.RegistryImage
import com.google.cloud.tools.jib.frontend.CredentialRetrieverFactory
import com.google.cloud.tools.jib.image.ImageReference

// 'jibcopy' copies a container image from `sourceImage` to `targetImage`.
task('jibcopy') {
  doLast { 
    def sourceImage = '<source image reference>'
    def targetImage = '<target image reference>'
    Jib
        // Starts with the existing image.
        .from(sourceImage)
        // Performs the containerization.
        .containerize(
            Containerizer.to(
                // Tells Jib to containerize to targetImage's registry. 
                RegistryImage
                    .named(targetImage)
                    // Tells Jib to get registry credentials from a Docker config.
                    .addCredentialRetriever(
                        CredentialRetrieverFactory
                            .forImage(ImageReference.parse(targetImage))
                            .dockerConfig())))
  }
}

@gluehbirnenkopf
Copy link

@coollog This is valueable input. I will dive into jib core right after checking crane.
I really like JIB and therefore would like to go with it.

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

No branches or pull requests

4 participants