Coder Social home page Coder Social logo

ci-cd-gcp-terraform-example's Introduction

CI-CD-GCP-terraform-example

An example/practice repository for setting up a CI/CD pipeline. Set up on GCP with Terraform.

Based on chapter 7 of 'Terraform in Action', but with some changes of my own.

The pipeline:

  • Code is pushed to Cloud Source Repositories
  • This triggers a Cloud Build build, with the template based on the buildtemplate.yaml file
  • The Cloud Build:
    • Tests the code with pytest
    • Builds the Docker app in the app folder
    • Pushes the image to the Container Registry
    • Deploys the image to Cloud Run

Terraform steps

  1. Create a GCP project
  2. Create a service account with the Project/Editor, Project IAM Admin, Security Admin, and Source Repository Administrator roles.
  3. Create and download a key for the service account
  4. Create a terraform.tfvars file in the terraform folder that contains the project variable with your project ID and the credentials variable with the location of your credentials file.
  5. Enable the following APIs for your project:
  6. Run terraform init
  7. Run terraform apply
  8. Type yes and hit enter.
  9. You can run terraform destroy to destroy the provisioned resources.

Terraform will output 2 urls. One is the url of your app, the other is the url of the Cloud Source Repository. You can set this as a remote for the git repository you have with git remote add google <url> and then push to that remote with git push --all google

Run build from GitHub repository

You can set a Cloud Source Repository to mirror a GitHub repository, but you can't (yet) do this with Terraform, so if you want to do this you will have to do it manually.

ci-cd-gcp-terraform-example's People

Contributors

lgvacanti avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.