Skip to content

SMore-Napi/DevOps_Innopolis

 
 

Repository files navigation

DevOps course at Innopolis University

Semester 7, 4th study year

Python CI workflow Kotlin CI workflow

Contents

Overview

This is a simple web application that shows the Moscow time each time when you refresh a page. The application was developed in two programming languages:

Build

Download

  • Open your terminal
  • git clone https://github.com/SMore-Napi/DevOps_Innopolis.git
  • cd DevOps_Innopolis
  • git checkout lab14

Python build

Installation

  • All required dependencies are stored in the requirements.txt file.
  • Open your terminal.
  • Go to the app_python folder: cd app_python
  • pip install -r requirements.txt

Running

  • Open your terminal
  • Go to the app_python folder: cd app_python/app
  • Run application: uvicorn main:app --reload

Kotlin build

  • Install JDK
  • Install Gradle
  • Open your terminal
  • Go to the app_kotlin folder: cd app_kotlin
  • Run application: ./gradlew bootRun

Docker

  • You can skip the Build part and avoid installing packages. Instead, run the docker image. Preliminarily, you should build or pull this image.

Python image

Build Python image

  • Open your terminal. Your directory should be the root: pwd: /DevOps_Innopolis
  • Build image: docker build -t app_python_image app_python
    • app_python_image - image name. You can change it whatever you want.
    • app_python - the folder in which the Dockerfile is placed.

    In case you are already in the /app_python folder, you can use this command docker build -t app_python_image .

Pull Python image

  • In case you don't want to build an image, you can pull the already pushed image in the docker hub: app_python
  • Run docker pull smorenapi/app_python:latest
Small instruction on how to push an image
  • Assign image name: docker image tag app_python_image:latest <login>/app_python:latest
  • Push: docker image push <login>/app_python:latest

Use your docker hub login instead of <login>

Run Python image

  • You need a built or pulled image.
  • Run image: docker run --rm -p 8000:8000 --name app_python <app_python_image>
    • --rm automatically remove the container when it exits. You can omit this parameter.
    • -p expose port 8000.
    • --name - container name. You can specify any name you'd like.
    • <app_python_image> - image name.
      • Use app_python_image if you built your own image.
      • Use smorenapi/app_python:latest if you pulled the image from my repository
    • You can also include -d to run a container in the background (detached mode).

Kotlin image

Build Kotlin image

  • Open your terminal. Your directory should be the root: pwd: /DevOps_Innopolis
  • Build image: docker build -t app_kotlin_image app_kotlin
    • app_kotlin_image - image name. You can change it whatever you want.
    • app_kotlin - the folder in which the Dockerfile is placed.

      In case you are already in the /app_kotlin folder, you can use this command docker build -t app_kotlin_image .

Pull Kotlin image

  • In case you don't want to build an image, you can pull the already pushed image in the docker hub: app_kotlin
  • Run docker pull smorenapi/app_kotlin:latest

Run Kotlin image

  • You need a built or pulled image.
  • Run image: docker run --rm -p 8080:8080 --name app_kotlin <app_kotlin_image>
    • --rm automatically remove the container when it exits. You can omit this parameter.
    • -p expose port 8080.
    • --name - container name. You can specify any name you'd like.
    • <app_kotlin_image> - image name.
      • Use app_kotlin_image if you built your own image.
      • Use smorenapi/app_kotlin:latest if you pulled the image from my repository
    • You can also include -d to run a container in the background (detached mode).

Usage

Python usage

  • Run the application and open this URL in your browser: http://127.0.0.1:8000
  • Each time when you refresh a page you will see the actual Moscow time

Web App

Web App Healthcheck

Kotlin usage

  • Run the application and open this URL in your browser: http://127.0.0.1:8080
  • Each time when you refresh a page you will see the actual Moscow time

Web App

Web App Healthcheck

Unit tests

  • Right now there are unit tests that check the Moscow Time retrieving: time interval (that time is really updated each second) and HTML web page content.

Run Python tests

Run Kotlin tests

  • cd app_kotlin
  • ./gradlew detekt

Linters

  • to check markdown files I used Markdown lint tool
    • Install: rake install
    • Check: mdl ../DevOps_Innopolis (will argue on Labs files)

CI

  • I used GitHub Actions for the Continuous integration

Python CI

  • Workflow is described in python_ci.yml
  • It runs python build:
    • Download dependencies.
    • Run linter.
    • Run tests.
  • Then checks for vulnerabilities.
  • Finally, uploads Docker image to docker hub.

Kotlin CI

  • Workflow is described in kotlin_ci.yml
  • Firstly, we set up JDK 17.
  • Then run gradle build which includes tasks:
    • Download dependencies.
    • Run detekt linter.
    • Run unit tests.
  • Then checks for vulnerabilities. Snyk might show warnings since there are new vulnerabilities which can be fixed right now because there are no library updates.
  • Finally, uploads Docker image to docker hub.

Contact

About

Labs from DevOps course

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • Kotlin 30.8%
  • Python 20.1%
  • Smarty 19.8%
  • HCL 18.9%
  • Dockerfile 7.8%
  • Jinja 2.6%