From 2b874272991a98c53423bf2464df31343116768d Mon Sep 17 00:00:00 2001 From: Inohara Date: Tue, 24 Sep 2024 16:55:37 +0400 Subject: [PATCH 1/4] =?UTF-8?q?=D1=87=D1=82=D0=BE-=D1=82=D0=BE=20=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tsukanova_irina_lab_2/.gitignore | 2 ++ tsukanova_irina_lab_2/docker-compose.yaml | 17 ++++++++++++++ tsukanova_irina_lab_2/result/data.txt | 1 + tsukanova_irina_lab_2/worker-1/Dockerfile | 11 +++++++++ tsukanova_irina_lab_2/worker-1/worker_1.py | 27 ++++++++++++++++++++++ tsukanova_irina_lab_2/worker-2/Dockerfile | 11 +++++++++ tsukanova_irina_lab_2/worker-2/worker_2.py | 19 +++++++++++++++ 7 files changed, 88 insertions(+) create mode 100644 tsukanova_irina_lab_2/.gitignore create mode 100644 tsukanova_irina_lab_2/docker-compose.yaml create mode 100644 tsukanova_irina_lab_2/result/data.txt create mode 100644 tsukanova_irina_lab_2/worker-1/Dockerfile create mode 100644 tsukanova_irina_lab_2/worker-1/worker_1.py create mode 100644 tsukanova_irina_lab_2/worker-2/Dockerfile create mode 100644 tsukanova_irina_lab_2/worker-2/worker_2.py diff --git a/tsukanova_irina_lab_2/.gitignore b/tsukanova_irina_lab_2/.gitignore new file mode 100644 index 0000000..0196882 --- /dev/null +++ b/tsukanova_irina_lab_2/.gitignore @@ -0,0 +1,2 @@ +/.venv +/.idea diff --git a/tsukanova_irina_lab_2/docker-compose.yaml b/tsukanova_irina_lab_2/docker-compose.yaml new file mode 100644 index 0000000..86991f2 --- /dev/null +++ b/tsukanova_irina_lab_2/docker-compose.yaml @@ -0,0 +1,17 @@ +services: + worker_one: + container_name: worker_one + build: + context: ./worker-1 + volumes: + - ./data:/var/data + - ./result:/var/result + + worker_two: + container_name: worker_two + build: + context: ./worker-2 + depends_on: + - worker_one + volumes: + - ./result:/var/result \ No newline at end of file diff --git a/tsukanova_irina_lab_2/result/data.txt b/tsukanova_irina_lab_2/result/data.txt new file mode 100644 index 0000000..cb69abd --- /dev/null +++ b/tsukanova_irina_lab_2/result/data.txt @@ -0,0 +1 @@ +5 34 7 9 6 43 5 768 4 23 1 3 657 534 4 3 87 6 9 8 56 37 525 5 7 3 2 65 4 86 7 295 473 254 633 4 45 2 \ No newline at end of file diff --git a/tsukanova_irina_lab_2/worker-1/Dockerfile b/tsukanova_irina_lab_2/worker-1/Dockerfile new file mode 100644 index 0000000..585db02 --- /dev/null +++ b/tsukanova_irina_lab_2/worker-1/Dockerfile @@ -0,0 +1,11 @@ +# Использую базовый образ Python +FROM python:3.12-slim + +# Устанавливаю рабочую директорию внутри контейнера +WORKDIR /app + +# Копирую все файлы в контейнер +COPY worker_1.py . + +# Команда для запуска Python-скрипта +CMD ["python", "worker_1.py"] diff --git a/tsukanova_irina_lab_2/worker-1/worker_1.py b/tsukanova_irina_lab_2/worker-1/worker_1.py new file mode 100644 index 0000000..3cb493f --- /dev/null +++ b/tsukanova_irina_lab_2/worker-1/worker_1.py @@ -0,0 +1,27 @@ +import os +import shutil + +# Ищет в каталоге /var/data самый большой по объёму файл и перекладывает его в /var/result/data.txt. +print("start one") +dir_data = "/var/data" +dir_res = "/var/result" + +if not os.path.exists(dir_data): + os.mkdir(dir_data) + +if not os.path.exists(dir_res): + os.mkdir(dir_res) + +largest_file = None +largest_size = 0 + +for root, dirs, files in os.walk(dir_data): + for file in files: + file_path = os.path.join(root, file) + file_size = os.path.getsize(file_path) + if file_size > largest_size: + largest_size = file_size + largest_file = file_path + +if largest_file: + shutil.copyfile(largest_file, dir_res + "/data.txt") diff --git a/tsukanova_irina_lab_2/worker-2/Dockerfile b/tsukanova_irina_lab_2/worker-2/Dockerfile new file mode 100644 index 0000000..360f8ec --- /dev/null +++ b/tsukanova_irina_lab_2/worker-2/Dockerfile @@ -0,0 +1,11 @@ +# Использую базовый образ Python +FROM python:3.12-slim + +# Устанавливаю рабочую директорию внутри контейнера +WORKDIR /app + +# Копирую все файлы в контейнер +COPY worker_2.py . + +# Команда для запуска Python-скрипта +CMD ["python", "worker_2.py"] diff --git a/tsukanova_irina_lab_2/worker-2/worker_2.py b/tsukanova_irina_lab_2/worker-2/worker_2.py new file mode 100644 index 0000000..9bfdb95 --- /dev/null +++ b/tsukanova_irina_lab_2/worker-2/worker_2.py @@ -0,0 +1,19 @@ +# Сохраняет произведение первого и последнего числа из файла /var/result/data.txt в /var/result/result.txt. + +print("start two") + +with open('/var/result/data.txt', 'r') as f: + numbers = [int(num) for num in f.read().split() if num.isdigit()] + +if numbers: + first_number = numbers[0] + last_number = numbers[-1] + + result = first_number * last_number + + with open('/var/result/result.txt', 'w') as f: + f.write(f"{result}\n") + + print(f"Получен результат - {result}") +else: + print("Результат не получен. Файл не содержит чисел") From 5047b16cde56d2d8f25741566ff41d1c89ab22d6 Mon Sep 17 00:00:00 2001 From: Inohara Date: Tue, 24 Sep 2024 16:56:39 +0400 Subject: [PATCH 2/4] files --- tsukanova_irina_lab_2/data/file_1.txt | 1 + tsukanova_irina_lab_2/data/file_2.txt | 1 + tsukanova_irina_lab_2/data/file_3.txt | 1 + 3 files changed, 3 insertions(+) create mode 100644 tsukanova_irina_lab_2/data/file_1.txt create mode 100644 tsukanova_irina_lab_2/data/file_2.txt create mode 100644 tsukanova_irina_lab_2/data/file_3.txt diff --git a/tsukanova_irina_lab_2/data/file_1.txt b/tsukanova_irina_lab_2/data/file_1.txt new file mode 100644 index 0000000..f74e918 --- /dev/null +++ b/tsukanova_irina_lab_2/data/file_1.txt @@ -0,0 +1 @@ +34 905 63 92 74 9 3 25 8 0 2 4 24 452 94 6 2 4 2 65 83 73 672 47 23 21 1 \ No newline at end of file diff --git a/tsukanova_irina_lab_2/data/file_2.txt b/tsukanova_irina_lab_2/data/file_2.txt new file mode 100644 index 0000000..85c06ca --- /dev/null +++ b/tsukanova_irina_lab_2/data/file_2.txt @@ -0,0 +1 @@ +4 9 6 320 75 348 12 75 94 63 45 23 3 \ No newline at end of file diff --git a/tsukanova_irina_lab_2/data/file_3.txt b/tsukanova_irina_lab_2/data/file_3.txt new file mode 100644 index 0000000..cb69abd --- /dev/null +++ b/tsukanova_irina_lab_2/data/file_3.txt @@ -0,0 +1 @@ +5 34 7 9 6 43 5 768 4 23 1 3 657 534 4 3 87 6 9 8 56 37 525 5 7 3 2 65 4 86 7 295 473 254 633 4 45 2 \ No newline at end of file From 780b4b2924c46f6f0c7862eed3bc45365586e3e9 Mon Sep 17 00:00:00 2001 From: HellsSenju Date: Wed, 25 Sep 2024 10:51:07 +0400 Subject: [PATCH 3/4] add readme and fix --- tsukanova_irina_lab_2/README.md | 16 ++++++++++++++++ tsukanova_irina_lab_2/docker-compose.yaml | 11 ++++++----- tsukanova_irina_lab_2/result/result.txt | 1 + tsukanova_irina_lab_2/worker-1/worker_1.py | 2 +- tsukanova_irina_lab_2/worker-2/worker_2.py | 2 +- 5 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 tsukanova_irina_lab_2/README.md create mode 100644 tsukanova_irina_lab_2/result/result.txt diff --git a/tsukanova_irina_lab_2/README.md b/tsukanova_irina_lab_2/README.md new file mode 100644 index 0000000..78078d1 --- /dev/null +++ b/tsukanova_irina_lab_2/README.md @@ -0,0 +1,16 @@ +# Цуканова Ирина ПИбд-32 +# Лабораторная работа №2 - Разработка простейшего распределённого приложения + +### Язык разработки приложений: Python + +## Выбранные варианты +- Для программы 1: Ищет в каталоге ```/var/data``` самый большой по объёму файл и перекладывает его в ```/var/result/data.txt```. +- Для программы 2: Сохраняет произведение первого и последнего числа из файла ```/var/result/data.txt``` в ```/var/result/result.txt```. + +## Описание: +Каждая программа лежит в своей папке, первая в worker-1, вторая в worker-2. +В этих же папках лежат Dockerfile'ы с инструкциями по сборке. В них присутствуют комментарии для значимых строк. +Монтированные папки ```data``` для ```/var/data``` и ```result``` для ```/var/result```. + + +## [Видео]() \ No newline at end of file diff --git a/tsukanova_irina_lab_2/docker-compose.yaml b/tsukanova_irina_lab_2/docker-compose.yaml index 86991f2..2fbe8cd 100644 --- a/tsukanova_irina_lab_2/docker-compose.yaml +++ b/tsukanova_irina_lab_2/docker-compose.yaml @@ -1,8 +1,9 @@ services: + worker_one: container_name: worker_one build: - context: ./worker-1 + dockerfile: ./worker-1 volumes: - ./data:/var/data - ./result:/var/result @@ -10,8 +11,8 @@ services: worker_two: container_name: worker_two build: - context: ./worker-2 - depends_on: - - worker_one + dockerfile: ./worker-2 volumes: - - ./result:/var/result \ No newline at end of file + - ./result:/var/result + depends_on: + - worker_one \ No newline at end of file diff --git a/tsukanova_irina_lab_2/result/result.txt b/tsukanova_irina_lab_2/result/result.txt new file mode 100644 index 0000000..f599e28 --- /dev/null +++ b/tsukanova_irina_lab_2/result/result.txt @@ -0,0 +1 @@ +10 diff --git a/tsukanova_irina_lab_2/worker-1/worker_1.py b/tsukanova_irina_lab_2/worker-1/worker_1.py index 3cb493f..fa8f9ee 100644 --- a/tsukanova_irina_lab_2/worker-1/worker_1.py +++ b/tsukanova_irina_lab_2/worker-1/worker_1.py @@ -2,7 +2,7 @@ import os import shutil # Ищет в каталоге /var/data самый большой по объёму файл и перекладывает его в /var/result/data.txt. -print("start one") +print("start worker_1") dir_data = "/var/data" dir_res = "/var/result" diff --git a/tsukanova_irina_lab_2/worker-2/worker_2.py b/tsukanova_irina_lab_2/worker-2/worker_2.py index 9bfdb95..924a47d 100644 --- a/tsukanova_irina_lab_2/worker-2/worker_2.py +++ b/tsukanova_irina_lab_2/worker-2/worker_2.py @@ -1,6 +1,6 @@ # Сохраняет произведение первого и последнего числа из файла /var/result/data.txt в /var/result/result.txt. -print("start two") +print("start worker_2") with open('/var/result/data.txt', 'r') as f: numbers = [int(num) for num in f.read().split() if num.isdigit()] From ad3988e5fccb3c62be484938eb56787f9b174ec9 Mon Sep 17 00:00:00 2001 From: HellsSenju Date: Wed, 25 Sep 2024 10:58:41 +0400 Subject: [PATCH 4/4] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=B2=D0=B8=D0=B4=D0=B5=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tsukanova_irina_lab_2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsukanova_irina_lab_2/README.md b/tsukanova_irina_lab_2/README.md index 78078d1..b22bf49 100644 --- a/tsukanova_irina_lab_2/README.md +++ b/tsukanova_irina_lab_2/README.md @@ -13,4 +13,4 @@ Монтированные папки ```data``` для ```/var/data``` и ```result``` для ```/var/result```. -## [Видео]() \ No newline at end of file +## [Видео](https://drive.google.com/file/d/1eBbIDgTo3MF4EeM677EPEKgJEINekaC0/view?usp=drive_link) \ No newline at end of file