DigitalOcean Container Registry
Learn how to push Docker images to your DigitalOcean Container Registry
You can use the DigitalOcean Container Registry as your Docker Registry in your Codefresh pipeline.
Overview: DigitalOcean Container Registry
The DigitalOcean Container Registry is directly integrated into your DigitalOcean Dashboard. While it is optional to use the DigitalOcean Container registry with your DigitalOcean Kubernetes cluster, it allows for easier integration between resources.
The next sections will look at:
- Creating the DigitalOcean Container Registry
- Generating a DigitalOcean Access token
- Adding the DigitalOcean Container Registry to our Docker Registry in Codefresh
- Modifying the Build step in our Codefresh pipeline
- Viewing the built image in the DigitalOcean Container Registry
Building and pushing a Container image with DigitalOcean and Codefresh
Prerequisites:
- A DigitalOcean account (your GitHub username)
- A DigitalOcean access token
- An application with a Dockerfile to build images
Creating the DigitalOcean Container Registry
Once you are logged into your DigitalOcean Account, open the Container Registry
tap and provide the name of your registry. Note that the name has to be unique.
Creating an access token
Now that we are already in DigitalOcean, we have to create an access token. For this head over to API in the bottom right of your left-side Menu under Tokens/Keys we can create a new access token. Note that it requires read and write access. Copy and paste the token somewhere secure and where you will find it again.
Add the DigitalOcean Container Registry to our Docker Registry
Within your Codefresh Account go to:
Codefresh Account => Account Settings (bottom left) => Docker Registries => Integrations => Docker Registries => Add Registry Provider => Other Registries
Alternatively, you can follow the direct link.
This should lead you to the following screen:
Adding a new Registry within Other Registries, we fill out the fields like so:
- Registry name: You can name it anyway you like
- Username: The DigitalOcean access token we created prior
- Password: The DigitalOcean access token we created prior
- URL:
registry.digitalocean.com
- Optional, you can add your registry name to the advanced settings section. For instance, if you named it in Digital Ocean “anais-codefresh”, you can ensure that every time the registry is used, it is automatically referenced in the build step of your pipeline.
Modify your build step
Within your Codefresh YAML file, we will have to modify the build step to push to our DigitalOcean Container Registry. Note that you do not have to specify the Registry if you set the DigitalOcean Container Registry as default registry.
We have added the following line to your build step:
registry: "digital-ocean"
Our full build step will look as such:
version: "1.0"
stages:
- "clone"
- "build"
steps:
clone:
title: "Cloning repository"
type: "git-clone"
repo: "anais-codefresh/react-article-display"
# CF_BRANCH value is auto set when pipeline is triggered
# Learn more at codefresh.io/docs/docs/codefresh-yaml/variables/
revision: "${{CF_BRANCH}}"
git: "github"
stage: "clone"
build:
title: "Building Docker image"
type: "build"
image_name: "anais-codefresh/react-article-display-do-registry"
tags:
- "1.0.0"
working_directory: "${{clone}}"
dockerfile: "Dockerfile"
stage: "build"
registry: "digital-ocean"
Note that Codefresh builds AND pushes images both in the same step.
Running the Pipeline and viewing the image in the DigitalOcean Container Registry
Once you modified the step, save and run your pipeline. In it’s simplest form this will look as such:
We can then view our image in the DigitalOcean Container Registry: