diff --git a/Dockerfile b/Dockerfile index d68b868d6..c4dd4eacf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,5 +2,9 @@ FROM python:3.12-slim # Ваш код здесь # +WORKDIR /app +COPY requirements.txt ./ +RUN pip install -r requirements.txt +COPY main.py ./ # Запускаем приложение с помощью uvicorn, делая его доступным по сети -CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "5000"] \ No newline at end of file +CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "5000"] diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 000000000..fe2c56752 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,37 @@ +version: '3.7' +include: + - proxy.yaml + +volumes: + db_mysql: + +services: + + db: + image: mysql:8 + restart: on-failure + env_file: + - .env + volumes: + - /var/lib/docker/volumes/db_mysql/_data:/var/lib/mysql + ports: + - 3306:3306 + networks: + backend: + ipv4_address: 172.20.0.10 + + web: + build: + dockerfile: Dockerfile + restart: on-failure + environment: +- MYSQL_ROOT_PASSWORD: YtReWq4321 +- MYSQL_DATABASE: virtd +- MYSQL_USER: app +- MYSQL_PASSWORD: QwErTy1234" + + depends_on: + - db + networks: + backend: + ipv4_address: 172.20.0.5 diff --git a/lighthouse-role-main/README.md b/lighthouse-role-main/README.md new file mode 100644 index 000000000..31dd41933 --- /dev/null +++ b/lighthouse-role-main/README.md @@ -0,0 +1,9 @@ +Роли + +| Name | Default Value | Description | +|----------------------------|-----------------------------------------|-----------------| +| lighthouse_vcs | https://github.com/VKCOM/lighthouse.git | Ресурс для скачивания | +| lighthouse_location_dir | /var/www/lighthouse | Инсталяция патча | +| lighthouse_access_log_name | lighthouse | Наименование в логах | +| nginx_user_name | nginx | Имя Nginx | + diff --git a/lighthouse-role-main/defaults/main.yml b/lighthouse-role-main/defaults/main.yml new file mode 100644 index 000000000..2a92592a7 --- /dev/null +++ b/lighthouse-role-main/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for lighthouse-role diff --git a/lighthouse-role-main/handlers/main.yml b/lighthouse-role-main/handlers/main.yml new file mode 100644 index 000000000..858ebca7e --- /dev/null +++ b/lighthouse-role-main/handlers/main.yml @@ -0,0 +1,7 @@ +--- +- name: restart-nginx + ansible.builtin.service: + name: nginx + state: restarted + become: true + become_method: sudo diff --git a/lighthouse-role-main/meta/main.yml b/lighthouse-role-main/meta/main.yml new file mode 100644 index 000000000..c572acc9f --- /dev/null +++ b/lighthouse-role-main/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/lighthouse-role-main/tasks/main.yml b/lighthouse-role-main/tasks/main.yml new file mode 100644 index 000000000..54e932a6a --- /dev/null +++ b/lighthouse-role-main/tasks/main.yml @@ -0,0 +1,23 @@ +--- +- name: Create Lighthouse directory + become: true + ansible.builtin.file: + path: /var/www/lighthouse + state: directory + recurse: yes + mode: '0755' + owner: nginx + group: nginx +- name: Lighthouse | Clone from Git + become: true + ansible.builtin.git: + repo: "{{ lighthouse_vcs }}" + version: master + dest: "{{ lighthouse_location_dir }}" +- name: Lighthouse | Create lighthouse config + become: true + ansible.builtin.template: + src: templates/lighthouse.conf.j2 + dest: /etc/nginx/conf.d/default.conf + mode: '0644' + notify: restart-nginx diff --git a/lighthouse-role-main/templates/lighthouse.conf.j2 b/lighthouse-role-main/templates/lighthouse.conf.j2 new file mode 100644 index 000000000..c666a90dc --- /dev/null +++ b/lighthouse-role-main/templates/lighthouse.conf.j2 @@ -0,0 +1,11 @@ +server { + listen 80; + server_name localhost; + + access_log /var/log/nginx/{{ lighthouse_access_log_name }}.log main; + + location / { + root {{ lighthouse_location_dir }}; + index index.html; + } +} \ No newline at end of file diff --git a/lighthouse-role-main/tests/inventory b/lighthouse-role-main/tests/inventory new file mode 100644 index 000000000..878877b07 --- /dev/null +++ b/lighthouse-role-main/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/lighthouse-role-main/tests/test.yml b/lighthouse-role-main/tests/test.yml new file mode 100644 index 000000000..a6f999fc8 --- /dev/null +++ b/lighthouse-role-main/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - lighthouse-role diff --git a/lighthouse-role-main/vars/main.yml b/lighthouse-role-main/vars/main.yml new file mode 100644 index 000000000..68235c344 --- /dev/null +++ b/lighthouse-role-main/vars/main.yml @@ -0,0 +1,5 @@ +--- +lighthouse_vcs: "https://github.com/VKCOM/lighthouse.git" +lighthouse_location_dir: /var/www/lighthouse +lighthouse_access_log_name: lighthouse +nginx_user_name: nginx \ No newline at end of file diff --git a/scr/.gitignore b/scr/.gitignore new file mode 100644 index 000000000..bbf86604b --- /dev/null +++ b/scr/.gitignore @@ -0,0 +1,12 @@ +# Local .terraform directories and files +**/.terraform/* +.terraform* + +!.terraformrc + +# .tfstate files +*.tfstate +*.tfstate.* + +# own secret vars store. +personal.auto.tfvars diff --git a/scr/.terraformrc b/scr/.terraformrc new file mode 100644 index 000000000..17415e3e0 --- /dev/null +++ b/scr/.terraformrc @@ -0,0 +1,9 @@ +provider_installation { + network_mirror { + url = "https://terraform-mirror.yandexcloud.net/" + include = ["registry.terraform.io/*/*"] + } + direct { + exclude = ["registry.terraform.io/*/*"] + } +} diff --git a/scr/console.tf b/scr/console.tf new file mode 100644 index 000000000..e5b888ed4 --- /dev/null +++ b/scr/console.tf @@ -0,0 +1,31 @@ +##Этот файл для 7 задания!! +locals { + + test_list = ["develop", "staging", "production"] + + test_map = { + admin = "John" + user = "Alex" + } + + servers = { + develop = { + cpu = 2 + ram = 4 + image = "ubuntu-21-10" + disks = ["vda", "vdb"] + }, + stage = { + cpu = 4 + ram = 8 + image = "ubuntu-20-04" + disks = ["vda", "vdb"] + }, + production = { + cpu = 10 + ram = 40 + image = "ubuntu-20-04" + disks = ["vda", "vdb", "vdc", "vdd"] + } + } +} diff --git a/scr/locals.tf b/scr/locals.tf new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/scr/locals.tf @@ -0,0 +1 @@ + diff --git a/scr/main.tf b/scr/main.tf new file mode 100644 index 000000000..49baf600a --- /dev/null +++ b/scr/main.tf @@ -0,0 +1,41 @@ +resource "yandex_vpc_network" "develop" { + name = var.vpc_name +} +resource "yandex_vpc_subnet" "develop" { + name = var.vpc_name + zone = var.default_zone + network_id = yandex_vpc_network.develop.id + v4_cidr_blocks = var.default_cidr +} + + +data "yandex_compute_image" "ubuntu" { + family = "ubuntu-2004-lts" +} +resource "yandex_compute_instance" "platform" { + name = "netology-develop-platform-web" + platform_id = "standart-v4" + resources { + cores = 1 + memory = 1 + core_fraction = 5 + } + boot_disk { + initialize_params { + image_id = data.yandex_compute_image.ubuntu.image_id + } + } + scheduling_policy { + preemptible = true + } + network_interface { + subnet_id = yandex_vpc_subnet.develop.id + nat = true + } + + metadata = { + serial-port-enable = 1 + ssh-keys = "ubuntu:${var.vms_ssh_root_key}" + } + +} diff --git a/scr/providers.tf b/scr/providers.tf new file mode 100644 index 000000000..c287aa1a6 --- /dev/null +++ b/scr/providers.tf @@ -0,0 +1,16 @@ +terraform { + required_providers { + yandex = { + source = "yandex-cloud/yandex" + } + } + required_version = ">=1.5" +} + +provider "yandex" { + # token = var.token + cloud_id = "b1gk34aj8huam4c6qc65" + folder_id = "b1groq7lioh1rbih3b87" + zone = "ru-central1-a" + service_account_key_file = file("~/.authorized_key.json") +} diff --git a/scr/variables.tf b/scr/variables.tf new file mode 100644 index 000000000..36ca23421 --- /dev/null +++ b/scr/variables.tf @@ -0,0 +1,38 @@ +###cloud vars + + +variable "cloud_id" { + type = string + description = "https://cloud.yandex.ru/docs/resource-manager/operations/cloud/get-id" +} + +variable "folder_id" { + type = string + description = "https://cloud.yandex.ru/docs/resource-manager/operations/folder/get-id" +} + +variable "default_zone" { + type = string + default = "ru-central1-a" + description = "https://cloud.yandex.ru/docs/overview/concepts/geo-scope" +} +variable "default_cidr" { + type = list(string) + default = ["10.0.1.0/24"] + description = "https://cloud.yandex.ru/docs/vpc/operations/subnet-create" +} + +variable "vpc_name" { + type = string + default = "develop" + description = "VPC network & subnet name" +} + + +###ssh vars + +variable "vms_ssh_root_key" { + type = string + default = "ssh-ed25519ssh-ed25519 roRitedX9AABWbmxLpX8vBtRrMXpyTY8r2RKCc/AIjg flid@devopsserver" + description = "ssh-keygen -t ed25519" +} diff --git a/vector-role-main/README.md b/vector-role-main/README.md new file mode 100644 index 000000000..91677f9fa --- /dev/null +++ b/vector-role-main/README.md @@ -0,0 +1,13 @@ +##Роли +========= + + +| Name | Default Value | Description | +|-------------------|---------------------------------------------------------------------|--------------------------------| +| vector_url | https://packages.timber.io/vector/0.33.1/vector-0.33.1-1.x86_64.rpm | Для скачивания | +| vector_config_dir | /etc/vector | Установленный патч | +| data_dir | /var/lib/vector | Директория для Vector | +| sources | | Конфигурация Vector | +| sinks | | Подключение к clickhouse | + + diff --git a/vector-role-main/defaults/main.yml b/vector-role-main/defaults/main.yml new file mode 100644 index 000000000..78ae8528b --- /dev/null +++ b/vector-role-main/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for vector-role diff --git a/vector-role-main/handlers/main.yml b/vector-role-main/handlers/main.yml new file mode 100644 index 000000000..b4121fd13 --- /dev/null +++ b/vector-role-main/handlers/main.yml @@ -0,0 +1,8 @@ +--- +- name: vector_start + become: true + become_method: sudo + ansible.builtin.systemd: + name: vector + state: started + daemon_reload: true \ No newline at end of file diff --git a/vector-role-main/meta/main.yml b/vector-role-main/meta/main.yml new file mode 100644 index 000000000..c572acc9f --- /dev/null +++ b/vector-role-main/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/vector-role-main/tasks/main.yml b/vector-role-main/tasks/main.yml new file mode 100644 index 000000000..dba4f5111 --- /dev/null +++ b/vector-role-main/tasks/main.yml @@ -0,0 +1,18 @@ +--- +- name: Vector | Install RPM + become: true + ansible.builtin.yum: + name: "{{ vector_url }}" + state: present +- name: Vector | Template file + ansible.builtin.template: + src: vector.yml.j2 + dest: vector.yml + mode: '0644' +- name: Vector | Create Vector service + become: true + ansible.builtin.template: + src: vector.service.j2 + dest: /etc/systemd/system/vector.service + mode: '0644' + notify: vector_start diff --git a/vector-role-main/templates/vector.service.j2 b/vector-role-main/templates/vector.service.j2 new file mode 100644 index 000000000..9d54be7db --- /dev/null +++ b/vector-role-main/templates/vector.service.j2 @@ -0,0 +1,10 @@ +[Unit] +Description=Vector Service +After=network.target +Requires=network-online.target +[Service] +User={{ ansible_user_id }} +Group={{ ansible_user_gid }} +ExecStart=/usr/bin/vector --config-yaml {{ vector_config_dir }}/vector.yml --watch-config true +Restart=always +WantedBy=multi-user.target% \ No newline at end of file diff --git a/vector-role-main/templates/vector.yml.j2 b/vector-role-main/templates/vector.yml.j2 new file mode 100644 index 000000000..c46abdd22 --- /dev/null +++ b/vector-role-main/templates/vector.yml.j2 @@ -0,0 +1,45 @@ +#TEST config from Ansible +# __ __ __ +# \ \ / / / / +# \ V / / / +# \_/ \/ +# +# V E C T O R +# Configuration +# +# ------------------------------------------------------------------------------ +# Website: https://vector.dev +# Docs: https://vector.dev/docs +# Chat: https://chat.vector.dev +# ------------------------------------------------------------------------------ + +# Change this to use a non-default directory for Vector data storage: +# data_dir = "/var/lib/vector" + +# Random Syslog-formatted logs +[sources.dummy_logs] +type = "demo_logs" +format = "syslog" +interval = 1 + +# Parse Syslog logs +# See the Vector Remap Language reference for more info: https://vrl.dev +[transforms.parse_logs] +type = "remap" +inputs = ["dummy_logs"] +source = ''' +. = parse_syslog!(string!(.message)) +''' + +# Print parsed logs to stdout +[sinks.print] +type = "console" +inputs = ["parse_logs"] +encoding.codec = "json" + +# Vector's GraphQL API (disabled by default) +# Uncomment to try it out with the `vector top` command or +# in your browser at http://localhost:8686 +#[api] +#enabled = true +#address = "127.0.0.1:8686" \ No newline at end of file diff --git a/vector-role-main/tests/inventory b/vector-role-main/tests/inventory new file mode 100644 index 000000000..878877b07 --- /dev/null +++ b/vector-role-main/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/vector-role-main/tests/test.yml b/vector-role-main/tests/test.yml new file mode 100644 index 000000000..8f0cc7425 --- /dev/null +++ b/vector-role-main/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - vector-role diff --git a/vector-role-main/vars/main.yml b/vector-role-main/vars/main.yml new file mode 100644 index 000000000..79f2a85fc --- /dev/null +++ b/vector-role-main/vars/main.yml @@ -0,0 +1,22 @@ +--- +vector_url: "https://packages.timber.io/vector/0.33.1/vector-0.33.x86_64.rpm" +vector_config_dir: "/etc/vector" +data_dir: "/var/lib/vector" +sources: + our_log: + type: file + include: + - "/home/cloud-user/logs/*.log" + ignore_older: 800 + read_from: beginning +sinks: + to_clickhouse: + inputs: + - our_log + type: clickhouse + database: logs + table: my_table + endpoints: "http://168.110.153.235:8125" + healthcheck: false + compression: gzip + skip_unknown_fields: true