Cloud Seed - Deploy faster with GitLab 🚀
Tags: cloud, gitlab, googlecloud, devops
Published: 2023-04-24 08:50:34

Were you at the [Cloud Next](https://cloud.withgoogle.com/next) in October? This big annual Google event where a lot of new features around Google and its cloud platform GCP are announced. This year, there was one linked to GitLab : [Cloud Seed](https://hello.cloudseed.app/).


## ⛅ 🌱Cloud Seed ?

What is Cloud Seed? This is a new, open source project launched by GitLab Incubation at the end of 2021 and lead by by [Sri Rangan](https://twitter.com/srirangan).

 
The objective of Cloud Seed is very simple. It’s to accelerate deployment of your application from GitLab to Google Cloud Platform. This project was opened first for beta testers, we were less than 100 people to try out this project and give some feedback. 

At the Cloud Next, Sri announced the first release of Cloud Seed and his opening to everyone. This talk is available on [this page](https://cloud.withgoogle.com/next/speakers?session=PAR21). 

## ⏪ Before Cloud Seed, deployments looked like …

Before Cloud Seed, deployments on GCP could be done with several methods. In all cases, continuous deployment (and integration) in GitLab is done by a GitLab homemade tool: [GitLab CI](https://docs.gitlab.com/ee/ci/).

GitLab CI is “_a tool for software development using the continuous methodologies: continuous integration, continuous delivery and continuous deployment_”. Based on the Go language, [GitLab Runner](https://docs.gitlab.com/runner/) made these CI/CD operations, defined in pipelines, very fast.

On GitLab CI, there are two concepts to know: “**stage**” and “**job**”.


* **Stage** is a step of your pipeline. Like “test”, “build”, “deploy” to test, build and deploy your application. 
* **Job** is a little entity that is going to make one operation on your application. Some jobs could be on the same stage.

I’ve created [this cheat sheet](https://dev.to/zenika/gitlab-cheatsheet-1-basics-of-stages-and-jobs-14p0) to explain basics of GitLab CI pipeline

![GitLab Cheatsheet : bascis of stages and jobs](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qzgpw2c54t8klqhto7la.png)

Come back to our deployment on GCP. I focus on solutions only based on GitLab CI. I voluntarily exclude external tools like [Ansible](https://docs.ansible.com/ansible/latest/index.html) and [Terraform](https://www.terraform.io/) that can be called from a GitLab CI pipeline. I see two options to deploy a project on GCP. 

First one, it’s to use the [gcloud](https://cloud.google.com/sdk/docs/install) Command Line Interface (CLI) as you can use on your computer. A new job based on the image “google/cloud-sdk” allows you to avoid installing this CLI. After configuration and authentication of your project, you can use gcloud command to deploy a [Cloud Function](https://cloud.google.com/functions), an application with [App engine](https://cloud.google.com/appengine?hl=fr), etc.  The GitLab CI job for a deployment of a Cloud Function could look like:

```
deploy-with-gcloud-image:
  [...]
  image: google/cloud-sdk:&lt;verion>
  script:
    - echo $GCP_SERVICE_KEY | base64 -d > /tmp/gcloud-service-key.json
    - gcloud auth activate-service-account --key-file /tmp/gcloud-service-key.json
    - gcloud functions deploy my_function [...]
```

If you are working on a bigger project deployed on [Google Kubernetes Engine](https://cloud.google.com/kubernetes-engine) (GKE), you can use the [Kubernetes Agent](https://docs.gitlab.com/ee/user/clusters/agent/) created by GitLab one year ago. This agent replaces an older version of Kubernetes integration, depreciated in 14.5 version and removed in the GitLab version 15 released last year.

How does it work? You configure an agent on your GitLab project. An agent is one or more yaml files. After declaring in the GitLab UI where your agent is, GitLab gives you a docker command to install it on your Kubernetes cluster. And that’s all. After this, each commit on your project will be detected by the agent and your application will be deployed automatically. Nice!

If, despite this, you want or have to deploy anything with a GitLab CI pipeline, this Kubernetes integration offers a “[CI/CD tunnel](https://about.gitlab.com/blog/2022/01/07/gitops-with-gitlab-using-ci-cd/)”. This agent is going to simplify the connection between GitLab and your Kubernetes cluster. In a job based on the image “bitnami/kubectl”, after declared your Kubernetes context linked to your agent, you can simply apply Kubernetes yaml file, for example:

```
deploy-with-cicd-tunnel:
  before_script:
    - kubectl config use-context "group/project:agentk"
  image:
    name: bitnami/kubectl:&lt;version>
    entrypoint: [""]
  script:
    - kubectl apply -f &lt;my kubernetes file>
```

I created [this cheat sheet](https://dev.to/zenika/gitlabcheatsheet-12-kubernetes-integration-2ph2) on this Kubernetes integration:

![GitLab Cheatsheet : Kubernetes integration](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h3gaz5s5t720fdvms9d9.png)


## 🚀 Cloud Seed, the deployment facilitator 

The main objective of Cloud Seed is to accelerate the deployment of your application. In the previous options, you could see that you need to declare and write a pipeline to deploy your application. Nothing really complicated but this is code mainly copied from other pipelines.

This is on this point that Cloud Seed steps in.

Others objectives are hidden behind the first. If applications deployment in the Cloud is faster and easier, this allows to attract people to decide a migration on the Cloud. Next, if applications are on Cloud, they can use Cloud services, modernizing them.


## 🔎 How Cloud Seed works ?  

Cloud Seed is available on GitLab in the Menu “Infrastructure > Google Cloud”. This allows you to see a new page containing three zones:  “Configuration”, “Deployments” et “Database”..

![Cloud Seed : how it works](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xpxwz7by83vvhei75bcv.png)

### Configuration

The first section is about configuration of connection with your Google account. After entering and choosing your Gmail address, you can set the name of your GCP project you have created before. Next, specify on which branch you can create a service account. 

During my tests I didn’t try to create some elements on a specific branch. This is for later.

![Cloud Seed : create a service account](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4scy54rks15ecupfidhp.png)


After this first step, you will see this new service account on the screen. And the last thing to do is to configure a GCP region to execute your actions. By default it’s “us-central1”.

These operations impacted your CI/CD variables. You can check on the “Settings > CI/CD > Variables” menu. Before Cloud Seed, these declarations had to be manually.


### Deployments

Now your configuration is done, we can focus on the main objective to Cloud Seed: the deployment of your application.

At the time I write this blog post, there are two deployment services visibles: [Cloud Run](https://cloud.google.com/run?hl=fr) and [Cloud Storage](https://cloud.google.com/storage). The first is the only one enabled for this moment. You may request support for additional Google Cloud services via [a Cloud Seed feature request](https://gitlab.com/gitlab-org/incubation-engineering/five-minute-production/feedback/-/issues/new?issuable_template=feature_request). This helps the open source community understand the needs and define future roadmaps. 

Cloud Run is a serverless platform which allows you to focus on development. Cloud Run builds for you your application from a Dockerfile, or if this file is missing, try to determine which typology your project is from a list of [buildpacks](https://github.com/GoogleCloudPlatform/buildpacks).

Cloud Seed configures your project for Cloud Run with a merge request containing a modification only on the **.gitlab-ci.yml** file. 

```
include:
- remote: https://gitlab.com/gitlab-org/incubation-engineering/five-minute-production/library/-/raw/main/gcp/cloud-run.gitlab-ci.yml
```

This modification creates a link with another GitLab project, belonging to GitLab, that the objective is to have CI/CD templates for the different GCP services.

Looking this yml file in detail, we can see that the job is simple:

```
deploy-to-cloud-run:
  stage: deploy
  image: registry.gitlab.com/gitlab-org/incubation-engineering/five-minute-production/library/google-cloud-sdk-for-gitlab:main
  script:
    - cp /cloud-run.sh .
    - ./cloud-run.sh
[...]
```

The job included in our project will be run on the **deploy** stage and will create a job called **deploy-to-cloud-run**. The job executes the script **cloud-run.sh**, saved in the same project. It’s a shell script which verifies the presence of all variables it needs and executes a **gcloud** command. 

That’s all. If you have a Dockerfile or a project listing in the available Google buildpacks, your application will be deployed on Cloud Run with this job.

If you have a doubt, you can see in the GCP console or with the CLI that you have a service Cloud Run running.

![Cloud Seed : Service is running on GCP](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/liuz8j88ddbny04ijne2.png)

The application, in my example a Quarkus API, is available! 🎉

![Cloud Seed : API is OK](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dqp62ptfuphi1ht13c8h.png)

In the **deploy-to-cloud-run** job, there is the notion of an environment I previously hide:

```
environment:
    name: $CI_COMMIT_REF_NAME
    url: $DYNAMIC_URL
```

These three lines are going to create, in your GitLab project, an environment by branch. Environment has no direct action on GCP but GitLab displays information and creates links with your services.

For example, in the **Environment** menu I have three branches, only two getting a Cloud Run service associated. “Open” buttons allow you to open your API.

![Cloud Seed - 3 branches](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/50wl0m3svbxi4vrun0kc.png)

⚠️ For this moment, “Stop” button don’t remove the dedicated Cloud Run services. It only removes the environment on GitLab. 


### Databases

The last part talks about Database. The objective is simple: allow you to create and get information about databases you need in your project. You can see on the GitLab UI that you can create an instance of [Cloud SQL](https://cloud.google.com/sql?hl=fr) database (Postgres, MySQL or SQL Server) directly on GitLab with some few clicks.

![Cloud Seed : Databases](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3q7iudvs00fridakwnul.png)

For example, for a Postgres database, you have to give some information, like the name, the machine type, the Postgres version and a reference which allows you to create a link between a branch of your project and an instance of a database.

![Cloud Seed : create a new instance of database](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r0vle43bkrcgz3mmmcjm.png)

After this step, of course you can see your instance on the GCP console or with the CLI:

![Cloud Seed : the new instance on GCP](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yuzy399i7wy5qwvndrbh.png)

On GitLab, some information are displayed:

![Cloud Seed : the new instance on GitLab](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f5u4uwu48gbx33hisery.png)

Perhaps more information will be displayed in the future, I created an issue to ask that 😄.


## 🗺️ The roadmap

Like all GitLab projects, the Cloud Seed roadmap is available for everyone: [https://gitlab.com/groups/gitlab-org/incubation-engineering/five-minute-production/-/boards](https://gitlab.com/groups/gitlab-org/incubation-engineering/five-minute-production/-/boards)

![Cloud Seed : the roadmap](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qobmpnrmz2ahj8fmw5rw.png)


We can see on this that scripts for Cloud Function and App engine are planned for and if you have experience with this, you can contribute! 


## 🔭 The future of Cloud Seed

After some first tests, I was so happy to see that, as a developer I am, I can avoid writing CI/CD jobs for configuring and writing **gcloud** commands. I agree, it’s not really difficult, but when I develop, I would like to focus on this task, not on scripting **gcloud** commands. It was very simple to configure your project, feedback is welcome and on discord we can exchange. The GitLab community is once again at the top!

I had this chance to test Cloud Seed during the beta testing phase and this allows me to give my feedback and get a correction faster. So it was logical to start migrating my personal projects interacting with GCP on Cloud Run. 

GitLab is a company with the slogan “_everyone can contribute_”. Contributions, as in all GitLab projects, are welcome and give feedback, try to resolve issues, make Cloud Seed grow and be greater than today!  A discord existed and allowed to exchange directly with GitLab members and got responses quickly. Very appreciable!

Some evolutions are planned for in the roadmap on others GCP services and I am waiting with impatience to test this and migrate others projects!

To explain quickly what is Cloud Seed, I created [this 14th GitLab cheat sheet](https://dev.to/zenika/gitlab-cheatsheet-14-cloud-seed-3oh7):

![Cloud Seed : Cheatsheet](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/scqxeq5rm2enejhiparc.png)

I have the chance to present Cloud Seed at the [DevFest Nantes 2022](https://devfest.gdgnantes.com/), the second developer conference in France. The video is available on [this link](https://www.youtube.com/watch?v=dO6ASsadHqM). 

If you have any questions or comments about this blog post, you can ping me on [Twitter](https://twitter.com/JPhi_Baconnais) 👋or on the Cloud Seed project Twitter account [@OpenCloudSeed](https://twitter.com/opencloudseed).