basharin_sevastyan_lab_2 #22
70
basharin_sevastyan_lab_2/README.md
Normal file
70
basharin_sevastyan_lab_2/README.md
Normal file
@ -0,0 +1,70 @@
|
||||
## Лабораторная работа 1. Вариант 5.
|
||||
|
||||
#### Вариант первой программы:
|
||||
Ищет в каталоге `/var/data` файл с самым коротким названием и перекладывает его в `/var/result/data.txt`.
|
||||
#### Вариант второй программы:
|
||||
Сохраняет произведение первого и последнего числа из файла `/var/data/data.txt` в `/var/result/result.txt`.
|
||||
### Как запустить:
|
||||
В директории с файлом `docker-compose` в консоли/терминале ввести команду `docker-compose up`
|
||||
|
||||
#### Файл сборки docker-compose.yaml
|
||||
```dockerfile
|
||||
version: "3"
|
||||
services:
|
||||
worker-1:
|
||||
build:
|
||||
context: /app1
|
||||
dockerfile: Dockerfile
|
||||
|
||||
worker-2:
|
||||
build:
|
||||
context: /app2
|
||||
dockerfile: Dockerfile
|
||||
```
|
||||
|
||||
#### Dockerfile каждой программы
|
||||
```dockerfile
|
||||
FROM python:3.11
|
||||
COPY . .
|
||||
COPY var/data /var/data
|
||||
COPY var/result /var/result
|
||||
CMD ["python", "main.py"]
|
||||
```
|
||||
|
||||
#### Код первой программы
|
||||
```python
|
||||
import os
|
||||
|
||||
|
||||
def main():
|
||||
data_dir = 'var/data'
|
||||
result_file = '/var/result/data.txt'
|
||||
min_name = min(os.listdir(data_dir)) # Ищем и записываем самое короткое название (включая расширение)
|
||||
with open(result_file, 'w') as result:
|
||||
result.write(min_name)
|
||||
print(f'В файл {result_file} было записано {min_name}')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
```
|
||||
|
||||
#### Код второй программы
|
||||
```python
|
||||
def main():
|
||||
data_path = 'var/data/data.txt'
|
||||
result_path = 'var/result/result.txt'
|
||||
data = []
|
||||
with open(data_path, "r") as data_file:
|
||||
data = list(map(lambda x: int(x), data_file.read().split()))
|
||||
with open(result_path, 'w') as result:
|
||||
result.write(f'{data[0] * data[-1]}')
|
||||
print(f'В файл {result_path} было записано {data[0] * data[-1]}')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
```
|
||||
|
||||
### Видео
|
||||
https://youtu.be/D7HKUqotLGA
|
5
basharin_sevastyan_lab_2/app1/Dockerfile
Normal file
5
basharin_sevastyan_lab_2/app1/Dockerfile
Normal file
@ -0,0 +1,5 @@
|
||||
FROM python:3.11
|
||||
COPY . .
|
||||
COPY var/data /var/data
|
||||
COPY var/result /var/result
|
||||
CMD ["python", "main.py"]
|
14
basharin_sevastyan_lab_2/app1/main.py
Normal file
14
basharin_sevastyan_lab_2/app1/main.py
Normal file
@ -0,0 +1,14 @@
|
||||
import os
|
||||
|
||||
|
||||
def main():
|
||||
data_dir = 'var/data'
|
||||
result_file = '/var/result/data.txt'
|
||||
min_name = min(os.listdir(data_dir)) # Ищем и записываем самое короткое название (включая расширение)
|
||||
with open(result_file, 'w') as result:
|
||||
result.write(min_name)
|
||||
print(f'В файл {result_file} было записано {min_name}')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
0
basharin_sevastyan_lab_2/app1/var/data/data.txt
Normal file
0
basharin_sevastyan_lab_2/app1/var/data/data.txt
Normal file
0
basharin_sevastyan_lab_2/app1/var/data/max_data.txt
Normal file
0
basharin_sevastyan_lab_2/app1/var/data/max_data.txt
Normal file
5
basharin_sevastyan_lab_2/app2/Dockerfile
Normal file
5
basharin_sevastyan_lab_2/app2/Dockerfile
Normal file
@ -0,0 +1,5 @@
|
||||
FROM python:3.11
|
||||
COPY . .
|
||||
COPY var/data /var/data
|
||||
COPY var/result /var/result
|
||||
CMD ["python", "main.py"]
|
13
basharin_sevastyan_lab_2/app2/main.py
Normal file
13
basharin_sevastyan_lab_2/app2/main.py
Normal file
@ -0,0 +1,13 @@
|
||||
def main():
|
||||
data_path = 'var/data/data.txt'
|
||||
result_path = 'var/result/result.txt'
|
||||
data = []
|
||||
with open(data_path, "r") as data_file:
|
||||
data = list(map(lambda x: int(x), data_file.read().split()))
|
||||
with open(result_path, 'w') as result:
|
||||
result.write(f'{data[0] * data[-1]}')
|
||||
print(f'В файл {result_path} было записано {data[0] * data[-1]}')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
10
basharin_sevastyan_lab_2/app2/var/data/data.txt
Normal file
10
basharin_sevastyan_lab_2/app2/var/data/data.txt
Normal file
@ -0,0 +1,10 @@
|
||||
30
|
||||
36
|
||||
20
|
||||
37
|
||||
39
|
||||
68
|
||||
22
|
||||
16
|
||||
5
|
||||
21
|
11
basharin_sevastyan_lab_2/docker-compose.yaml
Normal file
11
basharin_sevastyan_lab_2/docker-compose.yaml
Normal file
@ -0,0 +1,11 @@
|
||||
version: "3"
|
||||
services:
|
||||
worker-1:
|
||||
build:
|
||||
context: /app1
|
||||
dockerfile: Dockerfile
|
||||
|
||||
worker-2:
|
||||
build:
|
||||
context: /app2
|
||||
dockerfile: Dockerfile
|
Loading…
Reference in New Issue
Block a user