Skip to content

Commit

Permalink
Adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
VoronM1522 committed Feb 15, 2025
1 parent 0e2e1d6 commit e38da0d
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 2 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/C++_app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: C++ Application CI

on:
push:
paths:
'app_C\+\+/**'

env:
USERNAME: voronm1522
DOCKER_IMAGE: voronm1522/devops
DOCKER_TAG: cpp-app

jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
- name: Cache python
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ubuntu-python-${{ hashFiles('app_C++/requirements.txt') }}
restore-keys: |
ubuntu-python-
- uses: actions/checkout@v3

- name: Set up python
uses: actions/setup-python@v3
with:
python-version: '3.10'

- name: Install dependencies and linter
run: |
python -m pip install --upgrade pip
pip install -r app_C++/requirements.txt
sudo apt update
sudo apt install cppcheck
- name: Lint with Cppcheck
run: |
cppcheck app_C++/app.cpp
- name: Run tests
run: |
python app_C++/unittests.py
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ env.USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ubuntu-docker-${{ hashFiles('app_python/Dockerfile') }}
restore-keys: |
ubuntu-docker-
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: app_python
push: true
tags: ${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }}

- name: Install snyk
run: npm install -g snyk

- name: Run snyk
run: |
cd app_C++
snyk test
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}

4 changes: 3 additions & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: Application CI
name: Python Application CI

on:
push:
paths:
- "app_python/**"

env:
USERNAME: voronm1522
Expand Down
7 changes: 6 additions & 1 deletion app_C++/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ docker pull voronm1522/devops:cpp-app

To run image run:
```
docker run <name>
docker run <name>
```

## CI

[![C++ Application CI](https://github.com/VoronM1522/S25-core-course-labs/actions/workflows/C++_app.yml/badge.svg?branch=lab3)](https://github.com/VoronM1522/S25-core-course-labs/actions/workflows/C++_app.yml)
5 changes: 5 additions & 0 deletions app_C++/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
certifi==2025.1.31
charset-normalizer==3.4.1
idna==3.10
requests==2.32.3
urllib3==2.3.0
34 changes: 34 additions & 0 deletions app_C++/unittests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import unittest, subprocess, time, requests, os

SERVER="http://127.0.0.1:8080/"

class TestServer(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.server_process = subprocess.Popen(["./server"])
time.sleep(2)

@classmethod
def tearDownClass(cls):
cls.server_process.terminate()
cls.server_process.wait()

def test_response_status_code(self):
response = requests.get(SERVER)
self.assertEqual(response.status_code, 200)

def test_response_format(self):
response = requests.get(SERVER)
self.assertTrue(response.text.startswith("Random number is: "))

number_str = response.text[len("Random number is: "):]
self.assertTrue(number_str.isdigit())

if __name__ == "__main__":
os.system("g++ app.cpp -o server")

try:
unittest.main()
finally:
if os.path.exists("server"):
os.remove("server")

0 comments on commit e38da0d

Please sign in to comment.