Skip to content

Commit 107c3af

Browse files
Merge pull request #78 from Mr-Sunglasses/feat/minio+v2
Feat/minio+v2
2 parents 4fc2182 + 3e67444 commit 107c3af

28 files changed

+1854
-365
lines changed

.env.example

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
MINIO_CLIENT_LINK=
2+
MINIO_ACCESS_KEY=
3+
MINIO_SECRET_KEY=
4+
MINIO_BUCKET_NAME=
5+
BASE_URL=
6+
SQLALCHEMY_DATABASE_URL=

.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

Dockerfile

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ RUN pip install pdm
99

1010
# copy files
1111
COPY pyproject.toml pdm.lock README.md /project/
12-
COPY data/ project/data
13-
COPY src/ /project/src
12+
COPY . /project/
1413

1514

1615
WORKDIR /project
1716

1817
RUN pdm install
18+
RUN chmod +x docker-entrypoint.sh
19+
1920

2021
EXPOSE 8080
2122
CMD ["pdm", "run", "start"]

alembic.ini

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# A generic, single database configuration.
2+
3+
[alembic]
4+
# path to migration scripts
5+
# Use forward slashes (/) also on windows to provide an os agnostic path
6+
script_location = alembic
7+
8+
# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
9+
# Uncomment the line below if you want the files to be prepended with date and time
10+
# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
11+
# for all available tokens
12+
# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
13+
14+
# sys.path path, will be prepended to sys.path if present.
15+
# defaults to the current working directory.
16+
prepend_sys_path = .
17+
18+
# timezone to use when rendering the date within the migration file
19+
# as well as the filename.
20+
# If specified, requires the python>=3.9 or backports.zoneinfo library and tzdata library.
21+
# Any required deps can installed by adding `alembic[tz]` to the pip requirements
22+
# string value is passed to ZoneInfo()
23+
# leave blank for localtime
24+
# timezone =
25+
26+
# max length of characters to apply to the "slug" field
27+
# truncate_slug_length = 40
28+
29+
# set to 'true' to run the environment during
30+
# the 'revision' command, regardless of autogenerate
31+
# revision_environment = false
32+
33+
# set to 'true' to allow .pyc and .pyo files without
34+
# a source .py file to be detected as revisions in the
35+
# versions/ directory
36+
# sourceless = false
37+
38+
# version location specification; This defaults
39+
# to alembic/versions. When using multiple version
40+
# directories, initial revisions must be specified with --version-path.
41+
# The path separator used here should be the separator specified by "version_path_separator" below.
42+
# version_locations = %(here)s/bar:%(here)s/bat:alembic/versions
43+
44+
# version path separator; As mentioned above, this is the character used to split
45+
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
46+
# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas.
47+
# Valid values for version_path_separator are:
48+
#
49+
# version_path_separator = :
50+
# version_path_separator = ;
51+
# version_path_separator = space
52+
# version_path_separator = newline
53+
#
54+
# Use os.pathsep. Default configuration used for new projects.
55+
version_path_separator = os
56+
57+
# set to 'true' to search source files recursively
58+
# in each "version_locations" directory
59+
# new in Alembic version 1.10
60+
# recursive_version_locations = false
61+
62+
# the output encoding used when revision files
63+
# are written from script.py.mako
64+
# output_encoding = utf-8
65+
66+
sqlalchemy.url = driver://user:pass@localhost/dbname
67+
68+
69+
[post_write_hooks]
70+
# post_write_hooks defines scripts or Python functions that are run
71+
# on newly generated revision scripts. See the documentation for further
72+
# detail and examples
73+
74+
# format using "black" - use the console_scripts runner, against the "black" entrypoint
75+
# hooks = black
76+
# black.type = console_scripts
77+
# black.entrypoint = black
78+
# black.options = -l 79 REVISION_SCRIPT_FILENAME
79+
80+
# lint with attempts to fix using "ruff" - use the exec runner, execute a binary
81+
# hooks = ruff
82+
# ruff.type = exec
83+
# ruff.executable = %(here)s/.venv/bin/ruff
84+
# ruff.options = --fix REVISION_SCRIPT_FILENAME
85+
86+
# Logging configuration
87+
[loggers]
88+
keys = root,sqlalchemy,alembic
89+
90+
[handlers]
91+
keys = console
92+
93+
[formatters]
94+
keys = generic
95+
96+
[logger_root]
97+
level = WARNING
98+
handlers = console
99+
qualname =
100+
101+
[logger_sqlalchemy]
102+
level = WARNING
103+
handlers =
104+
qualname = sqlalchemy.engine
105+
106+
[logger_alembic]
107+
level = INFO
108+
handlers =
109+
qualname = alembic
110+
111+
[handler_console]
112+
class = StreamHandler
113+
args = (sys.stderr,)
114+
level = NOTSET
115+
formatter = generic
116+
117+
[formatter_generic]
118+
format = %(levelname)-5.5s [%(name)s] %(message)s
119+
datefmt = %H:%M:%S

alembic/README

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Generic single-database configuration.

alembic/env.py

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# migrations/env.py
2+
import os
3+
import sys
4+
from logging.config import fileConfig
5+
6+
from sqlalchemy import engine_from_config
7+
from sqlalchemy import pool
8+
9+
from alembic import context
10+
11+
# Add the src directory to Python path
12+
current_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
13+
src_dir = os.path.join(current_dir, "src")
14+
sys.path.append(src_dir)
15+
16+
# Import your models and Base
17+
from paste.database import Base
18+
# Import all your models here
19+
from paste.models import Paste
20+
# this is the Alembic Config object
21+
config = context.config
22+
23+
# Interpret the config file for Python logging.
24+
if config.config_file_name is not None:
25+
fileConfig(config.config_file_name)
26+
27+
from paste.config import get_settings
28+
29+
config.set_main_option("sqlalchemy.url", get_settings().SQLALCHEMY_DATABASE_URL)
30+
31+
32+
# Add metadata to the context
33+
target_metadata = Base.metadata
34+
35+
36+
def run_migrations_offline() -> None:
37+
"""Run migrations in 'offline' mode."""
38+
url = config.get_main_option("sqlalchemy.url")
39+
context.configure(
40+
url=url,
41+
target_metadata=target_metadata,
42+
literal_binds=True,
43+
dialect_opts={"paramstyle": "named"},
44+
)
45+
46+
with context.begin_transaction():
47+
context.run_migrations()
48+
49+
def run_migrations_online() -> None:
50+
connectable = engine_from_config(
51+
config.get_section(config.config_ini_section, {}),
52+
prefix="sqlalchemy.",
53+
poolclass=pool.NullPool,
54+
)
55+
56+
with connectable.connect() as connection:
57+
context.configure(
58+
connection=connection, target_metadata=target_metadata
59+
)
60+
61+
with context.begin_transaction():
62+
context.run_migrations()
63+
64+
if context.is_offline_mode():
65+
run_migrations_offline()
66+
else:
67+
run_migrations_online()

alembic/script.py.mako

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""${message}
2+
3+
Revision ID: ${up_revision}
4+
Revises: ${down_revision | comma,n}
5+
Create Date: ${create_date}
6+
7+
"""
8+
from typing import Sequence, Union
9+
10+
from alembic import op
11+
import sqlalchemy as sa
12+
${imports if imports else ""}
13+
14+
# revision identifiers, used by Alembic.
15+
revision: str = ${repr(up_revision)}
16+
down_revision: Union[str, None] = ${repr(down_revision)}
17+
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
18+
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
19+
20+
21+
def upgrade() -> None:
22+
${upgrades if upgrades else "pass"}
23+
24+
25+
def downgrade() -> None:
26+
${downgrades if downgrades else "pass"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""Initial migration
2+
3+
Revision ID: 9513acd42747
4+
Revises:
5+
Create Date: 2025-02-09 02:54:48.803960
6+
7+
"""
8+
from typing import Sequence, Union
9+
10+
from alembic import op
11+
import sqlalchemy as sa
12+
13+
14+
# revision identifiers, used by Alembic.
15+
revision: str = '9513acd42747'
16+
down_revision: Union[str, None] = None
17+
branch_labels: Union[str, Sequence[str], None] = None
18+
depends_on: Union[str, Sequence[str], None] = None
19+
20+
21+
def upgrade() -> None:
22+
# ### commands auto generated by Alembic - please adjust! ###
23+
op.create_table('pastes',
24+
sa.Column('pasteID', sa.String(length=4), nullable=False),
25+
sa.Column('content', sa.Text(), nullable=True),
26+
sa.Column('extension', sa.String(length=50), nullable=True),
27+
sa.Column('s3_link', sa.String(length=500), nullable=True),
28+
sa.Column('created_at', sa.DateTime(), nullable=True),
29+
sa.Column('expiresat', sa.DateTime(), nullable=True),
30+
sa.PrimaryKeyConstraint('pasteID')
31+
)
32+
# ### end Alembic commands ###
33+
34+
35+
def downgrade() -> None:
36+
# ### commands auto generated by Alembic - please adjust! ###
37+
op.drop_table('pastes')
38+
# ### end Alembic commands ###

data/test

-1
This file was deleted.

docker-compose.yaml

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
version: '3.8'
2-
31
services:
42
myapp:
5-
build:
6-
context: .
7-
target: builder
3+
image: mrsunglasses/pastepy:latest
4+
env_file:
5+
- .env
86
ports:
9-
- "8080:8080"
10-
command: ["pdm", "run", "start"]
7+
- "8082:8080"
8+
entrypoint: ["./docker-entrypoint.sh"]
9+
command: ["pdm", "run", "start"]

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 "$@"

0 commit comments

Comments
 (0)