From 91e8f7bbf45c187bf330a94619eb280b136aa5ce Mon Sep 17 00:00:00 2001 From: Eriks Karls Date: Tue, 12 Dec 2023 11:41:48 +0200 Subject: [PATCH] Version Update 2023-12-12 --- .dockerignore | 117 +++++++++++++++++++++++++++++++++++++++++++++++ .gitignore | 116 ++++++++++++++++++++++++++++++++++++++++++++++ .gitlab-ci.yml | 12 ----- Dockerfile | 9 ++-- Makefile | 5 ++ app.py | 5 +- gunicorn.py | 92 +++++++++++++++++++++++++++++++++++++ pyproject.toml | 17 +++++++ requirements.txt | 7 +-- setup.cfg | 13 ++++++ 10 files changed, 370 insertions(+), 23 deletions(-) create mode 100644 .gitignore delete mode 100644 .gitlab-ci.yml create mode 100644 Makefile create mode 100644 gunicorn.py create mode 100644 pyproject.toml create mode 100644 setup.cfg diff --git a/.dockerignore b/.dockerignore index 541a4b1..906818d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,119 @@ .git *.pdf + +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf +.idea/**/aws.xml +.idea/**/contentModel.xml +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml +.idea/**/gradle.xml +.idea/**/libraries +cmake-build-*/ +.idea/**/mongoSettings.xml +*.iws +out/ +.idea_modules/ +atlassian-ide-plugin.xml +.idea/replstate.xml +.idea/sonarlint/ +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties +.idea/httpRequests +.idea/caches/build_file_checksums.ser +.Python +[Bb]in +[Ii]nclude +[Ll]ib +[Ll]ib64 +[Ll]ocal +[Ss]cripts +pyvenv.cfg +.venv +pip-selfcheck.json +__pycache__/ +*.py[cod] +*$py.class +*.so +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST +*.manifest +*.spec +pip-log.txt +pip-delete-this-directory.txt +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ +*.mo +*.pot +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal +instance/ +.webassets-cache +.scrapy +docs/_build/ +.pybuilder/ +target/ +.ipynb_checkpoints +profile_default/ +ipython_config.py +.pdm.toml +__pypackages__/ +celerybeat-schedule +celerybeat.pid +*.sage.py +.env +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +.spyderproject +.spyproject +.ropeproject +/site +.mypy_cache/ +.dmypy.json +dmypy.json +.pyre/ +.pytype/ +cython_debug/ +instance/* +!instance/.gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..09dd3e1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,116 @@ +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf +.idea/**/aws.xml +.idea/**/contentModel.xml +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml +.idea/**/gradle.xml +.idea/**/libraries +cmake-build-*/ +.idea/**/mongoSettings.xml +*.iws +out/ +.idea_modules/ +atlassian-ide-plugin.xml +.idea/replstate.xml +.idea/sonarlint/ +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties +.idea/httpRequests +.idea/caches/build_file_checksums.ser +.Python +[Bb]in +[Ii]nclude +[Ll]ib +[Ll]ib64 +[Ll]ocal +[Ss]cripts +pyvenv.cfg +.venv +pip-selfcheck.json +__pycache__/ +*.py[cod] +*$py.class +*.so +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST +*.manifest +*.spec +pip-log.txt +pip-delete-this-directory.txt +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ +*.mo +*.pot +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal +instance/ +.webassets-cache +.scrapy +docs/_build/ +.pybuilder/ +target/ +.ipynb_checkpoints +profile_default/ +ipython_config.py +.pdm.toml +__pypackages__/ +celerybeat-schedule +celerybeat.pid +*.sage.py +.env +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +.spyderproject +.spyproject +.ropeproject +/site +.mypy_cache/ +.dmypy.json +dmypy.json +.pyre/ +.pytype/ +cython_debug/ +instance/* +!instance/.gitignore diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 776bc61..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,12 +0,0 @@ -# You can override the included template(s) by including variable overrides -# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings -# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/#customizing-settings -# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings -# Note that environment variables can be set in several places -# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence -stages: -- test -sast: - stage: test -include: -- template: Security/SAST.gitlab-ci.yml diff --git a/Dockerfile b/Dockerfile index 726376c..bd43e6c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,8 @@ -FROM python:3.9-alpine -RUN pip install --no-cache-dir Flask icalendar gunicorn Unidecode -COPY . /app +FROM python:3-alpine as base WORKDIR /app +COPY requirements.txt . +RUN pip install --compile --no-cache-dir --requirement requirements.txt +COPY . /app -CMD ["gunicorn", "--workers=2", "--access-logfile", "-", "--log-level", "debug", "-b", "0.0.0.0:5000", "app:app"] +CMD ["gunicorn", "-c", "gunicorn.py"] #CMD python app.py diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c388031 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +docker-build: + docker build --tag=registry.72.lv/flask-namedays:latest --tag=flask-namedays:latest . + +docker-push: docker-build + docker push registry.72.lv/flask-namedays:latest diff --git a/app.py b/app.py index 29ccc40..9958823 100644 --- a/app.py +++ b/app.py @@ -1,6 +1,5 @@ import datetime import json -import logging import uuid from collections import defaultdict from io import BytesIO @@ -65,9 +64,7 @@ def calendar(): if cal: name = f"{uuid.uuid4().hex}.ics" f = generate_ical_for_mapping(cal) - return send_file( - f, mimetype="text/calendar", as_attachment=True, download_name=name - ) + return send_file(f, mimetype="text/calendar", as_attachment=True, download_name=name) return render_template("namedays.html") diff --git a/gunicorn.py b/gunicorn.py new file mode 100644 index 0000000..d3a68f9 --- /dev/null +++ b/gunicorn.py @@ -0,0 +1,92 @@ +""" Reference: https://docs.gunicorn.org/en/stable/settings.html """ +""" Config File https://docs.gunicorn.org/en/stable/settings.html#config-file """ +config = "gunicorn.py" +wsgi_app = "app:app" + +""" Debugging https://docs.gunicorn.org/en/stable/settings.html#debugging """ +# reload = False +# reload_engine = "auto" +# reload_extra_files = [] +# spew = False +# check_config = False +# print_config = False + +""" Logging https://docs.gunicorn.org/en/stable/settings.html#logging """ +accesslog = "-" +# disable_redirect_access_to_syslog = False +access_log_format = "%(t)s [%({HTTP_X_REAL_IP}e)s] '%(m)s' %(s)s %(b)s '%(U)s' '%(q)s' '%(a)s' '%(D)s'" +# errorlog = "-" +loglevel = "debug" +capture_output = True +# logger_class = 'gunicorn.glogging.Logger' +# logconfig = None +# logconfig_dict = dict() +# logconfig_json = None +# syslog_addr = 'udp://localhost:514' +# syslog = None +# syslog_prefix = None +# syslog_facility = "user" +# enable_stdio_inheritance = False +# statsd_host = None +# dogstatsd_tags = "" +# statsd_prefix = "" + +""" Process Naming https://docs.gunicorn.org/en/stable/settings.html#process-naming """ +# proc_name = None +# default_proc_name = "backoffice" + +""" SSL https://docs.gunicorn.org/en/stable/settings.html#ssl """ +# keyfile = None +# certfile = None +# ssl_version = 2 +# cert_reqs = 0 +# ca_certs = None +# suppress_ragged_eofs = True +# do_handshake_on_connect = False +# ciphers = None + +""" Security https://docs.gunicorn.org/en/stable/settings.html#security """ +# limit_request_line = 4094 +# limit_request_fields = 100 +# limit_request_field_size = 8190 + +""" Server Hooks https://docs.gunicorn.org/en/stable/settings.html#server-hooks """ + + +""" Server Mechanics https://docs.gunicorn.org/en/stable/settings.html#server-mechanics """ +# preload_app = False +# sendfile = None +# reuse_port = False +chdir = "/app" +# daemon = False +# raw_env = [] +# pidfile = None +# worker_tmp_dir = None +# user = "django" +# group = "django" +# umask = 0 +# initgroups = False +# tmp_upload_dir = None +# secure_scheme_headers = {'X-FORWARDED-PROTOCOL': 'ssl', 'X-FORWARDED-PROTO': 'https', 'X-FORWARDED-SSL': 'on'} +# forwarded_allow_ips = ['127.0.0.1'] +# pythonpath = None +# paste = None +# proxy_protocol = False +# proxy_allow_ips = ['127.0.0.1'] +# raw_paste_global_conf = [] +# strip_header_spaces = False + +""" Server Socket https://docs.gunicorn.org/en/stable/settings.html#server-socket """ +bind = "0.0.0.0:5000" +# backlog = 2048 + +""" Worker Processes https://docs.gunicorn.org/en/stable/settings.html#worker-processes """ +workers = 2 +# worker_class = "sync" +threads = 2 +# worker_connections = 1000 +# max_requests = 0 +# max_requests_jitter = 0 +# timeout = 30 +# graceful_timeout = 30 +# keepalive = 2 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..843ffbf --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,17 @@ +[tool.black] +line-length = 120 +target-version = ['py311'] +include = '\.pyi?$' +extend-exclude = '''( + migrations/* + | .git/* + | media/* +)''' +workers = 4 + + +[tool.isort] +profile = "black" +line_length = 120 +skip = ["venv", "templates", ".git"] +multi_line_output = 3 diff --git a/requirements.txt b/requirements.txt index 5e6b661..567bd46 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ -Flask==2.2.2 -icalendar==5.0.1 -unidecode==1.3.6 +Flask==3.0.0 +icalendar==5.0.11 +Unidecode==1.3.7 +Gunicorn==21.2.0 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..a1d69eb --- /dev/null +++ b/setup.cfg @@ -0,0 +1,13 @@ +[flake8] +max-line-length = 120 +exclude = .git,venv +ignore = E203,E262,E265,E501,E722,E741,W503,W605,F405,F841,F401 + +[mypy] +python_version = 3.11 +check_untyped_defs = True +ignore_missing_imports = True +warn_unused_ignores = True +warn_redundant_casts = True +warn_unused_configs = True +