Using the DigitalOcean Container Registry with Codefresh
Tags: digitalocean, container, devops, cicd
Published: 2020-12-09 10:58:41

DigitalOcean has <a href="https://www.digitalocean.com/blog/container-registry-generally-available/">just announced the DigitalOcean Container Registry,</a> which is directly integrated into the DigitalOcean Dashboard. While you can use any Container Registry in your DigitalOcean resources, the goal of the Container Registry is to provide for easy connection between the Container Registry and <a href="https://www.digitalocean.com/products/kubernetes/">DigitalOcean Kubernetes</a> resources.

<i>DigitalOcean Container Registry Dashboard</i>

<a href="https://codefresh.io/wp-content/uploads/2020/12/digital-ocean-registry.png"><img class="wp-image-18271 size-full aligncenter" src="https://codefresh.io/wp-content/uploads/2020/12/digital-ocean-registry.png" alt="digital-ocean-registry" width="1230" height="639" /></a>

Whether you have already integrated DigitalOcean cloud resources into your Codefresh pipelines or not, you could use the DigitalOcean Container Registry like any <a href="https://codefresh.io/docs/docs/integrations/docker-registries/">other container registry</a> in your Codefresh Pipeline.
<h1>Overview</h1>
The DigitalOcean Container Registry provides:
<ul>
 	<li>Three<a href="https://www.digitalocean.com/docs/container-registry/#plans-and-pricing"> subscription plans</a> that offer different allowances for repositories, storage, and bandwidth</li>
 	<li>1-click method to<a href="https://www.digitalocean.com/docs/container-registry/how-to/use-registry-docker-kubernetes/#add-secret-control-panel"> configure DigitalOcean Kubernetes Cluster to use the registry</a></li>
 	<li><a href="https://www.digitalocean.com/docs/container-registry/how-to/clean-up-container-registry/">Garbage collection</a> using the command line or the API</li>
 	<li>Ability to see the current storage usage in the control panel</li>
 	<li>Automatic global load balancing across caching endpoints in multiple geographic regions</li>
 	<li>Ability to store any artifact that is compatible with OCI-based registries, such as<a href="https://helm.sh/docs/topics/registries/"> Helm charts</a></li>
</ul>
Furthermore, the DigitalOcean Container Registry is not just for containers. It allows users to store any artifacts that are compatible with the OCI specifications. This allows you to keep Helm Charts in your DigitalOcean Container Registry (note that<a href="https://helm.sh/docs/topics/registries/"> Helm’s OCI support is still experimental</a>).
<h1>Building and pushing a Container image with DigitalOcean and Codefresh</h1>
The set-up will only take 4 steps, assuming that you have a
<ul>
 	<li><a href="https://www.digitalocean.com/">DigitalOcean Account</a></li>
 	<li>Codefresh Account -- If not <a href="https://codefresh.io/codefresh-signup/?utm_source=Blog&amp;utm_medium=Post&amp;utm_campaign=digitaloceanregistry">Create Your Free Account today</a>!</li>
</ul>
First, we have to set-up our Container Registry in DigitalOcean. This can be done by opening your account and accessing the “Container Registry” section:

<a href="https://codefresh.io/wp-content/uploads/2020/12/container-registry-ui.png"><img class="wp-image-18273 size-large" src="https://codefresh.io/wp-content/uploads/2020/12/container-registry-ui-1024x467.png" alt="container-registry-ui" width="1024" height="467" /></a>

Since we are already in DigitalOcean, we can go ahead and create our access token. Open <b>API</b> in the bottom left of the Account page (below Settings). And create a new token at <b>Tokens/Keys. </b>The token needs to have both read and write permissions. Make sure to take note of the token since we will need it in the next step.

Now we can add the DigitalOcean Container registry to our <a href="https://g.codefresh.io/account-admin/account-conf/integration/registryNew">Docker registries</a> in Codefresh. For this, <a href="https://g.codefresh.io/account-admin/account-conf/integration/registryNew">open</a>:

Codefresh Account =&gt; Account Settings (bottom left) =&gt; Docker Registries =&gt; Integrations =&gt; Docker Registries =&gt; Add Registry Provider =&gt; Other Registries

This should get you to the following screen. As you can see, Codefresh supports a variety of Container Registries:

<a href="https://codefresh.io/wp-content/uploads/2020/12/Codefresh-registry-settings.png"><img class="wp-image-18274 size-large" src="https://codefresh.io/wp-content/uploads/2020/12/Codefresh-registry-settings-1024x529.png" alt="Codefresh-registry-settings" width="1024" height="529" /></a>

Next, we have to provide the configuration information for the DigitalOcean Container Registry. For this, you will need our <a href="https://www.digitalocean.com/docs/apis-clis/api/create-personal-access-token/">DigitalOcean Access Token</a>. The token is used <a href="https://www.digitalocean.com/docs/container-registry/how-to/set-up-ci-cd/">both as username and as password</a>.

<a href="https://codefresh.io/wp-content/uploads/2020/12/registry-settings.png"><img class="wp-image-18275 size-large" src="https://codefresh.io/wp-content/uploads/2020/12/registry-settings-1024x435.png" alt="registry-settings" width="1024" height="435" />

The URL is going to be <b>registry.digitalocean.com</b> -- you can then provide the registry name in the advanced options (alternatively, you could include it in your build step before the image name).

That’s it! Now we can push images from our Codefresh Pipeline directly to the DigitalOcean Container Registry. Note that if DigitalOcean is not set as your default registry, you have to define the registry in your build step:
<pre>registry: "digital-ocean"</pre>
Our full build step will look as follow:
<pre>  build:
    title: "Building Docker image"
    type: "build"
    image_name: "anais-codefresh/react-article-display-do-registry"
    tags:
      - "1.0.0"
    dockerfile: "Dockerfile"
    registry: "digital-ocean"
</pre>
Different to other platforms, the Codefresh Build Step both builds AND pushes the image to the registry.

Running the image, we can see the step execute in the output section of our pipeline:

<a href="https://codefresh.io/wp-content/uploads/2020/12/do-codefresh-pipeline.png"><img class="wp-image-18276 size-large" src="https://codefresh.io/wp-content/uploads/2020/12/do-codefresh-pipeline-1024x577.png" alt="do-codefresh-pipeline" width="1024" height="577" />

And view the Container image directly in DigitalOcean

<a href="https://codefresh.io/wp-content/uploads/2020/12/container-image-in-digital-ocean.png"><img class="wp-image-18277 size-large" src="https://codefresh.io/wp-content/uploads/2020/12/container-image-in-digital-ocean-1024x532.png" alt="container-image-in-digital-ocean" width="1024" height="532" /></a>

<h3><b>Try it out TODAY!</b></h3>
We made it super easy for you to connect DigitalOcean Container Registry to your Codefresh pipeline. You can find more details in the <a href="https://codefresh.io/docs/docs/integrations/docker-registries/digital-ocean-container-registry/">Codefresh documentation</a>.

Wait, you are not a Codefresh user yet? <a href="https://codefresh.io/codefresh-signup/?utm_source=Blog&amp;utm_medium=Post&amp;utm_campaign=digitaloceanregistry">Create Your Free Account today</a>!

This process works on all Codefresh accounts. You can set it up in minutes to try it out.

If you have any questions, feel free to ask in<a href="https://community.codefresh.io/"> our community forum</a>, we would love to hear from you.