Giter VIP home page Giter VIP logo

devops-home-tasks's Introduction

DevOps-home-tasks

Task 1

The directory task1 contains two implementations of task 1, Scripting Homework.

These scripts finds network connections of processes (by process name or PID) and for each Foreign Address print information about IP address owner. By default they looking for all TCP and UDP connections, sort them by remote IP address and for last 5 connections returns the informations about of the organization to which the Remote Address belongs as well as count of connections per organization.

More details in README file for each implementations.

Task 2

The directory "task2" contains implementations of task 2, Scripting Homework related to working with jq and contains 4 files:

  1. mean_origin.sh - Original script from the task.

  2. mean_v2.sh - Version of original script without using grep and pattern matching.

  3. quotes.json - Historical quotes for EUR/RUB pair since late November 2014:

  4. best_march.sh - Final part of task. This script read the quotes.json and find the year which March the price was the least volatile since 2015.

    Usage: ./best_march.sh MONTH_NUMBER START_YEAR END_YEAR

    Example of usage: ./best_march.sh 3 15 18

    Get help: ./best_march.sh -h

More details in task2/README.md.

Task 3

Task 3 related to working with GitHub REST API from linux shell. It contains only one script - git_get_pulls.sh.
This script take a link to an user GitHub repository and get various info about the repository's open Pull Requests, such as:

  1. Number of Pull Requests.
  2. Most productive contributors (i.e. contributors who has more than 1 open PR).
  3. Number of Pull Requests of each contributor with labels of all his/her commits.
  4. Top 10 most discussed Pull Requests.

It uses curl to query the API and jq to parse the data. Script query the data page by page (100 Pull Requests per page) until empty page is returned and then process them. So. if the repo you pass as argument has 80 open Pull Requests, it issue 3 requst to the API, one for first page (PRs from 1 to 80), empty page which shows that the data ends and last requst to get most popular Pull Requests.

Authentication

The script support authentication with GitHub personal token. If you don't provide the username and token You will be limited to 60 requests per hour.

USAGE

./git_get_pulls.sh [LINK_TO_REPOSITORY]
 ./git_get_pulls.sh LINK_TO_REPOSITORY -u AUTH_USERNAME -t AUTH_TOKEN

EXAMPLE OF USAGE

 ./git_get_pulls.sh https://github.com/curl/curl
 ./git_get_pulls.sh https://github.com/vkutas/DevOps-home-tasks
 ./git_get_pulls.sh https://github.com/vkutas/DevOps-home-tasks -u znak -t sdfs4ghklkj23sdf23424fvdfv3g541dsf

NOTE

This script works with open Pull Requests only. Also note that GitHub limit API requests to 60 per hour from IP for unauthenticated clients.

Task 4

Emoji Service

Python service which can provide you with emoji you like.

The service can accept http and https requests with POST and GET methods. POST request receive JSON object of the following format: {"word":"name", "count": n} and returns a string which consists of 'name' repeated 'n' times using emoji which name is equal to the 'name' as delimeter. If there is no emoji with the name 'name', random emoji is used instead.

http POST example:
Request:
curl -X POST -d '{"word":"owl", "count":3}' http://<ip_address>
Response:
🦉owl🦉owl🦉owl🦉

POST https example: Because server uses self-signed SSL certificate, you should use -k flag to ask curl don't verify it:
curl -X POST -k -d '{"word":"dolphin", "count":5}' https://<ip_address>
Response:
🐬dolphin🐬dolphin🐬dolphin🐬dolphin🐬dolphin🐬

or, you can import certificate from them server and tell curl where it located.

WARNING: Don't use mentioned above approach with production servers, only for testing purpose on local machine!

GET http and https request returns greetings page. You can see it in your browser typing server IP in address line.

Project structure

The project comprises the following parts:

  1. emoji-service
    Python flask application, which also uses emoji library to work with emoji.
  2. uWSGI - application server.
    The file wsgi.py is the entry point to the application. The file emojiservice.ini contains uWSGI settings.
  3. Nginx is used to handle http requests. It communicate with uWSGI application server using uwsgi binary protocol through unix socket.
  4. Vagrant is used to manage VM and describe VM configuration as code. This project uses debian/contrib-buster64 - Debian 10 "Buster" image with installed VirtualBox guests additions in order to sync folders and port forwarding works properly.
  5. Ansible is used for configuration management and application deploying.

Directory ansible_provisioning contains all files related to Asible:

  1. hosts.yml - ansible inventory file.
  2. webservers_install_dependencies.yml - playbook to install required dependecies on the server.
  3. webservers_security_config.yml - playbook to apply security rules to the server.
  4. ssl_self_signed.yml - playbook which creates self-signed SSL certificate on the server.
  5. install_nginx.yml - playbook which install and configure nginx
  6. emoji-service_deploy.yml - playbook which deploy emoji service on the server using emojiservice_deploy role.

Usage

To run this project on your machine your need:

  1. Vagrant
  2. VirtualBox as VM provider for Vagrant.
    You can also use another provider which Vagrant supports, such as VMware or Hyper-V, but in this case you will need to make some changes in Vagrantfile
  3. Ansible to run Vagrant provisioners in order to set up environment and deploy aplication.
  4. community.crypto.* Ansible modules to create self-signed certificate. You can install it running:
    ansible-galaxy collection install community.crypto in your teminal.

When you have all dependencies mentioned above:

  1. Clone the repository.
  2. To run the provisioner. you need to create service_user_password:
    2.1. Come up with a strong password.
    2.2. Use mkpasswd command line utilty to get hash of your password, e.g. mkpasswd --method=SHA-512 yourpassword
    2.3. Come up with a strong password for ansible-vault and put it to text file to the ansible_provisioning directory (or any else).
    2.4. Use the following command to encrypt the date from step 2.2:
    ansible-vault encrypt_string --vault-password-file a_password_file 'string_from_step_2.2' --name 'emoji_service_user_password' where a_password_file path to the file with password from ansible vault.
    2.5 Open the emoji-service_deploy.yml and replace the value of emoji_service_user_password variable on ecrypted values from step 2.4.
    2.6. Open Vagrantfile and specify the path to the file with ansible vault password to the ANSIBLE_SERVICE_USER_VAULT_FILE_PATH

Alternatively, you can remove encrypted varible from emoji-service_deploy.yml. The role's defaults will be used instead.

  1. Open project's root directory (directory with Vagrantfile)
  2. Open terminal in this directory.
  3. Run vagrant up command in your terminal.

Vagrant will download VM box from Vagrant Cloud, set up the VM using VirtualBox and then run ansible provision to set up environment and deploy application.
Just after Ansible finish its job, you will see following message:
==> emojiservice: Vanilla Debian box. See https://app.vagrantup.com/debian for help and bug reports
Now you can test the service.

devops-home-tasks's People

Contributors

mataras avatar vkutas avatar

Watchers

 avatar

Forkers

mataras

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.