feat: deploy via SSH with port 8080, idempotent migrations
This commit is contained in:
@@ -33,75 +33,61 @@ jobs:
|
|||||||
- name: Run Tests
|
- name: Run Tests
|
||||||
run: pytest tests/ -v --tb=short
|
run: pytest tests/ -v --tb=short
|
||||||
|
|
||||||
# ── 2. Deploy to Docker LXC (only main branch & tags) ─────────────
|
# ── 2. Deploy to Docker LXC via SSH ─────────────────────────────────
|
||||||
deploy:
|
deploy:
|
||||||
needs: test
|
needs: test
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: gitea.event_name == 'push'
|
if: gitea.event_name == 'push'
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Deploy via SSH
|
||||||
run: |
|
uses: appleboy/ssh-action@v1.0.0
|
||||||
cd /tmp
|
with:
|
||||||
rm -rf adiuva-api-deploy
|
host: ${{ secrets.SSH_HOST }}
|
||||||
git clone --depth 1 "http://10.0.0.119:3000/${GITHUB_REPOSITORY}.git" adiuva-api-deploy || \
|
username: ${{ secrets.SSH_USER }}
|
||||||
git clone --depth 1 "http://10.0.0.119:3000/${GITHUB_REPOSITORY}.git" adiuva-api-deploy
|
key: ${{ secrets.SSH_KEY }}
|
||||||
cd adiuva-api-deploy && git checkout "${GITHUB_SHA}" 2>/dev/null || true
|
script: |
|
||||||
|
set -e
|
||||||
|
DEPLOY_DIR="/opt/adiuva-api"
|
||||||
|
REPO_URL="http://10.0.0.119:3000/${{ gitea.repository }}.git"
|
||||||
|
TAG="${{ gitea.ref_name }}"
|
||||||
|
|
||||||
- name: Sync to deploy directory
|
# ── Pull latest code ──
|
||||||
run: |
|
cd /tmp && rm -rf adiuva-api-deploy
|
||||||
DEPLOY_DIR="/opt/adiuva-api"
|
git clone --depth 1 --branch "${TAG}" "${REPO_URL}" adiuva-api-deploy
|
||||||
SRC="/tmp/adiuva-api-deploy"
|
|
||||||
mkdir -p "$DEPLOY_DIR"
|
|
||||||
|
|
||||||
# Sync source, preserve .env and volumes
|
# ── Sync source (preserve .env) ──
|
||||||
cp -rf "$SRC/app/" "$SRC/alembic/" "$SRC/alembic.ini" "$SRC/Dockerfile" "$SRC/docker-compose.yml" "$SRC/requirements.txt" "$DEPLOY_DIR/"
|
cp -rf /tmp/adiuva-api-deploy/app/ \
|
||||||
|
/tmp/adiuva-api-deploy/alembic/ \
|
||||||
|
/tmp/adiuva-api-deploy/alembic.ini \
|
||||||
|
/tmp/adiuva-api-deploy/Dockerfile \
|
||||||
|
/tmp/adiuva-api-deploy/docker-compose.yml \
|
||||||
|
/tmp/adiuva-api-deploy/requirements.txt \
|
||||||
|
"$DEPLOY_DIR/"
|
||||||
|
rm -rf /tmp/adiuva-api-deploy
|
||||||
|
|
||||||
- name: Build & restart services
|
# ── Verify .env ──
|
||||||
run: |
|
if [ ! -f "$DEPLOY_DIR/.env" ]; then
|
||||||
cd /opt/adiuva-api
|
echo "❌ $DEPLOY_DIR/.env not found. Create it before deploying."
|
||||||
docker compose up -d --build --remove-orphans
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Run database migrations
|
# ── Build & restart ──
|
||||||
run: |
|
cd "$DEPLOY_DIR"
|
||||||
cd /opt/adiuva-api
|
docker compose down --remove-orphans || true
|
||||||
docker compose exec -T app alembic upgrade head
|
docker compose up -d --build
|
||||||
|
|
||||||
- name: Verify deployment
|
# ── Migrations ──
|
||||||
run: |
|
docker compose exec -T app alembic upgrade head
|
||||||
echo "Waiting for app to be ready..."
|
|
||||||
sleep 5
|
|
||||||
|
|
||||||
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/api/v1/health)
|
# ── Health check ──
|
||||||
if [ "$HTTP_CODE" -eq 200 ]; then
|
echo "Waiting for app..."
|
||||||
echo "✅ API is healthy (HTTP ${HTTP_CODE})"
|
sleep 5
|
||||||
else
|
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/api/v1/health)
|
||||||
echo "❌ Health check failed (HTTP ${HTTP_CODE})"
|
if [ "$HTTP_CODE" -eq 200 ]; then
|
||||||
docker compose -f /opt/adiuva-api/docker-compose.yml logs app --tail=50
|
echo "✅ API is healthy (HTTP ${HTTP_CODE})"
|
||||||
exit 1
|
else
|
||||||
fi
|
echo "❌ Health check failed (HTTP ${HTTP_CODE})"
|
||||||
|
docker compose logs app --tail=50
|
||||||
- name: Create Gitea Release (tags only)
|
exit 1
|
||||||
if: startsWith(gitea.ref, 'refs/tags/')
|
fi
|
||||||
run: |
|
|
||||||
GITEA_URL="http://10.0.0.119:3000"
|
|
||||||
TAG="${GITHUB_REF_NAME}"
|
|
||||||
REPO="${GITHUB_REPOSITORY}"
|
|
||||||
TOKEN="${{ gitea.token }}"
|
|
||||||
|
|
||||||
RELEASE_ID=$(curl -sf \
|
|
||||||
-H "Authorization: token ${TOKEN}" \
|
|
||||||
"${GITEA_URL}/api/v1/repos/${REPO}/releases/tags/${TAG}" \
|
|
||||||
| grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
|
||||||
|
|
||||||
if [ -z "$RELEASE_ID" ]; then
|
|
||||||
curl -sf \
|
|
||||||
-X POST \
|
|
||||||
-H "Authorization: token ${TOKEN}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "{\"tag_name\":\"${TAG}\",\"name\":\"Adiuva API ${TAG}\",\"body\":\"Deployed to Docker LXC\"}" \
|
|
||||||
"${GITEA_URL}/api/v1/repos/${REPO}/releases"
|
|
||||||
echo "✅ Release ${TAG} created"
|
|
||||||
else
|
|
||||||
echo "ℹ️ Release ${TAG} already exists (ID: ${RELEASE_ID})"
|
|
||||||
fi
|
|
||||||
@@ -40,7 +40,7 @@ def upgrade() -> None:
|
|||||||
sa.Column("id", postgresql.UUID(as_uuid=False), nullable=False),
|
sa.Column("id", postgresql.UUID(as_uuid=False), nullable=False),
|
||||||
sa.Column("email", sa.String(255), nullable=False),
|
sa.Column("email", sa.String(255), nullable=False),
|
||||||
sa.Column("password_hash", sa.String(255), nullable=False),
|
sa.Column("password_hash", sa.String(255), nullable=False),
|
||||||
sa.Column("tier", sa.Enum("free", "pro", "power", "team", name="billing_tier"), nullable=False, server_default="free"),
|
sa.Column("tier", sa.Enum("free", "pro", "power", "team", name="billing_tier", create_type=False), nullable=False, server_default="free"),
|
||||||
sa.Column("stripe_customer_id", sa.String(255), nullable=True),
|
sa.Column("stripe_customer_id", sa.String(255), nullable=True),
|
||||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
|
||||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
|
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
|
||||||
@@ -70,7 +70,7 @@ def upgrade() -> None:
|
|||||||
sa.Column("id", postgresql.UUID(as_uuid=False), nullable=False),
|
sa.Column("id", postgresql.UUID(as_uuid=False), nullable=False),
|
||||||
sa.Column("user_id", postgresql.UUID(as_uuid=False), nullable=False),
|
sa.Column("user_id", postgresql.UUID(as_uuid=False), nullable=False),
|
||||||
sa.Column("stripe_subscription_id", sa.String(255), nullable=True),
|
sa.Column("stripe_subscription_id", sa.String(255), nullable=True),
|
||||||
sa.Column("tier", sa.Enum("free", "pro", "power", "team", name="billing_tier"), nullable=False, server_default="free"),
|
sa.Column("tier", sa.Enum("free", "pro", "power", "team", name="billing_tier", create_type=False), nullable=False, server_default="free"),
|
||||||
sa.Column("status", sa.String(50), nullable=False, server_default="free"),
|
sa.Column("status", sa.String(50), nullable=False, server_default="free"),
|
||||||
sa.Column("current_period_end", sa.DateTime(timezone=True), nullable=True),
|
sa.Column("current_period_end", sa.DateTime(timezone=True), nullable=True),
|
||||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
|
||||||
@@ -125,7 +125,7 @@ def upgrade() -> None:
|
|||||||
sa.Column("category", sa.String(100), nullable=False, server_default=""),
|
sa.Column("category", sa.String(100), nullable=False, server_default=""),
|
||||||
sa.Column("price_cents", sa.Integer, nullable=False, server_default="0"),
|
sa.Column("price_cents", sa.Integer, nullable=False, server_default="0"),
|
||||||
sa.Column("permissions", sa.Text, nullable=False, server_default="[]"),
|
sa.Column("permissions", sa.Text, nullable=False, server_default="[]"),
|
||||||
sa.Column("status", sa.Enum("pending_review", "approved", "rejected", name="plugin_status"), nullable=False, server_default="pending_review"),
|
sa.Column("status", sa.Enum("pending_review", "approved", "rejected", name="plugin_status", create_type=False), nullable=False, server_default="pending_review"),
|
||||||
sa.Column("s3_package_key", sa.String(500), nullable=True),
|
sa.Column("s3_package_key", sa.String(500), nullable=True),
|
||||||
sa.Column("install_count", sa.Integer, nullable=False, server_default="0"),
|
sa.Column("install_count", sa.Integer, nullable=False, server_default="0"),
|
||||||
sa.Column("avg_rating", sa.Float, nullable=False, server_default="0.0"),
|
sa.Column("avg_rating", sa.Float, nullable=False, server_default="0.0"),
|
||||||
@@ -157,7 +157,7 @@ def upgrade() -> None:
|
|||||||
sa.Column("id", postgresql.UUID(as_uuid=False), nullable=False),
|
sa.Column("id", postgresql.UUID(as_uuid=False), nullable=False),
|
||||||
sa.Column("plugin_id", sa.String(255), nullable=False),
|
sa.Column("plugin_id", sa.String(255), nullable=False),
|
||||||
sa.Column("reviewer_id", postgresql.UUID(as_uuid=False), nullable=True),
|
sa.Column("reviewer_id", postgresql.UUID(as_uuid=False), nullable=True),
|
||||||
sa.Column("decision", sa.Enum("approved", "rejected", name="review_decision"), nullable=False),
|
sa.Column("decision", sa.Enum("approved", "rejected", name="review_decision", create_type=False), nullable=False),
|
||||||
sa.Column("notes", sa.Text, nullable=True),
|
sa.Column("notes", sa.Text, nullable=True),
|
||||||
sa.Column("reviewed_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
|
sa.Column("reviewed_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
|
||||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ services:
|
|||||||
app:
|
app:
|
||||||
build: .
|
build: .
|
||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "8080:8000"
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- path: .env
|
||||||
|
required: false
|
||||||
environment:
|
environment:
|
||||||
DATABASE_URL: postgresql+asyncpg://postgres:postgres@db:5432/adiuva
|
DATABASE_URL: postgresql+asyncpg://postgres:postgres@db:5432/adiuva
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|||||||
Reference in New Issue
Block a user