Skip to content
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
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.11.3
3.11
24 changes: 13 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
# Dockerfile

# pull the official docker image
FROM python:3.11.1-slim AS builder
FROM python:3.11.3-slim

# install PDM
RUN pip install -U pip setuptools wheel
RUN pip install pdm
RUN pip install -U pip setuptools wheel && \
pip install pdm

# copy files
COPY pyproject.toml pdm.lock README.md /project/
COPY . /project/
WORKDIR /project

# copy dependency files first for better layer caching
COPY pyproject.toml pdm.lock README.md ./

WORKDIR /project
# install dependencies (this layer is cached unless lock file changes)
RUN pdm install --no-self

RUN pdm install
RUN chmod +x docker-entrypoint.sh
# copy the rest of the source code
COPY . .

RUN chmod +x /project/docker-entrypoint.sh

EXPOSE 8080

ENTRYPOINT ["/project/docker-entrypoint.sh"]
CMD ["pdm", "run", "start"]
33 changes: 33 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.PHONY: help sync run dev test make-migration migrate docker-dev docker-dev-down docker-dev-build

.DEFAULT_GOAL := help

help: ## Show this help message
@awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m<target>\033[0m\n\nTargets:\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)

sync: pyproject.toml ## Install dependencies via pdm sync
pdm sync

run: pyproject.toml ## Run the application
pdm run start

dev: pyproject.toml ## Run the application in development mode
pdm run dev

test: pyproject.toml ## Run the test suite
pdm run test

make-migration: pyproject.toml ## Generate a new database migration
pdm run make_migration

migrate: pyproject.toml ## Apply database migrations
pdm run migrate

docker-dev-run: dev/docker-compose.yml ## Start development containers
docker-compose -f dev/docker-compose.yml up

docker-dev-down: dev/docker-compose.yml ## Stop development containers
docker-compose -f dev/docker-compose.yml down

docker-dev-build: dev/docker-compose.yml ## Build development containers
docker-compose -f dev/docker-compose.yml build
19 changes: 10 additions & 9 deletions alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,30 @@
import sys
from logging.config import fileConfig

from sqlalchemy import engine_from_config
from sqlalchemy import pool
from sqlalchemy import engine_from_config, pool

from alembic import context

# Add the src directory to Python path
# Add the src directory to Python path explicitly before importing app modules
current_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
src_dir = os.path.join(current_dir, "src")
sys.path.append(src_dir)
if src_dir not in sys.path:
sys.path.insert(0, src_dir)

# Import your models and Base
from paste.database import Base
# Import your models and Base after path setup
from paste.config import get_settings # noqa: E402
from paste.database import Base # noqa: E402

# Import all your models here so Base.metadata is populated
from paste.models import Paste # noqa: F401, E402

# Import all your models here
# this is the Alembic Config object
config = context.config

# Interpret the config file for Python logging.
if config.config_file_name is not None:
fileConfig(config.config_file_name)

from paste.config import get_settings

config.set_main_option("sqlalchemy.url", get_settings().SQLALCHEMY_DATABASE_URL)


Expand Down
67 changes: 67 additions & 0 deletions dev/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
services:
postgres:
image: postgres:15-alpine
container_name: postgres15
restart: unless-stopped
environment:
POSTGRES_DB: pastedb
POSTGRES_USER: postgres
POSTGRES_PASSWORD: mytestpassword
volumes:
- postgres_data:/var/lib/postgresql/data
ports:
- "5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d pastedb"]
interval: 10s
timeout: 5s
retries: 5

rustfs:
image: rustfs/rustfs:1.0.0-alpha.89
container_name: rustfs
restart: unless-stopped
user: root
ports:
- "9000:9000" # S3 API endpoint
- "9001:9001" # Console UI
security_opt:
- "no-new-privileges:true"
environment:
- RUSTFS_VOLUMES=/data{1...4}
- RUSTFS_ADDRESS=0.0.0.0:9000
- RUSTFS_CONSOLE_ENABLE=true
- RUSTFS_CONSOLE_ADDRESS=0.0.0.0:9001
- RUSTFS_ACCESS_KEY=minioadmin
- RUSTFS_SECRET_KEY=minioadmin123
volumes:
- data1:/data1
- data2:/data2
- data3:/data3
- data4:/data4

myapp:
build:
context: ../
dockerfile: Dockerfile
environment:
MINIO_CLIENT_LINK: http://rustfs:9000
MINIO_ACCESS_KEY: minioadmin
MINIO_SECRET_KEY: minioadmin123
MINIO_BUCKET_NAME: pastebucket
BASE_URL: http://127.0.0.1:8082
SQLALCHEMY_DATABASE_URL: postgresql://postgres:mytestpassword@postgres:5432/pastedb
ports:
- "8082:8080"
entrypoint: ["/project/docker-entrypoint.sh"]
command: ["pdm", "run", "dev"]
depends_on:
postgres:
condition: service_healthy

volumes:
postgres_data:
data1:
data2:
data3:
data4:
9 changes: 0 additions & 9 deletions docker-compose.yaml

This file was deleted.

6 changes: 3 additions & 3 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/sh
set -e

# Run migrations
echo "Running database migrations..."
pdm run migrate

# Execute the main command
exec "$@"
echo "Starting application..."
exec "$@"
Loading
Loading