Deploying to Artifactory/Bintray from Codefresh pipelines

Deploying to Artifactory/Bintray from Codefresh pipelines

7 min read

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:

version: '1.0'
stages:
- build
- push
steps:
  MyAppDockerImage:
    title: Building Docker Image
    stage: 'build'
    type: build
    image_name: trivial-go-web
    working_directory: ./
    tag: ${{CF_BRANCH_TAG_NORMALIZED}}
    dockerfile: Dockerfile.multistage
  pushingTo_jfrog_BintrayRegistry:
    stage: 'push'
    type: push
    title: jfrog_Pushing To Bintray Registry
    candidate: ${{MyAppDockerImage}}
    tag: ${{CF_SHORT_REVISION}}
    registry: 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:

version: '1.0'
stages:
- Compile
- Bintray upload
- Dockerize
steps:
  BuildingArtifact:
    title: Compile Go Code
    image: golang:1.7.1
    stage: Compile
    working_directory: upload-example/
    commands:
      - cp -r src /go/src
      - cd /go/src
      - go build -o /go/bin/sample src/sample/trivial-web-server.go
      - cp -r /go/bin /codefresh/volume/
  UploadBinary:
    stage: 'Bintray upload'
    title: upload Go binary to Bintray
    image: codefresh/cfstep-bintray:master
    environment:
      - BINTRAY_COMMAND=u
      - BINTRAY_ARGS=/codefresh/volume/bin/sample codefresh-demo/test/cf-demo/v7.0 --override
  PublishVersion:
    stage: 'Bintray upload'
    title: Publish Bintray version
    image: codefresh/cfstep-bintray:master
    environment:
      - BINTRAY_COMMAND=vp
      - BINTRAY_ARGS=codefresh-demo/test/cf-demo/v7.0
  Waiting:
    stage: 'Bintray upload'
    title: 'Awaiting publication'
    image: alpine
    commands:
      - sleep 30 

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:

version: '1.0'
stages:
- Bintray download
- Dockerize
steps:
  Prepare:
    title: 'Delete previous artifact'
    image: alpine
    commands:
      - rm -f download-example/sample
  DownloadNewVersion:
    stage: 'Bintray download'
    title: Download from Bintray
    image: codefresh/cfstep-bintray:master
    working_directory: download-example/
    environment:
      - BINTRAY_COMMAND=dlv
      - BINTRAY_ARGS= codefresh-demo/test/cf-demo/v4.0 --unpublished
  MyAppDockerImage:
    title: Building Docker Image
    stage: 'Dockerize'
    type: build
    image_name: my-full-app
    working_directory: download-example/
    tag: ${{CF_BRANCH_TAG_NORMALIZED}}
    dockerfile: Dockerfile
  PushingToBintray:
    stage: 'Dockerize'
    type: push
    title: jfrog_Pushing To Bintray Registry
    candidate: ${{MyAppDockerImage}}
    tag: ${{CF_SHORT_REVISION}}
    registry: bintray    

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!

Ready to Get Started?
  • safer deployments
  • More frequent deployments
  • resilient deployments