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("Результат не получен. Файл не содержит чисел")