Add docker support and automatic docker build

This commit is contained in:
csd4ni3l
2025-10-04 10:00:07 +02:00
parent 28738202f6
commit 46245998d2
7 changed files with 169 additions and 5 deletions

6
.dockerignore Normal file
View File

@@ -0,0 +1,6 @@
.env
.env.example
.venv
__pycache__
Dockerfile
docker-compose.yml

26
.github/workflows/docker.yml vendored Normal file
View File

@@ -0,0 +1,26 @@
name: ci
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ vars.DOCKER_USERNAME }}/${{ github.event.repository.name }}:latest

15
Dockerfile Normal file
View File

@@ -0,0 +1,15 @@
FROM debian:12-slim AS build
RUN apt-get update && \
apt-get install --no-install-suggests --no-install-recommends --yes python3-venv gcc libpython3-dev && \
python3 -m venv /venv && \
/venv/bin/pip install --upgrade pip setuptools wheel
FROM build AS build-venv
COPY requirements.txt /requirements.txt
RUN /venv/bin/pip install --disable-pip-version-check -r /requirements.txt
FROM gcr.io/distroless/python3-debian12
COPY --from=build-venv /venv /venv
COPY . /app
WORKDIR /app
ENTRYPOINT ["/venv/bin/python3", "app.py"]

View File

@@ -1,3 +1,10 @@
Inspired by the Death By AI game available on Discord. (This project has no affiliation with Discord inc. Or any subsidiaries.) Inspired by the Death By AI game available on Discord. (This project has no affiliation with Discord inc. Or any subsidiaries.)
A game where you have to convince AI to get into debt, or have to convince AI to put you out of debt. A game where you have to convince AI to get into debt, or have to convince AI to put you out of debt.
How to run:
1. Download the repository code.
2. Run with either:
- Install the modules into a venv or use `uv sync` to automatically do it for you, and then run `app.py`.
- Run `docker compose up -d` in this directory
- Build the docker image, then run with `docker run`

9
app.py
View File

@@ -6,13 +6,14 @@ from constants import *
import os, requests, time, re, sqlite3, flask_login, bcrypt, secrets import os, requests, time, re, sqlite3, flask_login, bcrypt, secrets
load_dotenv(".env") if os.path.exists(".env"):
load_dotenv(".env")
if not os.environ["USE_HACKCLUB_AI"]: if not os.environ.get("USE_HACKCLUB_AI", True):
gemini_client = Client() gemini_client = Client()
app = Flask(__name__) app = Flask(__name__)
app.secret_key = os.environ["FLASK_SECRET_KEY"] app.secret_key = os.environ.get("FLASK_SECRET_KEY", secrets.token_hex(32))
login_manager = flask_login.LoginManager() login_manager = flask_login.LoginManager()
login_manager.init_app(app) login_manager.init_app(app)
@@ -237,7 +238,7 @@ def register():
return redirect(url_for("login")) return redirect(url_for("login"))
def ai_prompt(prompt): def ai_prompt(prompt):
if os.environ["USE_HACKCLUB_AI"]: if os.environ.get("USE_HACKCLUB_AI", True):
response = requests.post( response = requests.post(
"https://ai.hackclub.com/chat/completions", "https://ai.hackclub.com/chat/completions",
headers={"Content-Type": "application/json"}, headers={"Content-Type": "application/json"},

17
docker-compose.yml Normal file
View File

@@ -0,0 +1,17 @@
services:
debt-by-ai:
build: .
container_name: debt-by-ai
ports:
- "8080:8080"
environment:
HOST: "0.0.0.0"
PORT: "8080"
DEBUG_MODE: "false"
USE_HACKCLUB_AI: "false"
GEMINI_API_KEY: "changeme"
FLASK_SECRET_KEY: "changeme"
DB_FILE: "/app/data.db"
volumes:
- ./data.db:/app/data.db
restart: unless-stopped

92
requirements.txt Normal file
View File

@@ -0,0 +1,92 @@
# This file was autogenerated by uv via the following command:
# uv pip compile pyproject.toml -o requirements.txt
annotated-types==0.7.0
# via pydantic
anyio==4.11.0
# via
# google-genai
# httpx
bcrypt==5.0.0
# via debt-by-ai (pyproject.toml)
blinker==1.9.0
# via flask
cachetools==6.2.0
# via google-auth
certifi==2025.8.3
# via
# httpcore
# httpx
# requests
charset-normalizer==3.4.3
# via requests
click==8.3.0
# via flask
flask==3.1.2
# via
# debt-by-ai (pyproject.toml)
# flask-login
flask-login==0.6.3
# via debt-by-ai (pyproject.toml)
google-auth==2.41.1
# via google-genai
google-genai==1.41.0
# via debt-by-ai (pyproject.toml)
h11==0.16.0
# via httpcore
httpcore==1.0.9
# via httpx
httpx==0.28.1
# via google-genai
idna==3.10
# via
# anyio
# httpx
# requests
itsdangerous==2.2.0
# via flask
jinja2==3.1.6
# via flask
markupsafe==3.0.3
# via
# flask
# jinja2
# werkzeug
pyasn1==0.6.1
# via
# pyasn1-modules
# rsa
pyasn1-modules==0.4.2
# via google-auth
pydantic==2.11.9
# via google-genai
pydantic-core==2.33.2
# via pydantic
python-dotenv==1.1.1
# via debt-by-ai (pyproject.toml)
requests==2.32.5
# via
# debt-by-ai (pyproject.toml)
# google-genai
rsa==4.9.1
# via google-auth
sniffio==1.3.1
# via anyio
tenacity==9.1.2
# via google-genai
typing-extensions==4.15.0
# via
# anyio
# google-genai
# pydantic
# pydantic-core
# typing-inspection
typing-inspection==0.4.2
# via pydantic
urllib3==2.5.0
# via requests
websockets==15.0.1
# via google-genai
werkzeug==3.1.3
# via
# flask
# flask-login