From 79c62bdf6a8a726c83d3349ed02d68d3c394569f Mon Sep 17 00:00:00 2001 From: KirillTepechin Date: Mon, 11 Dec 2023 03:01:38 +0400 Subject: [PATCH] tepechin_kirill_lab_2 --- tepechin_kirill_lab_2/README.md | 100 ++++++++++++++++++ tepechin_kirill_lab_2/data/data.txt | 2 + tepechin_kirill_lab_2/data/data2.txt | 2 + tepechin_kirill_lab_2/docker-compose.yml | 19 ++++ tepechin_kirill_lab_2/result/data.txt | 2 + tepechin_kirill_lab_2/result/result.txt | 1 + tepechin_kirill_lab_2/worker-1/Dockerfile | 13 +++ tepechin_kirill_lab_2/worker-1/src/First.java | 35 ++++++ tepechin_kirill_lab_2/worker-2/Dockerfile | 13 +++ .../worker-2/src/Second.java | 39 +++++++ 10 files changed, 226 insertions(+) create mode 100644 tepechin_kirill_lab_2/README.md create mode 100644 tepechin_kirill_lab_2/data/data.txt create mode 100644 tepechin_kirill_lab_2/data/data2.txt create mode 100644 tepechin_kirill_lab_2/docker-compose.yml create mode 100644 tepechin_kirill_lab_2/result/data.txt create mode 100644 tepechin_kirill_lab_2/result/result.txt create mode 100644 tepechin_kirill_lab_2/worker-1/Dockerfile create mode 100644 tepechin_kirill_lab_2/worker-1/src/First.java create mode 100644 tepechin_kirill_lab_2/worker-2/Dockerfile create mode 100644 tepechin_kirill_lab_2/worker-2/src/Second.java diff --git a/tepechin_kirill_lab_2/README.md b/tepechin_kirill_lab_2/README.md new file mode 100644 index 0000000..51ad225 --- /dev/null +++ b/tepechin_kirill_lab_2/README.md @@ -0,0 +1,100 @@ +## Лабораторная работа №1, ПИбд-42 Тепечин Кирилл, Вариант 26 (2, 2) + +### Задание +#### Задание для первого приложения +Формирует файл /var/result/data.txt из первых строк всех файлов каталога /var/data +#### Задание для второго приложения +Ищет наименьшее число из файла /var/data/data.txt и сохраняет его третью степень в /var/result/result.txt. + +### Содержимое файлов +#### data/data.txt +```` +13 50 5 3 33 +2 3 10 12 +```` +#### data/data2.txt +```` +2 3 10 12 +13 50 5 3 33 +```` +### Dockerfile worker-1 +````dockerfile +# Использование образа java +FROM openjdk:17 + +# Создание директорий +RUN mkdir /var/data +RUN mkdir /var/result + +# Рабочая директория +WORKDIR /app + +# Копирование исходных файлов +COPY src /app/src + +# Компиляция +RUN javac /app/src/First.java + +# Запуск +CMD ["java", "-jar", "/app/src", "First"] +```` + +### Dockerfile worker-2 +````dockerfile +# Использование образа java +FROM openjdk:17 + +# Создание директорий +RUN mkdir /var/data +RUN mkdir /var/result + +# Рабочая директория +WORKDIR /app + +# Копирование исходных файлов +COPY src /app/src + +# Компиляция +RUN javac /app/src/Second.java + +# Запуск +CMD ["java", "-jar", "/app/src", "Second"] +```` + +### docker-compose файл +````yaml +services: + worker-1: + build: + context: /worker-1 + dockerfile: Dockerfile + volumes: + - C:\pet\DAS_2023_1\tepechin_kirill_lab_2\data:/var/data # Монтирование + - C:\pet\DAS_2023_1\tepechin_kirill_lab_2\result:/var/result + worker-2: + build: + context: /worker-2 + dockerfile: Dockerfile + volumes: + - C:\pet\DAS_2023_1\tepechin_kirill_lab_2\data:/var/data + - C:\pet\DAS_2023_1\tepechin_kirill_lab_2\result:/var/result + depends_on: #Зависимость сервисов + - worker-1 +```` +### Результаты +#### Результат выполнения worker-1 +```` +13 50 5 3 33 +2 3 10 12 +```` +Результат взят из файлов data.txt и data2.txt +#### Результат выполнения worker-2 +```` +8 +```` +2^3=8 +### Ссылка на видео +https://vk.com/video170089763_456239479?list=ln-gcpaumCqgqZ6urwCaD + + + diff --git a/tepechin_kirill_lab_2/data/data.txt b/tepechin_kirill_lab_2/data/data.txt new file mode 100644 index 0000000..1f3ac8a --- /dev/null +++ b/tepechin_kirill_lab_2/data/data.txt @@ -0,0 +1,2 @@ +13 50 5 3 33 +2 3 10 12 \ No newline at end of file diff --git a/tepechin_kirill_lab_2/data/data2.txt b/tepechin_kirill_lab_2/data/data2.txt new file mode 100644 index 0000000..186ac92 --- /dev/null +++ b/tepechin_kirill_lab_2/data/data2.txt @@ -0,0 +1,2 @@ +2 3 10 12 +13 50 5 3 33 \ No newline at end of file diff --git a/tepechin_kirill_lab_2/docker-compose.yml b/tepechin_kirill_lab_2/docker-compose.yml new file mode 100644 index 0000000..126b03f --- /dev/null +++ b/tepechin_kirill_lab_2/docker-compose.yml @@ -0,0 +1,19 @@ +version: '3' + +services: + worker-1: + build: + context: /worker-1 + dockerfile: Dockerfile + volumes: + - C:\pet\DAS_2023_1\tepechin_kirill_lab_2\data:/var/data # Монтирование + - C:\pet\DAS_2023_1\tepechin_kirill_lab_2\result:/var/result + worker-2: + build: + context: /worker-2 + dockerfile: Dockerfile + volumes: + - C:\pet\DAS_2023_1\tepechin_kirill_lab_2\data:/var/data + - C:\pet\DAS_2023_1\tepechin_kirill_lab_2\result:/var/result + depends_on: #Зависимость сервисов + - worker-1 \ No newline at end of file diff --git a/tepechin_kirill_lab_2/result/data.txt b/tepechin_kirill_lab_2/result/data.txt new file mode 100644 index 0000000..557b52e --- /dev/null +++ b/tepechin_kirill_lab_2/result/data.txt @@ -0,0 +1,2 @@ +13 50 5 3 33 +2 3 10 12 diff --git a/tepechin_kirill_lab_2/result/result.txt b/tepechin_kirill_lab_2/result/result.txt new file mode 100644 index 0000000..45a4fb7 --- /dev/null +++ b/tepechin_kirill_lab_2/result/result.txt @@ -0,0 +1 @@ +8 diff --git a/tepechin_kirill_lab_2/worker-1/Dockerfile b/tepechin_kirill_lab_2/worker-1/Dockerfile new file mode 100644 index 0000000..200453d --- /dev/null +++ b/tepechin_kirill_lab_2/worker-1/Dockerfile @@ -0,0 +1,13 @@ +# Использование образа java +FROM openjdk:17 +# Создание директорий +RUN mkdir /var/data +RUN mkdir /var/result +# Рабочая директория +WORKDIR /app +# Копирование исходных файлов +COPY src /app/src +# Компиляция +RUN javac /app/src/First.java +# Запуск +CMD ["java", "-jar", "/app/src", "First"] \ No newline at end of file diff --git a/tepechin_kirill_lab_2/worker-1/src/First.java b/tepechin_kirill_lab_2/worker-1/src/First.java new file mode 100644 index 0000000..caf9247 --- /dev/null +++ b/tepechin_kirill_lab_2/worker-1/src/First.java @@ -0,0 +1,35 @@ +import java.io.*; + +public class First { + public static void main(String[] args) { + String dataDirectoryPath = "/var/data"; + + String resultFilePath = "/var/result/data.txt"; + + try { + BufferedWriter writer = new BufferedWriter(new FileWriter(resultFilePath)); + + File dataDirectory = new File(dataDirectoryPath); + File[] files = dataDirectory.listFiles(); + + if (files != null) { + for (File file : files) { + BufferedReader reader = new BufferedReader(new FileReader(file)); + String line = reader.readLine(); + + if (line != null) { + writer.write(line); + writer.newLine(); + } + + reader.close(); + } + } + + writer.close(); + + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/tepechin_kirill_lab_2/worker-2/Dockerfile b/tepechin_kirill_lab_2/worker-2/Dockerfile new file mode 100644 index 0000000..7bc794e --- /dev/null +++ b/tepechin_kirill_lab_2/worker-2/Dockerfile @@ -0,0 +1,13 @@ +# Использование образа java +FROM openjdk:17 +# Создание директорий +RUN mkdir /var/data +RUN mkdir /var/result +# Рабочая директория +WORKDIR /app +# Копирование исходных файлов +COPY src /app/src +# Компиляция +RUN javac /app/src/Second.java +# Запуск +CMD ["java", "-jar", "/app/src", "Second"] \ No newline at end of file diff --git a/tepechin_kirill_lab_2/worker-2/src/Second.java b/tepechin_kirill_lab_2/worker-2/src/Second.java new file mode 100644 index 0000000..52587dd --- /dev/null +++ b/tepechin_kirill_lab_2/worker-2/src/Second.java @@ -0,0 +1,39 @@ +import java.io.*; + +public class Second { + public static void main(String[] args) { + String dataFilePath = "/var/data/data.txt"; + String resultFilePath = "/var/result/result.txt"; + + try { + BufferedReader reader = new BufferedReader(new FileReader(dataFilePath)); + String line; + int minNumber = Integer.MAX_VALUE; + + while ((line = reader.readLine()) != null) { + String[] strNums = line.split(" "); + for (var strNum: strNums) { + int number = Integer.parseInt(strNum); + + if (number < minNumber) { + minNumber = number; + } + } + + } + + reader.close(); + + int result = (int) Math.pow(minNumber, 3); + + BufferedWriter writer = new BufferedWriter(new FileWriter(resultFilePath)); + writer.write(String.valueOf(result)); + writer.newLine(); + writer.close(); + + System.out.println(result); + } catch (IOException | NumberFormatException e) { + e.printStackTrace(); + } + } +}