Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab8 #10

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open

Lab8 #10

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
name: Application CI
name: C++ Application CI

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

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

jobs:
build-and-test:
Expand All @@ -17,7 +19,7 @@ jobs:
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ubuntu-python-${{ hashFiles('app_python/requirements.txt') }}
key: ubuntu-python-${{ hashFiles('app_C++/requirements.txt') }}
restore-keys: |
ubuntu-python-

Expand All @@ -31,16 +33,18 @@ jobs:
- name: Install dependencies and linter
run: |
python -m pip install --upgrade pip
pip install flake8
pip install -r app_python/requirements.txt
pip install -r app_C++/requirements.txt
sudo apt update
sudo apt install cppcheck wget
sudo mkdir -p /usr/local/include && sudo wget https://raw.githubusercontent.com/yhirose/cpp-httplib/master/httplib.h -O /usr/local/include/httplib.h

- name: Lint with flake8
- name: Lint with Cppcheck
run: |
flake8 app_python/app.py
cppcheck app_C++/app.cpp

- name: Run tests
run: |
python app_python/unittests.py
cd app_C++ && python unittests.py

- name: Login to Docker Hub
uses: docker/login-action@v2
Expand All @@ -52,18 +56,24 @@ jobs:
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ubuntu-docker-${{ hashFiles('app_python/Dockerfile') }}
key: ubuntu-docker-${{ hashFiles('app_C++/Dockerfile') }}
restore-keys: |
ubuntu-docker-

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: app_python
context: app_C++
push: true
tags: ${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }}

- name: Run snyk
uses: snyk/actions/python-3.10@master
- name: Install snyk
run: npm install -g snyk

- name: Run snyk
run: |
cd app_C++
snyk test
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
terraform/key.json
*.terraform*
*terraform.tfstate
ansible/roles/geerlingguy.docker/
*__pycache__*
ansible/inventory/token
145 changes: 145 additions & 0 deletions ansible/ANSIBLE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Lab 5

## Outputs

- `ansible-playbook playbooks/dev/main.yaml --check`
```
PLAY [Deploy Docker on VM in Yandex Cloud] *************************************************************************

TASK [Gathering Facts] *********************************************************************************************
fatal: [yandex_cloud_devops_lab4_vm]: FAILED! => {"msg": "The field 'remote_addr' has an invalid value, which includes an undefined variable.. 'dynamic_ip' is undefined"}

PLAY RECAP *********************************************************************************************************
yandex_cloud_devops_lab4_vm : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
```

- `ansible-playbook playbooks/dev/main.yaml -e "dynamic_ip=89.169.159.227"`
```

PLAY [Deploy Docker on VM in Yandex Cloud] *************************************

TASK [Gathering Facts] *********************************************************
[WARNING]: Platform linux on host yandex_cloud_devops_lab4_vm is using the
discovered Python interpreter at /usr/bin/python3.12, but future installation
of another Python interpreter could change the meaning of that path. See
https://docs.ansible.com/ansible-
core/2.18/reference_appendices/interpreter_discovery.html for more information.
ok: [yandex_cloud_devops_lab4_vm]

TASK [docker : include_tasks] **************************************************
included: /home/VM/User/Learning/Program/DOE/S25-core-course-labs/ansible/roles/docker/tasks/install_docker.yml for yandex_cloud_devops_lab4_vm

TASK [docker : Add GPG key] ****************************************************
ok: [yandex_cloud_devops_lab4_vm]

TASK [docker : Set up the Docker repository] ***********************************
ok: [yandex_cloud_devops_lab4_vm]

TASK [docker : Install Docker CE] **********************************************
ok: [yandex_cloud_devops_lab4_vm]

TASK [docker : include_tasks] **************************************************
included: /home/VM/User/Learning/Program/DOE/S25-core-course-labs/ansible/roles/docker/tasks/install_compose.yml for yandex_cloud_devops_lab4_vm

TASK [docker : Install docker-compose] *****************************************
ok: [yandex_cloud_devops_lab4_vm]

TASK [docker : include_tasks] **************************************************
included: /home/VM/User/Learning/Program/DOE/S25-core-course-labs/ansible/roles/docker/tasks/docker_enable.yml for yandex_cloud_devops_lab4_vm

TASK [docker : Enable Docker service to start on boot] *************************
ok: [yandex_cloud_devops_lab4_vm]

TASK [docker : include_tasks] **************************************************
included: /home/VM/User/Learning/Program/DOE/S25-core-course-labs/ansible/roles/docker/tasks/add_user_to_group.yml for yandex_cloud_devops_lab4_vm

TASK [docker : Add the current user to the docker group] ***********************
ok: [yandex_cloud_devops_lab4_vm]

PLAY RECAP *********************************************************************
yandex_cloud_devops_lab4_vm : ok=11 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0


```

- `ansible-inventory -i inventory/default_yandex_cloud.yml --list`
```
{
"_meta": {
"hostvars": {
"yandex_cloud_devops_lab4_vm": {
"ansible_host": "{{ dynamic_ip }}",
"ansible_ssh_private_key_file": "/home/VM/.ssh/yandex_cloud_vm",
"ansible_user": "user"
}
}
},
"all": {
"children": [
"ungrouped"
]
},
"ungrouped": {
"hosts": [
"yandex_cloud_devops_lab4_vm"
]
}
}
```

- `ansible-inventory -i inventory/default_yandex_cloud.yml --graph`
```
@all:
|--@ungrouped:
| |--yandex_cloud_devops_lab4_vm
```

### Bonus task

- `ansible-playbook playbooks/dev/main.yaml -e "dynamic_ip=158.160.41.38"`
```
TASK [docker : Modify daemon to disable root access] ***************************************************************
changed: [yandex_cloud_devops_lab4_vm]

TASK [docker : Restart docker.service to apply changes] ************************************************************
changed: [yandex_cloud_devops_lab4_vm]

PLAY RECAP *********************************************************************************************************
yandex_cloud_devops_lab4_vm : ok=14 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```

# Lab 6

## Outputs

- `ansible-playbook playbooks/dev/main.yaml`
```
(venv) [VM@LVM ansible]$ ansible-playbook playbooks/dev/main.yaml

PLAY [Deploy Docker on VM in Yandex Cloud] *************************************************************************

TASK [Gathering Facts] *********************************************************************************************
[WARNING]: Platform linux on host devops_lab4_vm is using the discovered Python interpreter at /usr/bin/python3.12,
but future installation of another Python interpreter could change the meaning of that path. See
https://docs.ansible.com/ansible-core/2.18/reference_appendices/interpreter_discovery.html for more information.
ok: [devops_lab4_vm]

TASK [web_app : include_tasks] *************************************************************************************
included: /home/VM/User/Learning/Program/DOE/S25-core-course-labs/ansible/roles/web_app/tasks/pull_image.yml for devops_lab4_vm

TASK [web_app : Pull docker image from Docker Hub] *****************************************************************
ok: [devops_lab4_vm]

TASK [web_app : include_tasks] *************************************************************************************
included: /home/VM/User/Learning/Program/DOE/S25-core-course-labs/ansible/roles/web_app/tasks/start_container.yml for devops_lab4_vm

TASK [web_app : Start container] ***********************************************************************************
changed: [devops_lab4_vm]

PLAY RECAP *********************************************************************************************************
devops_lab4_vm : ok=5 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
E0000 00:00:1739903906.085356 13756 init.cc:232] grpc_wait_for_shutdown_with_timeout() timed out.

```
6 changes: 6 additions & 0 deletions ansible/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[defaults]
inventory = inventory/yacloud_compute.yml
playbook_dir = playbooks/
roles_path = ./roles
inventory_plugins = inventory/plugins/
enable_plugins = yacloud_compute.py
Empty file.
6 changes: 6 additions & 0 deletions ansible/inventory/default_yandex_cloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
all:
hosts:
yandex_cloud_devops_lab4_vm:
ansible_host: "{{ dynamic_ip }}" # We need to set up it manually in `ansible-playbook playbooks/dev/main.yaml -e "dynamic_ip=<current_ip_address>"`, since it is dinamyc
ansible_user: user
ansible_ssh_private_key_file: /home/VM/.ssh/yandex_cloud_vm
Loading