IBM Cloud Code Engine (serverless) Application setup with a private registry — Step by Step Guide
Tags: ibmcloud, serverless, cloud, ibm
Published: 2024-02-29 16:06:20

The aim of the use case presented here is to provide a simplified step-by-step guide to deploy applications (any kind of application type eg. Batch, Job or Applications) from a <u>private code repository</u> (example here is using a private GitHub repo) to a <u>private container image registry</u> hosted on IBM Cloud.

> This document assumes working with a private GitHub repository.

## Create a Private Container Image Registry on IBM Cloud

The documentation: https://cloud.ibm.com/registry/start

### Install, Set Up, and Log In

- [Install the IBM Cloud CLI.](https://cloud.ibm.com/docs/containers?topic=containers-cli-install)

- [Install the Docker CLI.](https://docs.docker.com/engine/installation/) 

- > [Podman](https://podman.io/docs/installation) with Docker compatibility could be used as well
  >
  > [Podman Desktop](https://podman-desktop.io/) can replace Docker desktop with a 100% compatibility mode

- Install the Container Registry plug-in (assuming [IBM Cloud CLI](https://cloud.ibm.com/docs/cli?topic=cli-getting-started) is already installed)

  ```shell
  ibmcloud plugin install container-registry -r 'IBM Cloud'
  ```

- Log in to your IBM Cloud account

  ```shell
  ibmcloud login -a https://cloud.ibm.com
  ```

  > If you have a federated ID, use ibmcloud login --sso to log in to the IBM Cloud CLI.
  >
  > ```shell
  > ibmcloud login --sso
  > ```

- Ensure that you're targeting the correct IBM Cloud Container Registry region. Hereafter the region is set to **Frankfurt**

  ```shell
  ibmcloud cr region-set eu-central
  '''
  The region is set to 'eu-central', the registry is 'de.icr.io'.
  ```

- Choose a name for your first namespace, and create that namespace. Use this namespace for the rest of the Quick Start.

  ```shell
  ibmcloud cr namespace-add <my_namespace>
  '''
  ibmcloud cr namespace-add xxx_namespace
  Adding namespace 'xxx_namespace' in resource group 'default' for account XYZ's Account in registry de.icr.io...
  ```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bl3lj2bljwpzmsok7nfw.png)
  ### Push the image to your private registry (Testing the working with your registry)

- Log your local Docker daemon into the IBM Cloud Container Registry.

  ```shell
  ibmcloud cr login
  ```

- Pull a test image from Docker Hub

  ```shell
  docker pull hello-world
  '''
  Using default tag: latest
  c1ec31eb5944: Download complete
  d2c94e258dcb: Download complete
  docker.io/library/hello-world:latest
  ```

- Choose a repository and tag by which you can identify the image. Use the same repository and tag for the rest of this Quick Start

  ```shell
  docker tag hello-world de.icr.io/xxx_namespace/xxx_repository:my_tag
  ```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w6r0atrm3zch7iupcsxu.png)

- Push the image

  ```shell
  docker push de.icr.io/xxx_namespace/xxx_repository:1
  '''
  docker push de.icr.io/xxx_namespace/xxx_repository:1                                                     
  The push refers to repository [de.icr.io/xxx_namespace/xxx_repository:1]
  1: digest: sha256:5c2d1c82f9ecc3c3f3b3a4a50f6db9d09cdddb301f3eff37ff2116aa3a65ae10 size: 861
  ```

- Verify that your image is in your private registry

  ```shell
  ibmcloud cr image-list
  '''
  Listing images...
  
  Repository                               Tag   Digest         Namespace       Created         Size     Security status
  de.icr.io/xxx_namespace/aam_repository   1     5c2d1c82f9ec   xxx_namespace   10 months ago   2.5 kB   -
  ```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v4syn325zdh0u20xmxze.png)

## Create a Project in Code Engine

- Select **Code Engine** in the left side menu in the IBM Cloud resources dashboard (https://cloud.ibm.com/codeengine/overview)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v7itrc7u9tzu085tgpvt.png)

  

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9wgf2lc0nb1ohteeksjc.png)

- Select **Projects** in the left side menu, select the **Location** and **Resource group**, optionally set **Tags** and hit the **Create** button


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8y7cd09dzqbrwi9c5inb.png)
- Once the project is created, enter the project

## Create an application from a private GitHub repository

- Inside the **Project** click on **Application** on left side menu

- In the application creation settings dialog box, set the values and hit the **Specily build details** button

- > The URL of a private repository is not HTTPS but GIT! The documentation could be found at: https://docs.github.com/en/get-started/getting-started-with-git/managing-remote-repositories


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tnx1r6jt5z0z56yfyhxn.png)

- Specify the details as in the example below
  - The **Code repo URL** (private repo name provided in the previous step)
  - The  **Code repo access**  ([How to create a SSH Key for yoru GitHub account](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account)) (or a good article on how to set-up a **SSH Key** for GitHub: https://leangaurav.medium.com/setup-ssh-key-with-git-github-clone-private-repo-using-ssh-d983ab7bb956)
  - Hit **Next**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xvuzg3iyg0v0sknaq0ay.png)


- Specify the build details and hit **Next**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gxmlem01fo67ma48cd0f.png)

- You see the **Registry server**. You can either let **Code Engine** generate a secret for the registry or build your own secret (refer to **IAM** documentation on **IBM Cloud**). Choose the right **Namespace** for your application deployment and you can let **Code Engine** manage the **Repository (image name)**. Hit the **Done** button to start building your application.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r57233kl6mhustn6w4xm.png)
- Once your application is deployed and running you can access it through the interface! You're done, congrats!!!

  
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4dk0vccvn5ke3rq4zaka.png)


## Links and helpers

- Code Engine documentation: https://cloud.ibm.com/docs/codeengine
- Install IBM Cloud Code Engine **CLI**: https://cloud.ibm.com/codeengine/cli
- Creating **API Keys** on IBM Cloud: https://cloud.ibm.com/iam/apikeys