This commit is contained in:
Bryson Shepard 2025-05-18 01:00:52 -05:00
parent 2e2997afb6
commit b572dfe002
4 changed files with 29 additions and 5 deletions

View File

@ -28,6 +28,14 @@ up:
$(DOCKER_COMPOSE) up --build -d $(DOCKER_COMPOSE) up --build -d
@$(MAKE) wait @$(MAKE) wait
up-nobuild:
@if [ ! -f $(ENV_FILE) ]; then \
echo "[⚙] Generating .env from example..."; \
cp $(ENV_EXAMPLE) $(ENV_FILE); \
fi
$(DOCKER_COMPOSE) up -d
@$(MAKE) wait
down: down:
$(DOCKER_COMPOSE) down $(DOCKER_COMPOSE) down

View File

@ -7,25 +7,30 @@ db = SQLAlchemy()
migrate = Migrate() migrate = Migrate()
login_manager = LoginManager() login_manager = LoginManager()
def create_app(): def create_app():
app = Flask(__name__) app = Flask(__name__)
app.config.from_object('config.Config') app.config.from_object('config.Config')
# Initialize core extensions
db.init_app(app) db.init_app(app)
migrate.init_app(app, db) migrate.init_app(app, db)
login_manager.init_app(app) login_manager.init_app(app)
login_manager.login_view = 'auth.login' # Optional: redirect for @login_required
# Register Blueprints
from .core.routes import core from .core.routes import core
from .core.auth import auth from .core.auth import auth
app.register_blueprint(core) app.register_blueprint(core)
app.register_blueprint(auth) app.register_blueprint(auth, url_prefix="/auth")
# CLI command registration must be inside create_app # Register CLI commands
from .cli import seed_admin from .cli import seed_admin
app.cli.add_command(seed_admin) app.cli.add_command(seed_admin)
return app return app
@login_manager.user_loader @login_manager.user_loader
def load_user(user_id): def load_user(user_id):
from .core.models import User from .core.models import User

View File

@ -17,6 +17,10 @@ ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg'}
def allowed_file(filename): def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@core.route("/health")
def health_check():
return "OK", 200
@core.route('/') @core.route('/')
def index(): def index():
submissions = Submission.query.order_by(Submission.timestamp.desc()).limit(6).all() submissions = Submission.query.order_by(Submission.timestamp.desc()).limit(6).all()

View File

@ -18,9 +18,9 @@ services:
depends_on: depends_on:
- db - db
healthcheck: healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5000"] test: ["CMD", "curl", "-f", "http://localhost:5000/health"]
interval: 30s interval: 10s
timeout: 10s timeout: 5s
retries: 5 retries: 5
command: > command: >
bash -c " bash -c "
@ -32,6 +32,12 @@ services:
echo '[✔] Waiting for MySQL to be ready...' echo '[✔] Waiting for MySQL to be ready...'
until nc -z ${MYSQL_HOST} ${MYSQL_PORT}; do sleep 1; done until nc -z ${MYSQL_HOST} ${MYSQL_PORT}; do sleep 1; done
echo '[✔] Ensuring migration structure...'
if [ ! -d 'migrations' ]; then
echo '[] Running flask db init...'
flask db init
fi
echo '[] Autogenerating migration...' echo '[] Autogenerating migration...'
flask db migrate -m 'auto' || echo '[] No changes detected.' flask db migrate -m 'auto' || echo '[] No changes detected.'
@ -49,6 +55,7 @@ services:
flask run --host=0.0.0.0 flask run --host=0.0.0.0
" "
db: db:
image: mysql:8 image: mysql:8
restart: unless-stopped restart: unless-stopped