Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F/metrics #53

Merged
merged 14 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
runs:
using: composite
steps:
- name: "Install UV"
shell: bash
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
73 changes: 69 additions & 4 deletions .github/workflows/hetzner-prd-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: hetzner production workflow

on:
pull_request:
branches:
- main
- develop
push:
branches:
- main
Expand All @@ -16,11 +20,71 @@ env:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
lock_file:
runs-on: [self-hosted, "hetzner"]
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
- run: uv lock --locked
linting:
runs-on: [self-hosted, "hetzner"]
needs: [lock_file]
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
- run: uvx ruff check .
formatting:
runs-on: [self-hosted, "hetzner"]
needs: [lock_file]
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
- run: uvx ruff format --check .
# type_consistency:
# runs-on: [self-hosted, "hetzner"]
# needs: [lock_file]
# steps:
# - uses: actions/checkout@v4
# - uses: ./.github/actions/setup
# - run: uv run pyright
tests:
runs-on: [self-hosted, "hetzner"]
needs: [linting, formatting]
env:
ENV: "DVP"
DATABASE_URL: "mysql+aiomysql://root:root_bot_buster@mysql:3306/playerdata"
KAFKA_HOST: "localhost:9092"
POOL_RECYCLE: 60
POOL_TIMEOUT: 30
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: ".python-version"
- name: Setup Docker Containers
run: |
docker-compose up --build --quiet-pull -d
- name: Check API is Up
uses: cygnetdigital/[email protected]
with:
url: "http://localhost:5000/docs"
responseCode: "200,500"
timeout: 120000 # wait up to 120 seconds
interval: 5000 # poll every 5 seconds
- run: uv run pytest -v --durations=0 --cov --cov-report=xml

# This workflow contains two jobs: build_image and update_image_version
build_image:
# The type of runner that the job will run on
runs-on: [self-hosted, "hetzner"]
if: github.repository_owner == 'Bot-detector'
needs: [tests]
# Run only on manual trigger
if: ${{ github.event_name == 'workflow_dispatch' }}
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
Expand Down Expand Up @@ -50,8 +114,9 @@ jobs:

update_image_version:
runs-on: [self-hosted, "hetzner"]
if: github.repository_owner == 'Bot-detector'
needs: build_image # This ensures that the build_image job is completed before running this job
needs: build_image
# Run only on manual trigger
if: ${{ github.event_name == 'workflow_dispatch' }}

steps:
- name: Checkout Target Repository
Expand Down
81 changes: 0 additions & 81 deletions .github/workflows/pytest-workflow-manual.yml

This file was deleted.

98 changes: 0 additions & 98 deletions .github/workflows/pytest-workflow.yml

This file was deleted.

1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
11 changes: 3 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
FROM python:3.11-slim as base
FROM python:3.11-slim AS base
COPY --from=ghcr.io/astral-sh/uv:0.5.4 /uv /uvx /bin/

ARG api_port
ENV UVICORN_PORT ${api_port}

ARG root_path
ENV UVICORN_ROOT_PATH ${root_path}

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1

# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1

# set the working directory
WORKDIR /project

Expand All @@ -23,7 +18,7 @@ RUN pip install --no-cache-dir -r requirements.txt
COPY ./src /project/src

# production image
FROM base as production
FROM base AS production
# Creates a non-root user with an explicit UID and adds permission to access the /project folder
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /project
USER appuser
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ services:
# this overrides the env_file for the specific variable
environment:
- KAFKA_HOST=kafka:9092
- DATABASE_URL=mysql+aiomysql://root:root_bot_buster@mysql/playerdata
- DATABASE_URL=mysql+asyncmy://root:root_bot_buster@mysql/playerdata
- ENV=DEV
- POOL_RECYCLE=60
- POOL_TIMEOUT=30
# env_file:
# - .env
healthcheck:
test: ["CMD-SHELL", "python -c \"import requests; assert requests.get('http://localhost:5000/').status_code == 200\""]
test: ["CMD-SHELL", "python -c 'import urllib.request; assert urllib.request.urlopen(\"http://localhost:5000/\").getcode() == 200'"]
interval: 5s
timeout: 10s
retries: 3
Expand Down
35 changes: 35 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[project]
name = "public-api"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"aiokafka>=0.12.0",
"aiokafkaengine>=0.0.4",
"aiomysql[rsa]>=0.2.0",
"asyncmy>=0.2.9",
"fastapi[standard]>=0.115.5",
"prometheus-client>=0.21.0",
"pydantic-settings>=2.6.1",
"pydantic>=2.10.1",
"sqlalchemy>=2.0.36",
]

[dependency-groups]
dev = [
"pytest-asyncio>=0.24.0",
"ruff>=0.7.4",
"pre-commit>=4.0.1",
"pyright>=1.1.389",
"httpx>=0.27.2",
"pytest-cov>=6.0.0",
]
[tool.pyright]
include = [
"src"
]
# exclude = [
# "tests/",
# "kafka_setup/"
# ]
Loading