Schedule a FREE onboarding and start making pipelines fast.

Deploying to Artifactory/Bintray from Codefresh pipelines

Docker Tutorial | December 6, 2018

JFrog Artifactory is one of the leading repository management solutions. Originally a generic package management solution, it has now expanded to cover Docker images as well.

JFrog is also the company behind Bintray, the SAAS version of Artifactory offering the same storage capabilities in the Cloud. In this article, we will see how we can push Docker images and binary artifacts in Bintray. Artifactory can also be used in a similar manner for companies that prefer an on-premise JFrog installation.

Codefresh has native support for external Docker registries and it is very easy to connect JFrog Bintray as a compatible Docker registry in Codefresh pipelines. Once that is done, pushing and pulling Docker images from Bintray is no different than any other Docker registry (Bintray follows closely the Docker registry specification).

The big advantage of Artifactory/Bintray is that unlike other Docker registries they can still be used as repositories for any kind of binary artifacts. Therefore in the second part of this article,
we will see the usage of Bintray as a binary package manager, by pushing and pulling binary artifacts instead of Docker images.

Integrating Bintray as a Docker registry in Codefresh

Codefresh comes with native support for using JFrog Bintray as a Docker registry. Setting up Bintray in Codefresh is a two-step process:

  1. Finding the API key for Bintray for your account
  2. Using the API key in the Docker registry configuration in Codefresh

To find your API key, log-in to Bintray and edit your profile. On the left sidebar choose API key. Click “show” and copy the key down. (You might need to enter your Bintray password a second time.)

Finding your Bintray API key
Finding your Bintray API key

You will also need to get the registry domain. Go to your Docker repository inside Bintray and click the set-me-up button:

Finding your Docker repository
Finding your Docker repository

Then note down the repository name:

Finding your Docker registry domain URL
Finding your Docker registry domain URL

If you don’t have already a Docker repository in Bintray you can create a new one by choosing the “Docker” repository type during creation.

Creating a Docker registry in Bintray
Creating a Docker registry in Bintray

With the Bintray API key and repository domain at hand, go to your account Settings in Codefresh and select the Docker registry Integrations.

Connecting Bintray to your Codefresh account
Connecting Bintray to your Codefresh account

Click the “Add registry” button and select “JFrog Bintray” from the drop-down menu. Then fill in the following fields:

  • Registry name (you can use any name you like, unique for all registries in Codefresh)
  • Your Bintray username
  • Your API key
  • The domain of the Bintray repository.

Once everything is filled, click the “Test” button to verify the settings and then the “Save” button to apply all changes. Bintray is now set up in Codefresh!

Pushing Docker images to Bintray from a Codefresh pipeline

With the Bintray integration ready you can now easily push images from any graphic or YAML pipeline using only the name of the registry. For example, if you are just starting out with Codefresh and use the graphical pipeline creator, you can now select Bintray from the drop-down menu:

Selecting Bintray as a Docker registry
Selecting Bintray as a Docker registry

Alternatively, if your pipeline uses Codefresh YAML, you can easily use the push step to upload a Docker image to Bintray:

You can now execute the pipeline and see the individual steps running:

Pushing to Bintray
Pushing to Bintray

Once the build is finished, you can inspect the Docker image in the Bintray UI. Notice also that Codefresh will send some basic metadata of the build to Bintray:

Codefresh Bintray Metadata
Codefresh Bintray Metadata

This is the easiest way to use Bintray from within Codefresh (as a Docker registry) and should be effective if all your pipelines are based on Docker images.

You can find all code for this blog post at https://github.com/codefresh-contrib/cfstep-bintray.

Downloading and uploading binary artifacts to Bintray from Codefresh pipelines

In the previous section, we have seen how easy is to use Bintray as a Docker registry inside Codefresh. One of the major characteristics of Bintray is the fact that it supports any kind of binary artifact and not just Docker images (the same is also true for Artifactory). You can use Bintray to store npm, Maven and Debian packages, and even generic artifacts.

In our example, we will use Bintray to store Go binaries. We will create two pipelines:

Using Bintray as a binary repository
Using Bintray as a binary repository

The first pipeline compiles the GO source code, creates a binary and uploads it directly to Bintray (treating Bintray as a generic binary repository).

The second pipeline downloads the premade Go binary (treating Bintray as a generic repository), packages it into a Docker image, and uploads it to Bintray again (this time using Bintray as a Docker registry).

You should now see the dual role Bintray can play. At the end of the first pipeline (and the beginning of the second one), it acts as a Go Binary repository. At the end of the second pipeline, it acts as a Docker registry.

To interact with Bintray (as a generic binary repository) we will use the JFrog CLI. Since JFrog doesn’t offer a premade Docker image with its CLI, we created our own that can be found at codefresh/jfrog-cli. This is a single wrapper on top of the CLI.

Here is the Codefresh YAML for the first pipeline:

The pipeline has the following steps:

  1. A step that compiles the Go source code
  2. A step that uploads the binary to Bintray (at this point the binary is still not public)
  3. A step that “publishes” (makes public) the binary in Bintray
  4. A wait step since publishing the artifact can take some time

We use in the pipeline two variables: BINTRAY_USER, and BINTRAY_KEY, which are the Bintray username and API as mentioned in the previous section.

Bintray Credentials
Bintray Credentials

Here is the view of the pipeline:

Uploading to Bintray
Uploading to Bintray

At this point the GO binary is available in Bintray:

Bintray Artifact
Bintray Artifact

For the second pipeline we download this binary, add it into a Docker image and upload it again (this time in the Docker repository in Bintray).

Here is the Codefresh pipeline:

The pipeline should run:

Downloading from Bintray
Downloading from Bintray

Once the pipeline is finished we can verify the Docker image is uploaded in Bintray:

Final Bintray Docker image
Final Bintray Docker image

Notice that the Dockerfile we use in the second file is a special one that expects the GO binary to be present.

Conclusion

In this article, we have seen how easy the integration between Codefresh and JFrog Bintray is. We have seen:

  1. A simple pipeline where we upload a Docker image directly to Bintray (treating it a Docker registry).
  2. A more complex scenario where we upload a binary artifact to Bintray from one pipeline, and then download it and Dockerize it in a second pipeline (treating Bintray as a generic artifact repository).

You are now ready to use Codefresh and JFrog Bintray together in your own pipelines. Remember that the code for the plugin itself as well as the pipeline is available at Github. The plugin image can be found at https://hub.docker.com/r/codefresh/cfstep-bintray/.

New to Codefresh? Create Your Free Account Today!

Kostis Kapelonis

About Kostis Kapelonis

Kostis is a software engineer/technical-writer dual class character. He lives and breathes automation, good testing practices and stress-free deployments.

Reader Interactions

Enjoy this article? Don't forget to share.

Comments

Your email address will not be published. Required fields are marked *

Follow me on Twitter