Skip to content

Commit e4309c5

Browse files
Merge pull request #89 from Mr-Sunglasses/migrate-from-minio
2 parents 851b9ac + 619d822 commit e4309c5

12 files changed

Lines changed: 432 additions & 255 deletions

File tree

.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.11.3
1+
3.11

Dockerfile

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
# Dockerfile
2-
31
# pull the official docker image
4-
FROM python:3.11.1-slim AS builder
2+
FROM python:3.11.3-slim
53

64
# install PDM
7-
RUN pip install -U pip setuptools wheel
8-
RUN pip install pdm
5+
RUN pip install -U pip setuptools wheel && \
6+
pip install pdm
97

10-
# copy files
11-
COPY pyproject.toml pdm.lock README.md /project/
12-
COPY . /project/
8+
WORKDIR /project
139

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

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

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

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

2121
EXPOSE 8080
22+
23+
ENTRYPOINT ["/project/docker-entrypoint.sh"]
2224
CMD ["pdm", "run", "start"]

Makefile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.PHONY: help sync run dev test make-migration migrate docker-dev docker-dev-down docker-dev-build
2+
3+
.DEFAULT_GOAL := help
4+
5+
help: ## Show this help message
6+
@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)
7+
8+
sync: pyproject.toml ## Install dependencies via pdm sync
9+
pdm sync
10+
11+
run: pyproject.toml ## Run the application
12+
pdm run start
13+
14+
dev: pyproject.toml ## Run the application in development mode
15+
pdm run dev
16+
17+
test: pyproject.toml ## Run the test suite
18+
pdm run test
19+
20+
make-migration: pyproject.toml ## Generate a new database migration
21+
pdm run make_migration
22+
23+
migrate: pyproject.toml ## Apply database migrations
24+
pdm run migrate
25+
26+
docker-dev-run: dev/docker-compose.yml ## Start development containers
27+
docker-compose -f dev/docker-compose.yml up
28+
29+
docker-dev-down: dev/docker-compose.yml ## Stop development containers
30+
docker-compose -f dev/docker-compose.yml down
31+
32+
docker-dev-build: dev/docker-compose.yml ## Build development containers
33+
docker-compose -f dev/docker-compose.yml build

alembic/env.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,30 @@
33
import sys
44
from logging.config import fileConfig
55

6-
from sqlalchemy import engine_from_config
7-
from sqlalchemy import pool
6+
from sqlalchemy import engine_from_config, pool
87

98
from alembic import context
109

11-
# Add the src directory to Python path
10+
# Add the src directory to Python path explicitly before importing app modules
1211
current_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
1312
src_dir = os.path.join(current_dir, "src")
14-
sys.path.append(src_dir)
13+
if src_dir not in sys.path:
14+
sys.path.insert(0, src_dir)
1515

16-
# Import your models and Base
17-
from paste.database import Base
16+
# Import your models and Base after path setup
17+
from paste.config import get_settings # noqa: E402
18+
from paste.database import Base # noqa: E402
19+
20+
# Import all your models here so Base.metadata is populated
21+
from paste.models import Paste # noqa: F401, E402
1822

19-
# Import all your models here
2023
# this is the Alembic Config object
2124
config = context.config
2225

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

27-
from paste.config import get_settings
28-
2930
config.set_main_option("sqlalchemy.url", get_settings().SQLALCHEMY_DATABASE_URL)
3031

3132

dev/docker-compose.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
services:
2+
postgres:
3+
image: postgres:15-alpine
4+
container_name: postgres15
5+
restart: unless-stopped
6+
environment:
7+
POSTGRES_DB: pastedb
8+
POSTGRES_USER: postgres
9+
POSTGRES_PASSWORD: mytestpassword
10+
volumes:
11+
- postgres_data:/var/lib/postgresql/data
12+
ports:
13+
- "5432:5432"
14+
healthcheck:
15+
test: ["CMD-SHELL", "pg_isready -U postgres -d pastedb"]
16+
interval: 10s
17+
timeout: 5s
18+
retries: 5
19+
20+
rustfs:
21+
image: rustfs/rustfs:1.0.0-alpha.89
22+
container_name: rustfs
23+
restart: unless-stopped
24+
user: root
25+
ports:
26+
- "9000:9000" # S3 API endpoint
27+
- "9001:9001" # Console UI
28+
security_opt:
29+
- "no-new-privileges:true"
30+
environment:
31+
- RUSTFS_VOLUMES=/data{1...4}
32+
- RUSTFS_ADDRESS=0.0.0.0:9000
33+
- RUSTFS_CONSOLE_ENABLE=true
34+
- RUSTFS_CONSOLE_ADDRESS=0.0.0.0:9001
35+
- RUSTFS_ACCESS_KEY=minioadmin
36+
- RUSTFS_SECRET_KEY=minioadmin123
37+
volumes:
38+
- data1:/data1
39+
- data2:/data2
40+
- data3:/data3
41+
- data4:/data4
42+
43+
myapp:
44+
build:
45+
context: ../
46+
dockerfile: Dockerfile
47+
environment:
48+
MINIO_CLIENT_LINK: http://rustfs:9000
49+
MINIO_ACCESS_KEY: minioadmin
50+
MINIO_SECRET_KEY: minioadmin123
51+
MINIO_BUCKET_NAME: pastebucket
52+
BASE_URL: http://127.0.0.1:8082
53+
SQLALCHEMY_DATABASE_URL: postgresql://postgres:mytestpassword@postgres:5432/pastedb
54+
ports:
55+
- "8082:8080"
56+
entrypoint: ["/project/docker-entrypoint.sh"]
57+
command: ["pdm", "run", "dev"]
58+
depends_on:
59+
postgres:
60+
condition: service_healthy
61+
62+
volumes:
63+
postgres_data:
64+
data1:
65+
data2:
66+
data3:
67+
data4:

docker-compose.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.

docker-entrypoint.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/bin/sh
22
set -e
33

4-
# Run migrations
4+
echo "Running database migrations..."
55
pdm run migrate
66

7-
# Execute the main command
8-
exec "$@"
7+
echo "Starting application..."
8+
exec "$@"

0 commit comments

Comments
 (0)