Continuous integration and deployment (CI/CD) streamline the application development process, making it more efficient and less error-prone. Integrating platforms like CTO.ai with GCP's Container Registry can simplify and automate container deployment, saving time and resources. In this article, we'll walk you through the process of deploying a container to GCP's Container Registry using CTO.ai.
Prerequisites
- GCP account
- A created project on GCP
- Google Cloud SDK installed and enabled
- Docker installed on your local machine
- A CTO.ai account
- CTO.ai GCP workflow is installed on your machine, and Ops CLI installed.
- Pulumi Token installed on your project
Set Up Google Cloud Service Account
Create a service account on GCP to give CTO.ai access:
- Go to GCP console > IAM & admin > Service accounts.
- Click
Create Service Account
- Assign the
Storage Admin
role to the service account. This will allow CTO.ai to push images to the Container Registry. - Download the JSON key for your service account, which you will use later.
Configure and Set up GCP Workflows
Before we get started with this guide, install the GCP GKE Pulumi Py workflow from. If you don't have access to the repository, kindly contact us at [email protected] The repo includes a complete IaC for deploying infrastructure over GCP: Kubernetes, Container Registry, Database Clusters, Load Balancers, and Project Resource Management, all built using Python + Pulumi + CTO.ai.
Clone the repository with:
git clone “https://github.com/workflows-sh/gcp-gke-pulumi-py.git”
cd gcp-gke-pulumi-py
Run and Set up your Infrastructure
Next, you need to build and set up the infrastructure that will deploy each resource to GCP using the GCP workflow stack. Set up your infrastructure using the ops run -b .
This will provision your stack and set up your infrastructure.
- Select setup infrastructure over GCP
- This process will build your Docker image and start provisioning your GCP infra resources.
- Next, select the services you want to deploy from the CLI. We will select the all service and install all the dependencies, which will also provision our GCP container registry.
- Back in the GCP console, click on your container registry, and you will see your Container Registry created for usage.
Create and Update Ops.yml file
Next, create your ops.yml
file with the updated changes to push your resources to GCP Container Registry.
version: "1"
pipelines:
- name: sample-expressjs-pipeline-gcp-gke-pulumi-pyf:0.1.1
description: Build and Publish an image in a GCPContainer Registry
env:
static:
- DEBIAN_FRONTEND=noninteractive
- STACK_TYPE=gcp-gke-pulumi-py
- ORG=cto-ai
- GH_ORG=workflows-sh
- REPO=sample-expressjs-gcp-gke-pulumi-py
- BIN_LOCATION=/tmp/tools
secrets:
- GITHUB_TOKEN
- PULUMI_TOKEN
events:
- "github:workflows-sh/sample-gcp-gke-pulumi-py:pull_request.opened"
- "github:workflows-sh/sample-gcp-gke-pulumi-py:pull_request.synchronize"
- "github:workflows-sh/sample-gcp-gke-pulumi-py:pull_request.merged"
jobs:
- name: sample-expressjs-build-gcp-gke-pulumi-py
description: Build step for sample-expressjs-gcp-gke-pulumi-py
packages:
- git
- unzip
- wget
- tar
steps:
- mkdir -p $BIN_LOCATION
- export PATH=$PATH:$BIN_LOCATION
- ls -asl $BIN_LOCATION
jobs:
- name: build docker image
steps:
- docker build -t gcr.io/$GOOGLE_PROJECT_ID/my-image:$CTO_SHA1
- name: Push to GCP container Registry
steps:
- echo $GCLOUD_SERVICE_KEY | gcloud auth activate-service-account --key-file=-
- gcloud --quiet auth configure-docker
- docker push gcr.io/$GOOGLE_PROJECT_ID/my-image:$CTO_SHA1
Run the CTO.ai Pipeline
After updating the ops.yml
file, push it to your repository. This should trigger a CTO.ai build. CTo.ai will build your Docker image and push it to GCP’s Container Registry.
Verify Deployment to GCP
Once your CTO.ai pipeline completes:
- Go to the GCP Console
- Navigate to Container Registry, and click on Images.
- You should see your Docker image listed there, confirming a successful deployment.
Conclusion
Integrating CTO.ai with GCP’s Container Registry provides a powerful way to automate container deployment. With a few configuration steps, you can set up a CI/CD pipeline, ensuring your applications are built, tested, and deployed efficiently. This approach allows developers to focus on coding while CTO.ai and GCP handle the deployment processes.
Comments