From ceb7d5ec4bfd6c9b144a1f449d0c45295583a906 Mon Sep 17 00:00:00 2001
From: parsa aghaei
Date: Sun, 9 Aug 2026 22:26:52 +0330
Subject: [PATCH] deploy.yml updated
---
.gitea/workflows/deploy.yml | 85 +++++++++++++++++++++++++++++--------
1 file changed, 67 insertions(+), 18 deletions(-)
diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml
index 66f411fc..6ddf88b7 100644
--- a/.gitea/workflows/deploy.yml
+++ b/.gitea/workflows/deploy.yml
@@ -10,26 +10,75 @@ jobs:
deploy:
runs-on: canina
steps:
- - name: Add IP to hosts and download deploy.sh
+ - name: Add IP to hosts and run deployment directly
env:
BRANCH: ${{ github.ref_name }}
run: |
# 1. اضافه کردن آیپی به فایل hosts رانر تا دامنه حل شود
echo "87.248.133.138 git.parsaaghayi.ir" >> /etc/hosts
-
- # 2. ساختن پوشهی scripts اگر وجود ندارد
- mkdir -p scripts
-
- # 3. دانلود deploy.sh با یک نام جدید (برای شکستن کش رانر)
- wget --no-check-certificate -O scripts/deploy_new.sh \
- "https://git.parsaaghayi.ir/parsa/canina/raw/branch/main/scripts/deploy.sh" || \
- wget --no-check-certificate -O scripts/deploy_new.sh \
- "https://git.parsaaghayi.ir/parsa/canina/raw/branch/develop/scripts/deploy.sh"
-
- # 4. فایل جدید را به نام اصلی تغییر نام بده
- mv scripts/deploy_new.sh scripts/deploy.sh
-
- # 5. به اسکریپت دسترسی بده و اون رو از داخل پوشهی scripts اجرا کن
- chmod +x scripts/deploy.sh
- cd scripts
- ./deploy.sh ${BRANCH}
\ No newline at end of file
+
+ # 2. تعریف متغیرها بر اساس برنچ
+ if [ "$BRANCH" == "develop" ]; then
+ COMPOSE_FILE="compose.stage.yml"
+ TARGET_DIR="/opt/services/canina/stage"
+ BACKEND_HOST="backend_stage"
+ APP_HOST="stage.canina.ir"
+ ADMIN_HOST="stageadmin.canina.ir"
+ API_URL="https://stageapi.canina.ir"
+ CONTAINER_PREFIX="canino_backend_stage"
+ else
+ COMPOSE_FILE="compose.prod.yml"
+ TARGET_DIR="/opt/services/canina/prod"
+ BACKEND_HOST="backend_prod"
+ APP_HOST="canina.ir"
+ ADMIN_HOST="admin.canina.ir"
+ API_URL="https://api.canina.ir"
+ CONTAINER_PREFIX="canino_backend_prod"
+ fi
+
+ # 3. ساخت پوشهی مقصد
+ mkdir -p "$TARGET_DIR"
+
+ # 4. کلون کردن یا آپدیت کردن پروژه
+ if [ ! -d "$TARGET_DIR/.git" ]; then
+ echo "Cloning repository into $TARGET_DIR..."
+ git clone -b "$BRANCH" https://git.parsaaghayi.ir/parsa/canina.git "$TARGET_DIR"
+ else
+ echo "Pulling latest changes in $TARGET_DIR..."
+ cd "$TARGET_DIR"
+ git fetch origin "$BRANCH"
+ git reset --hard "origin/$BRANCH"
+ cd -
+ fi
+
+ # 5. کپی کردن فایلهای کانفیگ از پوشهی جاری (جایی که این اسکریپت اجرا میشود) به TARGET_DIR
+ echo "Copying configuration files to $TARGET_DIR..."
+ cp "$COMPOSE_FILE" "$TARGET_DIR/docker-compose.yml"
+ sed -i 's/- REDIS_PORT: 6379/- REDIS_PORT=6379/g' "$TARGET_DIR/docker-compose.yml" 2>/dev/null || true
+
+ # 6. پچ کردن nginx.conf (اگر وجود دارد)
+ echo "Patching nginx.conf for environment..."
+ cp nginx.conf "$TARGET_DIR/nginx.conf"
+ sed -i "s/__BACKEND_HOST__/${BACKEND_HOST}/g" "$TARGET_DIR/nginx.conf"
+ sed -i "s/__APP_HOST__/${APP_HOST}/g" "$TARGET_DIR/nginx.conf"
+ sed -i "s/__ADMIN_HOST__/${ADMIN_HOST}/g" "$TARGET_DIR/nginx.conf"
+
+ # 7. رفتن به پوشهی مقصد و اجرای داکر
+ cd "$TARGET_DIR"
+
+ echo "Building Docker images..."
+ docker compose build \
+ --build-arg NEXT_PUBLIC_API_URL="${API_URL}/api" \
+ --build-arg VITE_API_URL="${API_URL}"
+
+ echo "Starting containers..."
+ docker compose up -d
+
+ echo "Waiting for backend to start..."
+ sleep 15
+
+ echo "Running migrations and seeding database..."
+ docker exec "$CONTAINER_PREFIX" npx prisma migrate deploy || true
+ docker exec "$CONTAINER_PREFIX" npx prisma db seed || true
+
+ echo "Deployment for $BRANCH completed successfully!"
\ No newline at end of file