Skip to content

Commit 3e67444

Browse files
committed
feat: Add minio, dbsupport and url expiration
1 parent f4b3986 commit 3e67444

17 files changed

+894
-201
lines changed

.github/workflows/cd.yml

+19-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
name: CD Pipeline
2-
32
on:
43
workflow_run:
54
workflows: ["CI Pipeline"]
@@ -9,13 +8,24 @@ on:
98
jobs:
109
build:
1110
runs-on: self-hosted
12-
1311
steps:
14-
- name: Create data Folder
15-
run: mkdir -p data
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
15+
- name: Create .env file
16+
run: |
17+
echo "MINIO_CLIENT_LINK=${{ secrets.MINIO_CLIENT_LINK }}" >> .env
18+
echo "MINIO_ACCESS_KEY=${{ secrets.MINIO_ACCESS_KEY }}" >> .env
19+
echo "MINIO_SECRET_KEY=${{ secrets.MINIO_SECRET_KEY }}" >> .env
20+
echo "MINIO_BUCKET_NAME=${{ secrets.MINIO_BUCKET_NAME }}" >> .env
21+
echo "BASE_URL=${{ secrets.BASE_URL }}" >> .env
22+
echo "SQLALCHEMY_DATABASE_URL=${{ secrets.SQLALCHEMY_DATABASE_URL }}" >> .env
23+
1624
- name: Pull Docker image
17-
run: docker pull mrsunglasses/pastepy
18-
- name: Delete Old docker container
19-
run: docker rm -f pastepyprod || true
20-
- name: Run Docker Container
21-
run: docker run -d -p 8082:8080 -v $(pwd)/data:/project/data --name pastepyprod mrsunglasses/pastepy
25+
run: docker compose pull
26+
27+
- name: Stop and remove existing container
28+
run: docker compose down || true
29+
30+
- name: Start Docker container
31+
run: docker compose up -d

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,5 @@ cython_debug/
158158
# and can be added to the global gitignore or merged into this file. For a more nuclear
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160160
.idea/
161+
162+
*.db

docker-entrypoint.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# Run migrations
5+
pdm run migrate
6+
7+
# Execute the main command
8+
exec "$@"

src/paste/config.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from functools import lru_cache
2+
3+
from pydantic_settings import BaseSettings, SettingsConfigDict
4+
5+
6+
class Config(BaseSettings):
7+
MINIO_CLIENT_LINK: str
8+
MINIO_ACCESS_KEY: str
9+
MINIO_SECRET_KEY: str
10+
MINIO_BUCKET_NAME: str
11+
BASE_URL: str
12+
SQLALCHEMY_DATABASE_URL: str
13+
14+
model_config = SettingsConfigDict(env_file=".env")
15+
16+
17+
@lru_cache
18+
def get_settings():
19+
return Config()

src/paste/database.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from sqlalchemy import create_engine
2+
from sqlalchemy.ext.declarative import declarative_base
3+
from sqlalchemy.orm import sessionmaker
4+
5+
from .config import get_settings
6+
7+
SQLALCHEMY_DATABASE_URL = get_settings().SQLALCHEMY_DATABASE_URL
8+
9+
# Check if the database URL is for SQLite
10+
is_sqlite = SQLALCHEMY_DATABASE_URL.startswith("sqlite")
11+
12+
if is_sqlite:
13+
engine = create_engine(
14+
SQLALCHEMY_DATABASE_URL,
15+
connect_args={"check_same_thread": False}, # SQLite specific argument
16+
)
17+
18+
else:
19+
# PostgreSQL configuration
20+
engine = create_engine(
21+
SQLALCHEMY_DATABASE_URL,
22+
connect_args={},
23+
future=True,
24+
# Common PostgreSQL settings
25+
pool_size=5, # Maximum number of permanent connections
26+
max_overflow=10, # Maximum number of additional connections
27+
pool_timeout=30, # Timeout in seconds for getting a connection from pool
28+
pool_recycle=1800, # Recycle connections after 30 minutes
29+
)
30+
31+
32+
Session_Local = sessionmaker(bind=engine, autocommit=False, autoflush=False)
33+
34+
35+
Base = declarative_base()
36+
37+
38+
def get_db():
39+
db = Session_Local()
40+
try:
41+
yield db
42+
finally:
43+
db.close()
44+
45+
46+
# Example database URLs in config.py:
47+
# SQLite: "sqlite:///./sql_app.db"
48+
# PostgreSQL: "postgresql://user:password@localhost:5432/db_name"

src/paste/logging.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from typing import Any, Dict
2+
3+
from pydantic import BaseModel
4+
5+
6+
class LogConfig(BaseModel):
7+
"""Logging configuration to be set for the server"""
8+
9+
LOGGER_NAME: str = "paste"
10+
LOG_FORMAT: str = "%(levelprefix)s | %(asctime)s | %(message)s"
11+
LOG_LEVEL: str = "DEBUG"
12+
13+
# Logging config
14+
version: int = 1
15+
disable_existing_loggers: bool = False
16+
formatters: Dict[str, Dict[str, str]] = {
17+
"default": {
18+
"()": "uvicorn.logging.DefaultFormatter",
19+
"fmt": LOG_FORMAT,
20+
"datefmt": "%Y-%m-%d %H:%M:%S",
21+
},
22+
}
23+
handlers: Dict[str, Dict[str, Any]] = {
24+
"default": {
25+
"formatter": "default",
26+
"class": "logging.StreamHandler",
27+
"stream": "ext://sys.stderr",
28+
},
29+
}
30+
loggers: Dict[str, Dict[str, Any]] = {
31+
LOGGER_NAME: {"handlers": ["default"], "level": LOG_LEVEL},
32+
}

0 commit comments

Comments
 (0)