Push Docker Image to GCP Artifact Registry

Objective

You have a working docker project and the source code is managed in a Git repository. The goal of the tutorial is to push a docker image to the GCP Artifact Registry

This process will include:

  • cloning the application from a Git repository

  • building the docker image

  • push the docker image to the GCP Artifact Registry.

We will walk through each of the FlexDeploy features that will be created/configured to accomplish this goal and have the docker image published to the GCP Artifact Registry in a very short amount of time.

Checklist

Checklist

Description

Checklist

Description

Docker Registry Address

GCP Artifact Registry address

Docker Registry User

Use "oauth2accesstoken" to push images against the GCP Artifact Registry

Docker Registry Token/Password

Key file content, generated using Service Account of GCP

Docker Registry User permission

Service Account must have the required permission, to push images to the GCP Artifact Registry

Configure Cloud specific credential

To configure credential details according to the cloud provider, please refer to the document. https://flexagon.atlassian.net/wiki/spaces/FD60/pages/10109026311

Configure Container Account

Configure GCP Container Account under Topology. FlexDeploy will connect to the GCP Artifact Registry and push the image.

  1. Navigate to the Topology Tab

  2. Select Integrations from the left-hand pane

  3. Navigate to the Containers tab under Topology

  4. Create a new Containers account with the “+” button. Create a new Docker Registry account of provider type “DockerRegistry”

It should have a Registry Address, Registry User, and Registry Token/Password configured in it.

To push image to GCP Artifact Registry, the Service Account should at least have all permission of the Artifact Registry Writer.

  1. Docker Registry Token/password needs to be kept hidden. To update the same click on the pencil icon as shown below

  2. next update the GCP Service Account key file content under Secret Text. This is to make sure no one else can retrieve the password

Git repository structure

The Git repository should be a docker based application. Dockerfile should be present in application to build docker the image.

The Sample Git repository structure is given below:

Build Workflow

Navigate to the Workflows tab and create a workflow using the “+”(Click to create new Workflow) button as highlighted below.

Next, create one Build workflow as shown below. The workflow Type field defines the type of workflow.

Build Workflow

  1. Navigate to the Workflows Tab

  2. Select the “+” button from the left-hand pane to create a new workflow with type as Build.

The Workflow Group and Subgroup define the folder hierarchy. Once both workflows are created it should look like the below. No constraint on workflow or folder naming convention.

The steps of the workflow execution can be configured through the Workflow Definition section.

Below given is a sample build workflow to build and push docker image to the GCP Artifact Registry.

Step-i: Clone Git Repository

This step will clone the Git repository codebase into the project execution working directory. The Git URL will be retrieved from Source Control configured under Project Configuration.

Below given is the Git code structure and corresponding exported codebase during execution as a result of the above step.

Git Codebase

EXPORTED CODEBASE

Step-ii: Build and Push the docker image to the GCP Artifact Registry

Below given is the Docker plugin(buildImage operation) configurations. The below step will build and push docker image to the GCP Artifact Registry.

The plugin operation by default would look for Dokerfile under TEMP directory. In case the same exist in some other folder, relative path has to be specified from TEMP directory.

Below given is the Git project folder structure. Since our Dockerfile is under the DockerDemo folder in the Git repository we had to provide the relative path accordingly.

By default docker image and image tag details will be retrieved from Project Properties. However, one can always provide the details as part of the plugin operation input(highlighted in above plugin operation diagram). Plugin operation input shall take precedence over Project Properties.

We have also marked the “Push Image to Repository” checkbox to ensure the created image is push to the GCP Artifact Registry. pushImage operation under the Docker plugin can also be used to push the image to the target Docker Registry.

If the Container Registry Account is properly configured it would push the image to Docker Registry. In our case, the image is pushed to the GCP Artifact Registry as can be observed below.

After Build docker image information will also be available in the Artifacts section.

Project configuration

Navigate to the Project tab and create a Project with a logical name (PushDockerImageToGCPArtifactRegistry in this case)

Configure the Build workflow that has been created in previous steps as shown below.

Source Control

Configure the Source SCM repository under Source Control as shown below.

 

  1. To configure Project specific Source Control one first need to navigate to the Project Configuration tab.

  2. Next, expand the SOURCE CONTROL option from the left-hand pane.

  3. Select SOURCES for configuring the Source Repository

  4. Select the appropriate Source Control Type

  5. Configure Source Repository. For detailed steps of Source Control configuration please refer to https://flexagon.atlassian.net/wiki/spaces/FD60/pages/10107093010

Project Properties

To configure Project specific settings one can navigate to Configuration Properties as shown below.

  1. To configure Project specific settings one can navigate to the Project Configuration tab as shown above.

  2. Next, select the PROPERTIES option from the left-hand pane.

  3. Select the target Registry Account.

  4. Docker Image Name and Docker Image Tag are essential to build the docker image.

Target Properties

Select Topology from the menu and then select Topology Overview from the left menu. You will see a table that has Instances as the rows and Environments as the columns with colored circles representing the Environment

Instance. Color coding represents:

  • RED - no required properties are set and/or the Endpoint is not configured

  • YELLOW - some of the required properties are set and/or the Endpoint is not configured

  • GREEN - all required properties are set and the Endpoint is configured

Selecting the GREEN circle for DEV will display the configurable properties/Endpoint and allows for the configuration.

Properties

Mandatory field

Description

Docker Server

Optional

Docker server address. Required if Docker Unix Socket is not set.

Docker Server Port

Optional

The port to connect to on the Docker server.

Docker Unix Socket

Optional

The socket the Docker daemon listens on

The default value is [/var/run/docker.sock]

Registry Account

Optional

Docker Registry account with relevant details

GIT Path

Optional

Path to the Git executable. Required only if git is not on PATH.

Below given are the env-specific values which need to be updated.

Build Execution

For detailed steps on how to initiate Build and push docker image please refer to https://flexagon.atlassian.net/wiki/spaces/FD60/pages/10136879115

Congratulations! You have successfully completed the Push Docker Image to GCP Artifact Registry tutorial.

Now that you have configured FlexDeploy to push image to the GCP Artifact Registry, it is extremely easy to replicate the same for other Container Registry as well. Simply use the Copy Project feature and a new project will be created with all of the configuration completed already. You just need to make the necessary configuration changes.

 

 

 

 

 

 

The following macros are not currently supported in the footer:
  • style