Skip to content

rv0lt/devops_example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Devops_example

pipeline

This repository is a small project containing an example for a DevOps worflow:

Web servers

There are two demo web servers applications developed:

  • One of them is a nginx web server
  • The other one was built using the flask framework

Both of them are bundled in docker containers.

The first one (the nginx) serves on localhost:8000/cv my resume. Whereas the second one has two endoints: in locahost:5000/time displays the time in Unix and localhost:5000/random gives 10 random numbers from 1 to 5.

The two directories: webserver_example_1 and webserver_example_2 contain the source code of them. As well as explanations on how they were coded and how they work

CI pipeline

For the CI pipeline, the code is in the workflows directory.

For the first web server, we need to compile the latex document of the resume, and then build the docker image, as well as pushing it to the docker registry. For the second one, we just need to build and push.

The pipeline will be called anytime there is a push on the mainstream branch, the idea is that anytime there are changes on the code, the images will be built and pushed again, so we can always have the latest version available.

Terraform

A small terraform code is provided on the deployment folder, it is used to provision the infrastructure where we can deploy our applications. It creates an instance on Google Cloud.

To reproduce the code there are two main changes to make:

  • On the google_compute_instance resource:

     metadata = { 
         ssh-keys = "rv0lt:${file("~/.ssh/gcloud_key.pub")}"
     }
    

You would need to provide your own ssh key to connect with the instance, the same format is "username:${file("username.pub")}"

  • Also, at the beginning of the terraform file, where the provider is set up:

`

provider "google" {
	project =  "global-shard-391615"
	credentials =  "./global-shard-391615-970a65630c3a.json"
	region =  "us-east1"
	zone =  "us-east1-b"
}

You need to set up a service account and specify the path to the credentials, in the same fashion as it can be seen on the file and it is explained here.

Once everything is set up, and we apply the terraform file, we can see it outputs the external IP we can use to connect to the instance created.

enter image description here

Ansible

Finally, we can automatize the deployment of our application on the instance thanks to Ansible, the external IP that was generated on the previous step, needs to be changed on the inventory file. In this file, we also need to specify the path to the private key to connect to the host:

[host] 
35.138.195.100 ansible_ssh_private_key_file=~/.ssh/gcloud_key

The playbook file, contains the tasks to install docker and run the images.

We can run the file with the following command ansible-playbook -i inventory playbook.yaml

Once it has finalized the execution we can make a final sanitary test to check that everything works as it is supposed:

enter image description here enter image description here

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published