1

I am very new to the CICD.

I have to set up a pipeline to connect the GitLab repo to the cloud run.

I have currently hosted my website on cloud run and code in GitLab using the manual command.

I have tried to mind many documents and vedios but those are not very clear or I am not able to understand them. If anyone can provide me good documents or guide me, il really appreciate it.

Shivank
  • 95
  • 1
  • 1
  • 5
  • Can you detail where you are? what is not working? What is your current pipeline? what do you want to achieve? – guillaume blaquiere Apr 20 '21 at 19:07
  • Hi, @Shivank You can take a look on this articles: In this link explains step by step how to [Setup GitLab CI/CD Pipeline for Google Cloud Run](https://yubinghou.wordpress.com/2020/11/13/setup-gitlab-ci-cd-pipeline-for-google-cloud-run/) and this post explains [how to setup and integrate GitLab CI and GCP Cloud Run in order to provide an efficient CI/CD pipeline](https://tobiasmaier.info/posts/2020/12/12/gitlab-cicd-pipeline-for-service-on-gcp-cloud-run.html). Good Luck! – Mathew Bellamy Apr 23 '21 at 19:27
  • Hello, this article can help you [CI/CD pipeline with GitLab CI, Cloud Build and Cloud Run - Configuration](https://cloud-architecture-design.medium.com/ci-cd-pipeline-with-cloud-build-and-cloud-run-configuration-9512865a73cb) – Ezekias BOKOVE Feb 19 '22 at 18:26

1 Answers1

0

Here's my solution for your problem:

You have to configure your Google Cloud projects:

  1. Enable Google Cloud Run API and Cloud Build API services.
  2. Create a Google Service Account with the correct permissions (Cloud Build Service Agent, Service Account User, Cloud Run Admin and Viewer)
  3. Generate a credential file from your Service Account, it will output a JSON.
  4. Setup Gitlab CI/CD variables: GCP_PROJECT_ID (with your project id) and GCP_SERVICE_ACCOUNT (with the content of your previous generated JSON).
  5. Setup your .gitlab-ci.yml like this:
variables:
  SERVICE_NAME: 'your-service-id'

image: google/cloud-sdk:latest

before_script:
  - apt-get --assume-yes install npm
  - npm install
  - npm run build

deploy:
  stage: deploy
  only:
    - master
  script:
    - echo $GCP_SERVICE_ACCOUNT > gcloud-service-key.json
    - gcloud auth activate-service-account --key-file gcloud-service-key.json
    - gcloud auth configure-docker
    - gcloud config set project $GCP_PROJECT_ID
    - gcloud config set run/region europe-west3
    - gcloud run deploy $SERVICE_NAME --source . --allow-unauthenticated

If you have worked with the Gitlab CI/CD (.yml) and Cloud Run (local) before, you will understand the steps easily.

This example is assuming you have a NodeJS project.

Frederiko Ribeiro
  • 1,844
  • 1
  • 18
  • 30