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