@@ -0,0 +1,6 @@
|
||||
DB_HOST=mariadb
|
||||
DB_PORT=3306
|
||||
DB_ROOT_PASSWORD=rootpassword
|
||||
DB_USER=bnuy
|
||||
DB_PASSWORD=example
|
||||
DB_NAME=bnuy
|
||||
@@ -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 }}
|
||||
@@ -174,3 +174,5 @@ cython_debug/
|
||||
# PyPI configuration file
|
||||
.pypirc
|
||||
|
||||
data/
|
||||
|
||||
|
||||
+10
@@ -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"]
|
||||
@@ -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
|
||||
@@ -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
@@ -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:
|
||||
@@ -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"}
|
||||
@@ -0,0 +1,2 @@
|
||||
fastapi[standard]
|
||||
asyncmy
|
||||
Reference in New Issue
Block a user