Code Monkey home page Code Monkey logo

gcp-devops's Introduction

new

Pre-requisites

Ensure you have a GKE cluster created

Prepare the repo for your environment

#f03c15 Fork the repo and modify the following files before you proceeed

CloudBuild

  • Change the Image, location and cluster under args

Deployment File

  • Change the project under the image to your project name

Trigger

  • Change the Branch, ProjectID and Repo under triggerTemplate

Permissions

To use this builder, your builder service account will need IAM permissions sufficient for the operations you want to perform. For typical read-only usage, the "Kubernetes Engine Viewer" role is sufficient. To deploy container images on a GKE cluster, the "Kubernetes Engine Developer" role is sufficient. Check the GKE IAM page for details.

Prep work

#f03c15 Change core-demos to your Project name

gcloud config set project core-demos
gcloud services enable containerregistry.googleapis.com

gcloud services enable cloudbuild.googleapis.com

#f03c15 Change the details to your GKE Cluster setup

gcloud container clusters get-credentials --zone=us-central1-c devops-demo

Add required variables

PROJECT="$(gcloud projects describe \
    $(gcloud config get-value core/project -q) --format='get(projectNumber)')"

gcloud projects add-iam-policy-binding $PROJECT \
    --member=serviceAccount:[email protected] \
    --role=roles/container.developer

Manually submit a Cloud Build job

Clone the repo

#f03c15 Change YOURID to your Github ID

git clone https://github.com/YOURID/gcp-devops
cd gcp-devops

Build and push the image

#f03c15 Change core-demos to your Project name

docker build -t exapp .

docker tag exapp gcr.io/core-demos/exapp

docker push gcr.io/core-demos/exapp

Deploy to GKE

kubectl apply -f deployment.yaml

gcloud builds submit --config=cloudbuild.yaml

Watch the logs

kubectl logs -lrun=exapp -f

Setup CICD - Create a repo, and setup a Cloud Build trigger

Create your ssh keys

#c5f015 Use your email address

ssh-keygen -t rsa -b 4096 -C "source repo build [email protected]" -f ~/.ssh/myrepokey -P ''
cat ~/.ssh/myrepokey.pub

Upload key to GCP

https://source.cloud.google.com/user/ssh_keys

Setup Cloud Build

Create GCP source repo

gcloud source repos create mycode-repo
gcloud source repos describe mycode-repo

#c5f015 Use your email address

git config user.email [email protected]

Configure authentication over SSH

#c5f015 User should be your Cloud Identity

cat > ~/.ssh/config <<EOF
Host source.developers.google.com
    HostName source.developers.google.com
    User [email protected]
    IdentityFile ~/.ssh/myrepokey
EOF

Push config to the repo

#c5f015 Change IDENTITY to your Cloud Identity and PROJECT to your Project Name

git remote add google ssh://[email protected]@source.developers.google.com:2022/p/core-demos/r/mycode-repo
git add .
git commit -m "files"
git push --all google

Trigger a manual Cloud Build run

# Create the cloud build trigger
gcloud beta builds triggers import --source=trigger.yaml --verbosity debug
gcloud beta builds triggers list

Trigger an automated Cloud Build run

Edit some code & commit it

vim main.go
git add .
git commit -m "update 1"
git push --all google
watch -t -n2 kubectl logs -lrun=exapp
kubectl get events --sort-by='{.lastTimestamp}' --namespace=default --watch

Goto the following services in the portal

  • Cloud Build History
  • Container Registry
  • Cloud Source Repositories

gcp-devops's People

Contributors

louayshaat avatar

Watchers

James Cloos avatar  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.