This commit is contained in:
Евгений Сергеев 2024-01-16 16:05:42 +04:00
parent ea990fd848
commit bb78e6823b
12 changed files with 102 additions and 10 deletions

View File

@ -0,0 +1,20 @@
version: '3'
services:
service1:
build:
context: ./service1
ports:
- "8081:8081"
volumes:
- .\var\data:/var/data
- .\var\result:/var/result
service2:
build:
context: ./service2
ports:
- "8082:8082"
volumes:
- ./var/data:/var/data
- ./var/result:/var/result

View File

@ -1,4 +1,15 @@
FROM ubuntu:latest
LABEL authors="User"
FROM python:3.11
ENTRYPOINT ["top", "-b"]
ENV LISTEN_PORT=8081
EXPOSE 8081
RUN ["mkdir", "/work"]
RUN ["mkdir", "/var/data"]
RUN ["mkdir", "/var/result"]
RUN pip install Flask
WORKDIR /work
COPY index.html service1.py ./
CMD ["python", "service1.py"]

View File

@ -1,7 +1,7 @@
from flask import Flask, redirect, render_template
import os
app = Flask(__name__)
app = Flask(__name__, template_folder='')
@app.route('/')
@ -11,8 +11,11 @@ def home():
@app.route('/ex')
def do():
data_dir = '/var/data'
path_result_file = '/var/result/data.txt'
current_directory = os.getcwd()
directory_elements = current_directory.split(os.path.sep) # Разделяем по разделителю каталогов
cur_d = os.path.sep.join(directory_elements[:-1])
data_dir = cur_d + '/var/data'
path_result_file = cur_d + '/var/result/data.txt'
try:
# Получаем список файлов в указанном каталоге

View File

@ -1,4 +1,14 @@
FROM ubuntu:latest
LABEL authors="User"
FROM python:3.11
ENTRYPOINT ["top", "-b"]
ENV LISTEN_PORT=8082
EXPOSE 8082
RUN ["mkdir", "/work"]
RUN ["mkdir", "/var/result"]
RUN pip install Flask
WORKDIR /work
COPY index.html result.html service2.py ./
CMD ["python", "service2.py"]

View File

@ -0,0 +1,43 @@
import os
from flask import Flask, render_template
app = Flask(__name__, template_folder='')
@app.route('/')
def home():
return render_template("index.html")
@app.route('/ex')
def do():
current_directory = os.getcwd()
directory_elements = current_directory.split(os.path.sep) # Разделяем по разделителю каталогов
cur_d = os.path.sep.join(directory_elements[:-1])
path_data_file = cur_d + '/var/result/data.txt'
path_result_file = cur_d + '/var/result/result.txt'
min_number = 0
try:
# Чтение чисел из файла
with open(path_data_file, 'r') as file:
numbers = [float(line.strip()) for line in file]
# Поиск минимального числа
min_number = min(numbers)
# Возведение минимального числа в третью степень
result = min_number ** 3
# Запись результата в файл
with open(path_result_file, 'w') as result_file:
result_file.write(str(result))
print(f'Наименьшее число из файла {path_data_file} в третьей степени сохранено в {path_result_file}.')
except Exception as e:
print(f'Произошла ошибка: {e}')
return render_template("result.html", num=min_number)
app.run(host='0.0.0.0', port=8082)

View File

View File

View File

@ -0,0 +1,4 @@
1
3
12
13

View File

@ -0,0 +1 @@
1.0