init project

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-05-10 23:11:54 +02:00
parent 4d7853b778
commit a43ce47339
9 changed files with 162 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
DB_HOST=mariadb
DB_PORT=3306
DB_ROOT_PASSWORD=rootpassword
DB_USER=bnuy
DB_PASSWORD=example
DB_NAME=bnuy
+56
View File
@@ -0,0 +1,56 @@
# this is the first time I write a github / gitea actions workflow myself, so excuse me if it sucks
name: Build and publish bnuy api
on:
push:
branches:
- master
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
# this step was made by AI, i hope it works
- name: Extract registry host
id: registry
run: echo "host=$(echo ${{ github.server_url }} | sed 's|https\?://||')" >> "$GITHUB_OUTPUT"
- name: Docker meta
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ steps.registry.outputs.host }}/${{ github.repository }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Login to Gitea Container Registry
uses: docker/login-action@v4
with:
registry: ${{ steps.registry.outputs.host }}
username: ${{ github.repository_owner }}
password: ${{ secrets.REPO_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v7
with:
context: .
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' }}
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
+2
View File
@@ -174,3 +174,5 @@ cython_debug/
# PyPI configuration file
.pypirc
data/
+10
View File
@@ -0,0 +1,10 @@
# copy pasted from ich_iel bot
FROM python:3.13.13-slim-trixie
ENV PATH=/usr/local/bin:$PATH
WORKDIR /app
COPY requirements.txt .
RUN apt-get update && apt-get install -y gcc libmariadb-dev && rm -rf /var/lib/apt/lists/*
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["fastapi", "run", "main.py"]
+2
View File
@@ -1,2 +1,4 @@
# bnuy-api
A API which collects pictures of bunnies and provides a API to get random bunny pictures.
doesn't work yet, still in progress
+23
View File
@@ -0,0 +1,23 @@
services:
bnuy-api:
build: .
restart: unless-stopped
volumes:
- ./data:/app/data
ports:
- "8000:8000"
env_file: ".env"
mariadb:
image: mariadb:12
restart: unless-stopped
environment:
- MARIADB_DATABASE=${DB_NAME}
- MARIADB_PORT=${DB_PORT}
- MARIADB_USER=${DB_USER}
- MARIADB_PASSWORD=${DB_PASSWORD}
- MARIADB_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
volumes:
- mariadb_data:/var/lib/mysql
volumes:
mariadb_data:
+23
View File
@@ -0,0 +1,23 @@
services:
bnuy-api:
image: git.scrunkly.cat/michelle/bnuy-api:latest
restart: unless-stopped
volumes:
- ./data:/app/data
ports:
- "8000:8000"
env_file: ".env"
mariadb:
image: mariadb:12
restart: unless-stopped
environment:
- MARIADB_DATABASE=${DB_NAME}
- MARIADB_PORT=${DB_PORT}
- MARIADB_USER=${DB_USER}
- MARIADB_PASSWORD=${DB_PASSWORD}
- MARIADB_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
volumes:
- mariadb_data:/var/lib/mysql
volumes:
mariadb_data:
+38
View File
@@ -0,0 +1,38 @@
from fastapi import FastAPI
import asyncmy
import asyncio
import os
from contextlib import asynccontextmanager
@asynccontextmanager
async def connect_db(app: FastAPI):
app.state.pool = await asyncmy.create_pool(
host=os.getenv("DB_HOST", "localhost"),
port=int(os.getenv("DB_PORT", 3306)),
user=os.getenv("DB_USER"),
password=os.getenv("DB_PASSWORD"),
db=os.getenv("DB_NAME"),
minsize=5,
maxsize=20
)
try:
yield
finally:
app.state.pool.close()
await app.state.pool.wait_closed()
app = FastAPI(lifespan=connect_db)
@asynccontextmanager
async def get_connection():
async with app.state.pool.acquire() as conn:
yield conn
@app.get("/")
async def root():
return {"message": "yes the api works"}
@app.get("/random")
async def get_random_bnuy():
async with get_connection() as conn:
return {"message": "here could be a bnuy, if I would've implemented it"}
+2
View File
@@ -0,0 +1,2 @@
fastapi[standard]
asyncmy