Coder Social home page Coder Social logo

devops-pipeline-google-cloud's Introduction

DevOps Pipeline Google Cloud

Build a continuous integration pipeline using Cloud Source Repositories, Cloud Build, build triggers, and Container Registry.

Project

Init Git Repository

To the Cloud Console go to Activate Cloud Shell

mkdir gcp-course
cd gcp-course
gcloud source repos clone devops-repo
cd devops-repo

Python App

Into folder devops-repo, create new file main.py

vi main.py 

See the main.py file into my repo

Create new folder templates

mkdir templates
vi layout.html

See the layout.html into /templates folder

Same with the file index.html

vi index.html

Into devops-repo, create a new file requirement.txt

echo "Flask==1.1.1" > requirement.txt

First, you need to add all the files you created to your local Git repo. In Cloud Shell, enter the following code:

cd ~/gcp-course/devops-repo
git add --all
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
git commit -a -m "Initial Commit"
git push origin master

Deployement Web app in Cloud Shell

cd ~/gcp-course/devops-repo
sudo pip3 install -r requirements.txt
python3 main.py

Click on the web preview "Preview on port 8080."

You can edit the file main.py

model = {"title": "Hello Tux Fans."}

Redeployement on git

cd ~/gcp-course/devops-repo
git commit -a -m "Second Commit"
git push origin master

Click on the web preview "Preview on port 8080." View change.

Docker build

Create a Dockerfile

cd ~/gcp-course/devops-repo
vi Dockerfile

See the Dockerfile into my repo

Manage Docker Images with Cloud Build and Container Registry

Into the cloud shell

cd ~/gcp-course/devops-repo
echo $DEVSHELL_PROJECT_ID

DEVSHELL_PROJECT_ID automatically has your current project ID stored.

gcloud builds submit --tag gcr.io/$DEVSHELL_PROJECT_ID/devops-image:v0.1 .

Cloud Console and on the Navigation menu, click Container Registry. Your image should be on the list.

Navigate to the Cloud Build service, and your build should be listed in the history.

Now go to Compute Engine and create new instance

Property Value
Container Deploy a container image to this VM instance
Container image gcr.io//devops-image:v0.1 (change the project ID where indicated)
Firewall Allow HTTP traffic
cd ~/gcp-course/devops-repo
git add --all
git commit -am "Added Docker Support"
git push origin master

Automate Builds with Triggers

Container Registry. At this point, you should have a folder named devops-image with at least one container in it.

Cloud Build. The Build history page should open, and one or more builds should be in your history.

Click the Triggers link on the left.

Click Create trigger.

Name the trigger devops-trigger

Select your devops-repo Git repository.

Select .*(any branch) for the branch.

Choose Dockerfile for Build Configuration and select the dafault image.

Accept the rest of the defaults, and click Create.

To test the trigger, click Run and then Run trigger.

Click the History link and you should see a build running. Wait for the build to finish, and then click the link to it to see its details.

Edit main.py

model = {"title": "Hello Trigger Fans."}
cd ~/gcp-course/devops-repo
git commit -a -m "Testing Build Trigger"
git push origin master

Test your build changes

When the build completes, click on it to see its details. Under Execution Details, copy the image link, format should be gcr.io/qwiklabs-gcp-00-f23112/devops-repoxx34345xx.

Go to the Compute Engine service. As you did earlier, create a new virtual machine to test this image. Select the box to deploy a container image to the VM, and paste the image you just copied.

Select Allow HTTP traffic.

When the machine is created, test your change by making a request to the VM's external IP address in your browser. Your new message should be displayed.

devops-pipeline-google-cloud's People

Contributors

czantoine avatar

Watchers

 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.