From 1213b5db3c07bb36afeee53e95b2dde3008deb2e Mon Sep 17 00:00:00 2001 From: the Date: Fri, 4 Oct 2024 14:33:05 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A7=D0=B8=D1=81=D1=82=D1=8B=D0=B9=20=D0=BD?= =?UTF-8?q?=D0=B5=D0=BF=D0=BE=D0=B4=D0=BA=D1=83=D0=BF=D0=BD=D1=8B=D0=B9=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=87=D0=B8=D0=B9=20=D0=BA=D0=BE=D0=B4?= =?UTF-8?q?=202-=D0=B9=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=BD=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bogdanov_dmitry_lab_2/.gitignore | 2 ++ bogdanov_dmitry_lab_2/app-1/Dockerfile | 7 +++++ bogdanov_dmitry_lab_2/app-1/app.py | 22 ++++++++++++++++ bogdanov_dmitry_lab_2/app-2/Dockerfile | 7 +++++ bogdanov_dmitry_lab_2/app-2/app.py | 15 +++++++++++ .../app-generator/Dockerfile | 7 +++++ .../app-generator/generator.py | 26 +++++++++++++++++++ bogdanov_dmitry_lab_2/docker-compose.yaml | 24 +++++++++++++++++ 8 files changed, 110 insertions(+) create mode 100644 bogdanov_dmitry_lab_2/.gitignore create mode 100644 bogdanov_dmitry_lab_2/app-1/Dockerfile create mode 100644 bogdanov_dmitry_lab_2/app-1/app.py create mode 100644 bogdanov_dmitry_lab_2/app-2/Dockerfile create mode 100644 bogdanov_dmitry_lab_2/app-2/app.py create mode 100644 bogdanov_dmitry_lab_2/app-generator/Dockerfile create mode 100644 bogdanov_dmitry_lab_2/app-generator/generator.py create mode 100644 bogdanov_dmitry_lab_2/docker-compose.yaml diff --git a/bogdanov_dmitry_lab_2/.gitignore b/bogdanov_dmitry_lab_2/.gitignore new file mode 100644 index 0000000..6f12951 --- /dev/null +++ b/bogdanov_dmitry_lab_2/.gitignore @@ -0,0 +1,2 @@ +data/ +result/ \ No newline at end of file diff --git a/bogdanov_dmitry_lab_2/app-1/Dockerfile b/bogdanov_dmitry_lab_2/app-1/Dockerfile new file mode 100644 index 0000000..8e7da3d --- /dev/null +++ b/bogdanov_dmitry_lab_2/app-1/Dockerfile @@ -0,0 +1,7 @@ +FROM python:latest + +WORKDIR /app + +COPY app.py /app/ + +CMD ["python", "app.py"] \ No newline at end of file diff --git a/bogdanov_dmitry_lab_2/app-1/app.py b/bogdanov_dmitry_lab_2/app-1/app.py new file mode 100644 index 0000000..0257075 --- /dev/null +++ b/bogdanov_dmitry_lab_2/app-1/app.py @@ -0,0 +1,22 @@ +import os + +# Variant 2 +def solve(dir_files, dir_result, filename_result): + filenames = os.listdir(dir_files) + result = '' + for filename in filenames: + filepath = os.path.join(dir_files, filename) + file = open(filepath, "r") + result += f"{file.readline()}" + file.close() + + if not os.path.exists(dir_result): + os.makedirs(dir_result) + if os.listdir(dir_result): + return + result_file = open(os.path.join(dir_result, filename_result), "w") + result_file.write(result) + result_file.close() + +if __name__ == "__main__": + solve('/var/data', '/var/result', 'data.txt') \ No newline at end of file diff --git a/bogdanov_dmitry_lab_2/app-2/Dockerfile b/bogdanov_dmitry_lab_2/app-2/Dockerfile new file mode 100644 index 0000000..8e7da3d --- /dev/null +++ b/bogdanov_dmitry_lab_2/app-2/Dockerfile @@ -0,0 +1,7 @@ +FROM python:latest + +WORKDIR /app + +COPY app.py /app/ + +CMD ["python", "app.py"] \ No newline at end of file diff --git a/bogdanov_dmitry_lab_2/app-2/app.py b/bogdanov_dmitry_lab_2/app-2/app.py new file mode 100644 index 0000000..e5ea411 --- /dev/null +++ b/bogdanov_dmitry_lab_2/app-2/app.py @@ -0,0 +1,15 @@ +import os + +# Variant 1 +def solve(dir_input, dir_result, filename_result): + file_input = open(os.path.join(dir_input, 'data.txt')) + + inputs = [int(line) for line in file_input.readlines()] + if inputs: + result = max(inputs) ** 2 + file_result = open(os.path.join(dir_result, filename_result), "w") + file_result.write(str(result)) + file_result.close() + +if __name__ == "__main__": + solve("/var/result", '/var/result', 'result.txt') \ No newline at end of file diff --git a/bogdanov_dmitry_lab_2/app-generator/Dockerfile b/bogdanov_dmitry_lab_2/app-generator/Dockerfile new file mode 100644 index 0000000..d58d177 --- /dev/null +++ b/bogdanov_dmitry_lab_2/app-generator/Dockerfile @@ -0,0 +1,7 @@ +FROM python:latest + +WORKDIR /app + +COPY generator.py /app/ + +CMD ["python", "generate_files.py"] \ No newline at end of file diff --git a/bogdanov_dmitry_lab_2/app-generator/generator.py b/bogdanov_dmitry_lab_2/app-generator/generator.py new file mode 100644 index 0000000..1e1954a --- /dev/null +++ b/bogdanov_dmitry_lab_2/app-generator/generator.py @@ -0,0 +1,26 @@ +import os +import random as rnd +import string + + +def generate_filename(l): + return ''.join(rnd.choices(string.ascii_lowercase + string.digits, k=l)) + '.txt' + +def generate_files(dir, num_files, num_lines): + if not os.path.exists(dir): + os.makedirs(dir) + + if os.listdir(dir): + return + + for i in range(num_files): + filename = generate_filename(20) + filepath = os.path.join(dir, filename) + + file = open(filepath, "w") + for j in range(num_lines): + file.write(f"{rnd.randint(-1000, 1000)}\n") + file.close() + +if __name__ == "__main__": + generate_files('/var/data', 50, 50) \ No newline at end of file diff --git a/bogdanov_dmitry_lab_2/docker-compose.yaml b/bogdanov_dmitry_lab_2/docker-compose.yaml new file mode 100644 index 0000000..66dbd6f --- /dev/null +++ b/bogdanov_dmitry_lab_2/docker-compose.yaml @@ -0,0 +1,24 @@ +services: + generator: + build: + context: ./app-generator + volumes: + - ./data:/var/data + entrypoint: python generator.py + + app1: + build: + context: ./app-1 + volumes: + - ./data:/var/data + - ./result:/var/result + depends_on: + - generator + + app2: + build: + context: ./app-2 + volumes: + - ./result:/var/result + depends_on: + - app1 \ No newline at end of file