From eb679300f35ae69f9494a003e8f2610ec3dabad9 Mon Sep 17 00:00:00 2001 From: furkanyigit34 Date: Mon, 18 May 2026 11:42:02 +0300 Subject: [PATCH] =?UTF-8?q?ci(k8s):=20Gitea=20K8s=20pipeline=20ekle=20?= =?UTF-8?q?=E2=80=94=20CiroMarket=20K8s=20migration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ne yaptık: - .gitea/workflows/deploy-backend.yaml — Gitea Actions ile backend image'ı build et, Gitea registry'e push et, ci-cd repo manifest'ini bump'la - .gitea/workflows/deploy-frontend.yaml — Frontend'i VITE_API_URL=https://trendyol-api.194.187.253.61.sslip.io ile build et, aynı pattern - .github/workflows/deploy.yml — sync-gitea job eklendi: GitHub push sonrası Gitea mirror sync + deploy-backend/frontend.yaml dispatch Neden yaptık: - CiroMarket'i Coolify'dan K8s'e taşıma projesi - Coolify pipeline parallel çalışmaya devam ediyor (zero downtime) - GitHub push → Gitea mirror → Gitea Actions → Gitea registry → ArgoCD → K8s rolling update zinciri tamamlandı --- .gitea/workflows/deploy-backend.yaml | 77 ++++++++++++++++++++++++++ .gitea/workflows/deploy-frontend.yaml | 78 +++++++++++++++++++++++++++ .github/workflows/deploy.yml | 50 +++++++++++++++++ 3 files changed, 205 insertions(+) create mode 100644 .gitea/workflows/deploy-backend.yaml create mode 100644 .gitea/workflows/deploy-frontend.yaml diff --git a/.gitea/workflows/deploy-backend.yaml b/.gitea/workflows/deploy-backend.yaml new file mode 100644 index 0000000..1afe037 --- /dev/null +++ b/.gitea/workflows/deploy-backend.yaml @@ -0,0 +1,77 @@ +name: ciromarket-backend-build-and-deploy + +on: + push: + branches: [main] + paths: + - 'backend/**' + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + env: + REGISTRY: git.novasis.tr + IMAGE: admin/trendyol-analiz/backend + DOCKER_HOST: tcp://172.17.0.1:2375 + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Compute tag + id: tag + run: echo "sha=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT" + + - name: Pre-build disk check + run: | + df -h /var/lib/docker || df -h / + docker system df || true + + - name: Login to Gitea registry + run: echo "${{ secrets.REGISTRY_TOKEN }}" | docker login "$REGISTRY" -u admin --password-stdin + + - name: Build & push image + run: | + docker build \ + --file backend/Dockerfile \ + --tag "$REGISTRY/$IMAGE:${{ steps.tag.outputs.sha }}" \ + --tag "$REGISTRY/$IMAGE:latest" \ + . + docker push "$REGISTRY/$IMAGE:${{ steps.tag.outputs.sha }}" + docker push "$REGISTRY/$IMAGE:latest" + + - name: Bump deployment manifest in ci-cd repo + run: | + set -euo pipefail + git clone https://gitea_admin:${{ secrets.CI_CD_TOKEN }}@git.novasis.tr/gitea_admin/ci-cd.git /tmp/ci-cd + cd /tmp/ci-cd + git config user.email "ci@novasis.tr" + git config user.name "gitea-actions-bot" + MANIFEST="apps/ciromarket/backend/deploy/deployment.yaml" + MAX=5 + for i in $(seq 1 $MAX); do + git fetch origin main + git reset --hard origin/main + sed -i -E "s|image: ${REGISTRY}/${IMAGE}:.*|image: ${REGISTRY}/${IMAGE}:${{ steps.tag.outputs.sha }}|" "$MANIFEST" + if git diff --quiet "$MANIFEST"; then + echo "No image change to commit." + exit 0 + fi + git add "$MANIFEST" + git commit -m "ci: bump ciromarket/backend to ${{ steps.tag.outputs.sha }} [skip ci]" + if git push origin main; then + echo "Pushed on attempt $i" + exit 0 + fi + sleep 3 + done + exit 1 + + - name: Post-build cleanup + if: always() + run: | + docker buildx prune --force --keep-storage 3GB 2>&1 | tail -3 || true + docker image prune -f 2>&1 | tail -2 || true diff --git a/.gitea/workflows/deploy-frontend.yaml b/.gitea/workflows/deploy-frontend.yaml new file mode 100644 index 0000000..47dc9bf --- /dev/null +++ b/.gitea/workflows/deploy-frontend.yaml @@ -0,0 +1,78 @@ +name: ciromarket-frontend-build-and-deploy + +on: + push: + branches: [main] + paths: + - 'admin-panel/**' + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + env: + REGISTRY: git.novasis.tr + IMAGE: admin/trendyol-analiz/frontend + DOCKER_HOST: tcp://172.17.0.1:2375 + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Compute tag + id: tag + run: echo "sha=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT" + + - name: Pre-build disk check + run: | + df -h /var/lib/docker || df -h / + docker system df || true + + - name: Login to Gitea registry + run: echo "${{ secrets.REGISTRY_TOKEN }}" | docker login "$REGISTRY" -u admin --password-stdin + + - name: Build & push image + run: | + docker build \ + --file admin-panel/Dockerfile \ + --build-arg VITE_API_URL=https://trendyol-api.194.187.253.61.sslip.io \ + --tag "$REGISTRY/$IMAGE:${{ steps.tag.outputs.sha }}" \ + --tag "$REGISTRY/$IMAGE:latest" \ + ./admin-panel + docker push "$REGISTRY/$IMAGE:${{ steps.tag.outputs.sha }}" + docker push "$REGISTRY/$IMAGE:latest" + + - name: Bump deployment manifest in ci-cd repo + run: | + set -euo pipefail + git clone https://gitea_admin:${{ secrets.CI_CD_TOKEN }}@git.novasis.tr/gitea_admin/ci-cd.git /tmp/ci-cd + cd /tmp/ci-cd + git config user.email "ci@novasis.tr" + git config user.name "gitea-actions-bot" + MANIFEST="apps/ciromarket/frontend/deploy/deployment.yaml" + MAX=5 + for i in $(seq 1 $MAX); do + git fetch origin main + git reset --hard origin/main + sed -i -E "s|image: ${REGISTRY}/${IMAGE}:.*|image: ${REGISTRY}/${IMAGE}:${{ steps.tag.outputs.sha }}|" "$MANIFEST" + if git diff --quiet "$MANIFEST"; then + echo "No image change to commit." + exit 0 + fi + git add "$MANIFEST" + git commit -m "ci: bump ciromarket/frontend to ${{ steps.tag.outputs.sha }} [skip ci]" + if git push origin main; then + echo "Pushed on attempt $i" + exit 0 + fi + sleep 3 + done + exit 1 + + - name: Post-build cleanup + if: always() + run: | + docker buildx prune --force --keep-storage 3GB 2>&1 | tail -3 || true + docker image prune -f 2>&1 | tail -2 || true diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9f98c6a..453c953 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -4,6 +4,9 @@ name: Deploy # Zincir: validate → build-push (backend+frontend) → deploy → verify # Trendyol-analiz tertemiz auto-deploy — SellerX deploy-frontend.yml pattern'i # ───────────────────────────────────────────────────────────────────────────── +# K8s pipeline (Gitea mirror → Gitea Actions → Gitea registry → ArgoCD) parallel +# çalışır — Coolify pipeline'ı DURDURMAZ. +# ───────────────────────────────────────────────────────────────────────────── on: push: @@ -18,6 +21,53 @@ env: NODE_VERSION: '20' jobs: + # ─────────────────────────────────────────────────────────────────────────── + # K8s MIRROR SYNC — Coolify pipeline'dan BAĞIMSIZ, validate ile PARALEL. + # GitHub push → Gitea mirror sync → Gitea Actions → Gitea registry → ArgoCD + # Başarısız olursa Coolify pipeline DURMUYOR. + # ─────────────────────────────────────────────────────────────────────────── + sync-gitea: + name: Sync Gitea Mirror (K8s Pipeline) + runs-on: ubuntu-latest + steps: + - name: Trigger Gitea mirror sync + run: | + HTTP=$(curl -s -o /dev/null -w "%{http_code}" \ + -X POST "https://git.novasis.tr/api/v1/repos/admin/trendyol-analiz/mirror-sync" \ + -H "Authorization: token ${{ secrets.GITEA_MIRROR_TOKEN }}") + echo "Mirror sync HTTP: $HTTP" + if [ "$HTTP" -ge 400 ]; then + echo "Mirror sync failed (HTTP $HTTP) — K8s pipeline delayed, Coolify unaffected" + exit 0 + fi + echo "Mirror sync triggered — waiting 30s for sync to complete..." + sleep 30 + + - name: Dispatch Gitea Actions build (deploy-backend.yaml) + run: | + HTTP=$(curl -s -o /dev/null -w "%{http_code}" \ + -X POST "https://git.novasis.tr/api/v1/repos/admin/trendyol-analiz/actions/workflows/deploy-backend.yaml/dispatches" \ + -H "Authorization: token ${{ secrets.GITEA_MIRROR_TOKEN }}" \ + -H "Content-Type: application/json" \ + -d '{"ref":"main"}') + echo "Gitea backend dispatch HTTP: $HTTP" + if [ "$HTTP" -ge 400 ]; then + echo "Gitea backend dispatch failed — trigger manually" + fi + + - name: Dispatch Gitea Actions build (deploy-frontend.yaml) + run: | + HTTP=$(curl -s -o /dev/null -w "%{http_code}" \ + -X POST "https://git.novasis.tr/api/v1/repos/admin/trendyol-analiz/actions/workflows/deploy-frontend.yaml/dispatches" \ + -H "Authorization: token ${{ secrets.GITEA_MIRROR_TOKEN }}" \ + -H "Content-Type: application/json" \ + -d '{"ref":"main"}') + echo "Gitea frontend dispatch HTTP: $HTTP" + if [ "$HTTP" -ge 400 ]; then + echo "Gitea frontend dispatch failed — trigger manually" + fi + + # ─────────────────────────────────────────────────────────────────────────── # ADIM 1a — Backend hızlı sağlık testi (pytest) # ───────────────────────────────────────────────────────────────────────────