From b00ee5caee61be1226dbfbc0fdb54a7184d7b182 Mon Sep 17 00:00:00 2001 From: Beatriz Santana Date: Fri, 8 Nov 2024 17:58:02 -0300 Subject: [PATCH] add dockerfile --- .gitignore | 258 +++++++++++++++++++++---------------------- Dockerfile | 7 ++ app.py | 114 +++++++++---------- package-lock.json | 6 + requirements.txt | 14 +-- templates/index.html | 162 +++++++++++++-------------- 6 files changed, 287 insertions(+), 274 deletions(-) create mode 100644 Dockerfile create mode 100644 package-lock.json diff --git a/.gitignore b/.gitignore index b6e4761..25ff4b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,129 +1,129 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -.python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3d6bb4e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.13.0 +WORKDIR /app +COPY requirements.txt . +RUN pip install -r requirements.txt +COPY . /app/ +EXPOSE 5000 +CMD ["gunicorn", "--bind", "0.0.0.0:5000", "app:app"] \ No newline at end of file diff --git a/app.py b/app.py index 216eeec..1680f14 100644 --- a/app.py +++ b/app.py @@ -1,57 +1,57 @@ -from flask import Flask, render_template, request -import logging -import socket # Módulo para obter informações do servidor - -app = Flask(__name__, - static_url_path='', - static_folder='static', - template_folder='templates') - -@app.route('/', methods=['GET', 'POST']) -def index(): - # Obter informações do servidor - hostname = socket.gethostname() - ip_address = socket.gethostbyname(hostname) - - if request.method == 'GET': - return render_template('index.html', hostname=hostname, ip_address=ip_address) - else: - selecao = request.form.get('selectTemp') - valor = request.form.get('valorRef') - - try: - valor = float(valor) - except ValueError: - return render_template('index.html', conteudo={'unidade': 'inválido', 'valor': 'Entrada inválida'}, hostname=hostname, ip_address=ip_address) - - # Lógica de conversão - if selecao == '1': # Metro para Quilômetros - resultado = valor / 1000 - unidade = "quilômetros" - elif selecao == '2': # Quilômetros para Metro - resultado = valor * 1000 - unidade = "metros" - elif selecao == '3': # Metro para Milhas - resultado = valor / 1609.34 - unidade = "milhas" - elif selecao == '4': # Milhas para Metro - resultado = valor * 1609.34 - unidade = "metros" - elif selecao == '5': # Metro para Pés - resultado = valor * 3.28084 - unidade = "pés" - elif selecao == '6': # Pés para Metro - resultado = valor / 3.28084 - unidade = "metros" - else: - resultado = "Inválido" - unidade = "" - - return render_template('index.html', conteudo={'unidade': unidade, 'valor': resultado}, hostname=hostname, ip_address=ip_address) - -if __name__ == '__main__': - app.run() -else: - gunicorn_logger = logging.getLogger('gunicorn.error') - app.logger.handlers = gunicorn_logger.handlers - app.logger.setLevel(gunicorn_logger.level) +from flask import Flask, render_template, request +import logging +import socket # Módulo para obter informações do servidor + +app = Flask(__name__, + static_url_path='', + static_folder='static', + template_folder='templates') + +@app.route('/', methods=['GET', 'POST']) +def index(): + # Obter informações do servidor + hostname = socket.gethostname() + ip_address = socket.gethostbyname(hostname) + + if request.method == 'GET': + return render_template('index.html', hostname=hostname, ip_address=ip_address) + else: + selecao = request.form.get('selectTemp') + valor = request.form.get('valorRef') + + try: + valor = float(valor) + except ValueError: + return render_template('index.html', conteudo={'unidade': 'inválido', 'valor': 'Entrada inválida'}, hostname=hostname, ip_address=ip_address) + + # Lógica de conversão + if selecao == '1': # Metro para Quilômetros + resultado = valor / 1000 + unidade = "quilômetros" + elif selecao == '2': # Quilômetros para Metro + resultado = valor * 1000 + unidade = "metros" + elif selecao == '3': # Metro para Milhas + resultado = valor / 1609.34 + unidade = "milhas" + elif selecao == '4': # Milhas para Metro + resultado = valor * 1609.34 + unidade = "metros" + elif selecao == '5': # Metro para Pés + resultado = valor * 3.28084 + unidade = "pés" + elif selecao == '6': # Pés para Metro + resultado = valor / 3.28084 + unidade = "metros" + else: + resultado = "Inválido" + unidade = "" + + return render_template('index.html', conteudo={'unidade': unidade, 'valor': resultado}, hostname=hostname, ip_address=ip_address) + +if __name__ == '__main__': + app.run() +else: + gunicorn_logger = logging.getLogger('gunicorn.error') + app.logger.handlers = gunicorn_logger.handlers + app.logger.setLevel(gunicorn_logger.level) diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..ce0469a --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "devops-conversao-distancia", + "lockfileVersion": 3, + "requires": true, + "packages": {} +} diff --git a/requirements.txt b/requirements.txt index 16285b1..5ad7df2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ -click==8.0.1 -Flask==2.0.1 -gunicorn==20.1.0 -itsdangerous==2.0.1 -Jinja2==3.0.1 -MarkupSafe==2.0.1 -Werkzeug==2.0.1 +click==8.0.1 +Flask==2.0.1 +gunicorn==20.1.0 +itsdangerous==2.0.1 +Jinja2==3.0.1 +MarkupSafe==2.0.1 +Werkzeug==2.0.1 diff --git a/templates/index.html b/templates/index.html index 39d2323..575843d 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,82 +1,82 @@ - - - - - - - - - - Conversão de Distância - - - - - - - - - - -
- - -
- -
-
-
-

Conversor de Distância

-
- -
-
- - -
-
- -
-
- {% if conteudo is defined %} -

Valor Convertido

- O valor convertido pra {{ conteudo['unidade'] }} é igual a {{ conteudo['valor'] }} - {% endif %} -
-
- - - - + + + + + + + + + + Conversão de Distância + + + + + + + + + + +
+ + +
+ +
+
+
+

Conversor de Distância

+
+ +
+
+ + +
+
+ +
+
+ {% if conteudo is defined %} +

Valor Convertido

+ O valor convertido pra {{ conteudo['unidade'] }} é igual a {{ conteudo['valor'] }} + {% endif %} +
+
+ + + + \ No newline at end of file