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