mirror of
https://github.com/norohind/FDEV-CAPI-Handler.git
synced 2025-04-12 05:50:00 +03:00
Dockerized
This commit is contained in:
parent
e3b8c724e3
commit
f7f40738d0
3
.dockerignore
Normal file
3
.dockerignore
Normal file
@ -0,0 +1,3 @@
|
||||
.git
|
||||
.gitignore
|
||||
.dockerignore
|
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
__pycache__
|
||||
*.sqlite
|
||||
venv
|
||||
start_web_uwsgi.bash
|
||||
uwsgi.ini
|
27
Dockerfile
Normal file
27
Dockerfile
Normal file
@ -0,0 +1,27 @@
|
||||
FROM python:3.11-slim as builder
|
||||
WORKDIR /app
|
||||
|
||||
ENV PYTHONDONTWRITEBYTECODE 1
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
|
||||
COPY requirements.txt .
|
||||
RUN apt update && apt install -y gcc
|
||||
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /app/wheels -r requirements.txt
|
||||
|
||||
FROM python:3.11-slim
|
||||
|
||||
ENV PYTHONDONTWRITEBYTECODE 1
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
|
||||
RUN useradd --no-create-home --system user
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=builder /app/wheels /wheels
|
||||
COPY --from=builder /app/requirements.txt .
|
||||
|
||||
RUN pip install --no-cache /wheels/*
|
||||
USER user
|
||||
COPY . .
|
||||
|
||||
ENTRYPOINT ["/app/entrypoint.sh"]
|
||||
|
@ -207,4 +207,4 @@ class CAPIAuthorizer:
|
||||
return self.model.list_all_records()
|
||||
|
||||
|
||||
capi_authorizer = CAPIAuthorizer(model.Model())
|
||||
capi_authorizer = CAPIAuthorizer(model.Model(config.db_location))
|
||||
|
@ -8,8 +8,8 @@ logger = get_main_logger()
|
||||
|
||||
|
||||
class Model:
|
||||
def __init__(self):
|
||||
self.db: sqlite3.Connection = sqlite3.connect('companion-api.sqlite', check_same_thread=False)
|
||||
def __init__(self, db_location: str):
|
||||
self.db: sqlite3.Connection = sqlite3.connect(db_location, check_same_thread=False)
|
||||
self.db.row_factory = lambda c, r: dict(zip([col[0] for col in c.description], r))
|
||||
with self.db:
|
||||
self.db.execute(sqlite_requests.schema)
|
||||
|
@ -10,6 +10,8 @@ log_level = os.getenv('LOG_LEVEL', 'DEBUG').upper()
|
||||
|
||||
access_key = os.getenv('access_key')
|
||||
|
||||
db_location = os.getenv('db_location', 'companion-api.sqlite')
|
||||
|
||||
REDIRECT_URL = requests.utils.quote(os.getenv('REDIRECT_URL', ''))
|
||||
AUTH_URL = 'https://auth.frontierstore.net/auth'
|
||||
TOKEN_URL = 'https://auth.frontierstore.net/token'
|
||||
|
7
entrypoint.sh
Executable file
7
entrypoint.sh
Executable file
@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
python3 generate_uswgi_config.py
|
||||
exec uwsgi -c /tmp/uwsgi.ini
|
||||
|
30
generate_uswgi_config.py
Normal file
30
generate_uswgi_config.py
Normal file
@ -0,0 +1,30 @@
|
||||
import os
|
||||
|
||||
template = """
|
||||
[uwsgi]
|
||||
master = 1
|
||||
vacuum = true
|
||||
socket = 0.0.0.0:8080
|
||||
enable-threads = true
|
||||
die-on-term = true
|
||||
thunder-lock = true
|
||||
threads = {threads}
|
||||
processes = {processes}
|
||||
wsgi-file = {wsgi_file}
|
||||
need-app = true
|
||||
check-static = static
|
||||
chdir = {project_dir}"""[1:]
|
||||
|
||||
project_dir = os.path.dirname(os.path.abspath(__file__)) # current dir
|
||||
wsgi_file = os.path.join(project_dir, 'web.py')
|
||||
|
||||
cpu_count = os.cpu_count()
|
||||
process_count = cpu_count
|
||||
|
||||
config = template.format(threads=cpu_count,
|
||||
processes=process_count,
|
||||
wsgi_file=wsgi_file,
|
||||
project_dir=project_dir)
|
||||
|
||||
with open('/tmp/uwsgi.ini', 'w') as file:
|
||||
file.write(config)
|
Loading…
x
Reference in New Issue
Block a user