diff --git a/Makefile b/Makefile index 97cfbc9..e9fd655 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,14 @@ up: $(DOCKER_COMPOSE) up --build -d @$(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: $(DOCKER_COMPOSE) down diff --git a/app/__init__.py b/app/__init__.py index 1e1ed8e..4bedb52 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -7,25 +7,30 @@ db = SQLAlchemy() migrate = Migrate() login_manager = LoginManager() + def create_app(): app = Flask(__name__) app.config.from_object('config.Config') + # Initialize core extensions db.init_app(app) migrate.init_app(app, db) 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.auth import auth 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 app.cli.add_command(seed_admin) return app + @login_manager.user_loader def load_user(user_id): from .core.models import User diff --git a/app/core/routes.py b/app/core/routes.py index 9328a49..8725a16 100644 --- a/app/core/routes.py +++ b/app/core/routes.py @@ -17,6 +17,10 @@ ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg'} def allowed_file(filename): return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS +@core.route("/health") +def health_check(): + return "OK", 200 + @core.route('/') def index(): submissions = Submission.query.order_by(Submission.timestamp.desc()).limit(6).all() diff --git a/docker-compose.yml b/docker-compose.yml index 2966a23..f73fd6d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,9 +18,9 @@ services: depends_on: - db healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:5000"] - interval: 30s - timeout: 10s + test: ["CMD", "curl", "-f", "http://localhost:5000/health"] + interval: 10s + timeout: 5s retries: 5 command: > bash -c " @@ -32,6 +32,12 @@ services: echo '[✔] Waiting for MySQL to be ready...' 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...' flask db migrate -m 'auto' || echo '[ℹ] No changes detected.' @@ -49,6 +55,7 @@ services: flask run --host=0.0.0.0 " + db: image: mysql:8 restart: unless-stopped