diff --git a/.gitignore b/.gitignore index ab3e8ce..6d82f93 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,8 @@ -# ---> Python -# Byte-compiled / optimized / DLL files +# Bytecode __pycache__/ *.py[cod] -*$py.class - -# C extensions -*.so +*.pyc +*.pyo # Distribution / packaging .Python @@ -21,144 +18,93 @@ parts/ sdist/ var/ wheels/ -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/ -cover/ - -# 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 -.pybuilder/ -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -# For a library or package, you might want to ignore these files since the code is -# intended to run in multiple environments; otherwise, check them in: -# .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 - -# poetry -# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. -# This is especially recommended for binary packages to ensure reproducibility, and is more -# commonly ignored for libraries. -# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control -#poetry.lock - -# pdm -# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. -#pdm.lock -# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it -# in version control. -# https://pdm.fming.dev/latest/usage/project/#working-with-version-control -.pdm.toml -.pdm-python -.pdm-build/ - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ +# Virtual environments venv/ +env/ ENV/ env.bak/ venv.bak/ +.venv/ +virtualenv/ -# Spyder project settings -.spyderproject -.spyproject +# PyCharm / IDE +.idea/ +*.iml +.vscode/ +*.swp +*.swo +.DS_Store -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy +# Testing +.pytest_cache/ +.coverage +htmlcov/ +.tox/ .mypy_cache/ .dmypy.json dmypy.json +*.cover +*.log -# Pyre type checker -.pyre/ +# Documentation +docs/_build/ +site/ -# pytype static type analyzer -.pytype/ +# Database +*.db +*.sqlite +*.sqlite3 -# Cython debug symbols -cython_debug/ +# Environment variables +.env +.venv +.env.local +.env.*.local -# PyCharm -# JetBrains specific template is maintained in a separate JetBrains.gitignore that can -# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore -# and can be added to the global gitignore or merged into this file. For a more nuclear -# option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ +# Jupyter Notebooks +.ipynb_checkpoints/ +# Logs +logs/ +*.log + +# OS +Thumbs.db +.DS_Store +Desktop.ini + +# MyPy +.mypy_cache/ +.ruff_cache/ + +# Python version +.python-version + +# pyenv +.python-version + +# Poetry +poetry.lock # если используете poetry, обычно poetry.lock добавляют в git, но можно и игнорировать + +# PDM +.pdm.toml +__pypackages__/ + +# Coverage +.coverage.* +coverage.xml +*.py,cover + +# Profiling +*.prof + +# Secrets +secrets.yaml +config.local.yaml +*.pem +*.key +*.crt \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..141e36a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,59 @@ +# Stage 1: Builder +FROM python:3.12-slim AS builder + +# Аргументы для сборки +ARG PIP_INDEX_URL=https://pypi.org/simple +ARG BUILD_ENV=production + +WORKDIR /app + +# Оптимизация слоев: сначала копируем только зависимости +COPY requirements.txt . + +# Кэширование зависимостей +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install --no-cache-dir \ + --index-url ${PIP_INDEX_URL} \ + -r requirements.txt + +# Stage 2: Final +FROM python:3.12-slim + +# Метки для трекинга +LABEL maintainer="Vic Sergeev" \ + version="1.0.0" \ + build-date="${BUILD_DATE}" \ + git-commit="${GIT_COMMIT}" + +# Создание пользователя +RUN groupadd -r appuser && useradd -r -g appuser appuser + +# Установка системных пакетов +RUN apt-get update && apt-get install -y \ + curl \ + tini \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +# Копирование зависимостей +COPY --from=builder --chown=appuser:appuser \ + /usr/local/lib/python3.12/site-packages \ + /usr/local/lib/python3.12/site-packages +COPY --from=builder --chown=appuser:appuser \ + /usr/local/bin \ + /usr/local/bin + +# Копирование приложения +COPY --chown=appuser:appuser . . + +# Переключение на пользователя +USER appuser + +# Healthcheck +HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ + CMD curl -f http://localhost:8000/health || exit 1 + +# Использование tini для правильной обработки сигналов +ENTRYPOINT ["/usr/bin/tini", "--"] +CMD ["python", "main.py"] \ No newline at end of file diff --git a/README.md b/README.md index 35cc619..40e8b06 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # DummyApp -Dummy app for dockerfile training \ No newline at end of file +Dummy app for dockerfile training + +### Dockerfile +is created with AI, used as best practices example \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..5d20a01 --- /dev/null +++ b/main.py @@ -0,0 +1,12 @@ +from flask import Flask + +app = Flask(__name__) + + +@app.route('/') +def hello_world(): # put application's code here + return 'Hello World!' + + +if __name__ == '__main__': + app.run() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a993b8d --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +Flask==3.0.3 \ No newline at end of file