feat: add /api/version endpoint with IMAGE_TAG; validate in ci healthcheck
Some checks are pending
CI/CD → Deploy via SSH / Build & Push Docker Images (push) Waiting to run
CI/CD → Deploy via SSH / Deploy via SSH (push) Blocked by required conditions
CI/CD → Deploy via SSH / Validate HTTPS & Endpoints (push) Blocked by required conditions

This commit is contained in:
MatheusAlves96 2026-04-21 00:23:25 -03:00
parent b0eb12c17d
commit 849789d376
4 changed files with 23 additions and 0 deletions

View file

@ -188,6 +188,13 @@ jobs:
echo "Properties API: $STATUS" echo "Properties API: $STATUS"
[ "$STATUS" = "200" ] || (echo "❌ Properties API falhou ($STATUS)" && exit 1) [ "$STATUS" = "200" ] || (echo "❌ Properties API falhou ($STATUS)" && exit 1)
- name: Check deployed version matches image tag
run: |
RESPONSE=$(curl -s --max-time 10 "https://${{ vars.DOMAIN }}/api/version")
echo "Version response: $RESPONSE"
echo "$RESPONSE" | grep -q "${{ needs.build.outputs.image_tag }}" \
|| (echo "❌ Version tag não confere — esperado: ${{ needs.build.outputs.image_tag }}" && exit 1)
- name: All checks passed - name: All checks passed
run: | run: |
echo "✅ Deploy validado com sucesso!" echo "✅ Deploy validado com sucesso!"

View file

@ -53,6 +53,7 @@ def create_app(config_name: str | None = None) -> Flask:
from app.routes.analytics import analytics_bp, _should_track, record_page_view from app.routes.analytics import analytics_bp, _should_track, record_page_view
from app.routes.config import config_bp from app.routes.config import config_bp
from app.routes.agents import agents_public_bp, agents_admin_bp from app.routes.agents import agents_public_bp, agents_admin_bp
from app.routes.version import version_bp
app.register_blueprint(homepage_bp) app.register_blueprint(homepage_bp)
app.register_blueprint(properties_bp) app.register_blueprint(properties_bp)
@ -65,6 +66,7 @@ def create_app(config_name: str | None = None) -> Flask:
app.register_blueprint(config_bp) app.register_blueprint(config_bp)
app.register_blueprint(agents_public_bp) app.register_blueprint(agents_public_bp)
app.register_blueprint(agents_admin_bp) app.register_blueprint(agents_admin_bp)
app.register_blueprint(version_bp)
@app.route("/health") @app.route("/health")
def health(): def health():

View file

@ -0,0 +1,13 @@
import os
from flask import Blueprint, jsonify
version_bp = Blueprint("version", __name__)
@version_bp.get("/api/version")
def get_version():
"""Returns the running image tag — injected at deploy time via IMAGE_TAG env var."""
return jsonify({
"version": os.environ.get("IMAGE_TAG", "dev"),
"env": os.environ.get("FLASK_ENV", "development"),
})

View file

@ -26,6 +26,7 @@ services:
FLASK_ENV: production FLASK_ENV: production
FLASK_APP: app FLASK_APP: app
CORS_ORIGINS: https://${DOMAIN} CORS_ORIGINS: https://${DOMAIN}
IMAGE_TAG: ${IMAGE_TAG:-latest}
depends_on: depends_on:
db: db:
condition: service_healthy condition: service_healthy