containerized userdb
This commit is contained in:
parent
3296b9aa95
commit
41045fdf3a
4 changed files with 56 additions and 3 deletions
39
userdb/Dockerfile
Normal file
39
userdb/Dockerfile
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
# Use an official Python runtime as a parent image
|
||||||
|
FROM python:3.9-slim-bookworm
|
||||||
|
|
||||||
|
# --- Basic runtime hygiene ---
|
||||||
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||||
|
PYTHONUNBUFFERED=1
|
||||||
|
|
||||||
|
# Workdir
|
||||||
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
|
# Install OS deps first (so pip layer can cache better)
|
||||||
|
# You mentioned custom markovify & git, so we keep git.
|
||||||
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
|
git \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Copy only requirements first to leverage Docker layer cache
|
||||||
|
COPY requirements.txt .
|
||||||
|
|
||||||
|
# Install Python deps
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
# Copy the rest of your app
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Create a non-root user and give ownership
|
||||||
|
RUN adduser --disabled-password --gecos "" appuser \
|
||||||
|
&& chown -R appuser:appuser /usr/src/app
|
||||||
|
|
||||||
|
USER appuser
|
||||||
|
|
||||||
|
# Default cache dir (override with TEXTS_CACHE_DIR env if you want)
|
||||||
|
ENV DB_DIR=/usr/src/app/db
|
||||||
|
RUN mkdir -p "$DB_DIR"
|
||||||
|
|
||||||
|
# Expose the service port
|
||||||
|
EXPOSE 5000
|
||||||
|
|
||||||
|
CMD ["python", "-u", "db.py"]
|
||||||
|
|
@ -24,8 +24,8 @@ def track():
|
||||||
ua = str(request.args.get('ua'))
|
ua = str(request.args.get('ua'))
|
||||||
url = str(request.values.get("url") or request.headers.get("Referer"))
|
url = str(request.values.get("url") or request.headers.get("Referer"))
|
||||||
|
|
||||||
if os.path.exists('db.json'):
|
if os.path.exists('db/db.json'):
|
||||||
with open('db.json', 'r') as db:
|
with open('db/db.json', 'r') as db:
|
||||||
db = json.loads(db.read())
|
db = json.loads(db.read())
|
||||||
else:
|
else:
|
||||||
db = {}
|
db = {}
|
||||||
|
|
@ -45,7 +45,7 @@ def track():
|
||||||
|
|
||||||
send_msg(f'User <{hash}> visited { url } on { ua } ({ str(len(db[hash][cat])) })')
|
send_msg(f'User <{hash}> visited { url } on { ua } ({ str(len(db[hash][cat])) })')
|
||||||
|
|
||||||
with open('db.json', 'w+') as dbw:
|
with open('db/db.json', 'w+') as dbw:
|
||||||
dbw.write(json.dumps(db, indent=4))
|
dbw.write(json.dumps(db, indent=4))
|
||||||
|
|
||||||
return str(len(db[hash][cat]))
|
return str(len(db[hash][cat]))
|
||||||
|
|
|
||||||
11
userdb/docker-compose.yml
Normal file
11
userdb/docker-compose.yml
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
services:
|
||||||
|
wordonaut:
|
||||||
|
build: .
|
||||||
|
container_name: tagbot
|
||||||
|
ports:
|
||||||
|
- "8001:5000"
|
||||||
|
environment:
|
||||||
|
- FLASK_APP=wordonaut.py
|
||||||
|
- FLASK_RUN_HOST=0.0.0.0
|
||||||
|
volumes:
|
||||||
|
- .:/usr/src/app
|
||||||
3
userdb/requirements.txt
Normal file
3
userdb/requirements.txt
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
Flask
|
||||||
|
waitress
|
||||||
|
requests
|
||||||
Loading…
Add table
Add a link
Reference in a new issue