name: CI/CD Pipeline on: push: branches: - main jobs: quality-and-security: runs-on: ubuntu-latest container: image: node:20-alpine steps: - name: Checkout Code run: | apk add --no-cache git git clone http://gitea-http-ci.gitea.svc.cluster.local:3000/${{ gitea.repository }}.git . git checkout ${{ gitea.sha }} - name: Install dependencies (API) run: cd api && npm install - name: Code Quality (API Syntax Check) run: cd api && node -c server.js - name: Security Test (npm audit) run: cd api && npm audit --audit-level=low || true build-and-push: needs: quality-and-security runs-on: ubuntu-latest container: image: docker:24-cli options: -v /var/run/docker.sock:/var/run/docker.sock steps: - name: Install git run: apk add --no-cache git - name: Checkout Code run: | git clone http://gitea-http-ci.gitea.svc.cluster.local:3000/${{ gitea.repository }}.git . git checkout ${{ gitea.sha }} - name: Build API Docker Image run: docker build -t git.88.96.58.76.nip.io/khalil/tamagotchi-api:${{ gitea.sha }} ./api - name: Build Frontend Docker Image run: docker build -t git.88.96.58.76.nip.io/khalil/tamagotchi-frontend:${{ gitea.sha }} ./frontend - name: Login to Gitea Registry run: echo "${{ secrets.GITEA_TOKEN }}" | docker login git.88.96.58.76.nip.io -u ${{ gitea.repository_owner }} --password-stdin - name: Push API Image run: docker push git.88.96.58.76.nip.io/khalil/tamagotchi-api:${{ gitea.sha }} - name: Push Frontend Image run: docker push git.88.96.58.76.nip.io/khalil/tamagotchi-frontend:${{ gitea.sha }} deploy: needs: build-and-push runs-on: ubuntu-latest container: image: alpine/git:latest steps: - name: Clone GitOps Repo run: | git clone http://gitea-http-ci.gitea.svc.cluster.local:3000/khalil/tamagotchi-gitops.git . git config user.name "Gitea Actions" git config user.email "actions@gitea.local" - name: Update ArgoCD Manifest run: | sed -i "s|image: .*tamagotchi-api:.*|image: git.88.96.58.76.nip.io/khalil/tamagotchi-api:${{ gitea.sha }}|g" k8s.yaml sed -i "s|image: .*tamagotchi-frontend:.*|image: git.88.96.58.76.nip.io/khalil/tamagotchi-frontend:${{ gitea.sha }}|g" k8s.yaml - name: Push Updated Manifest run: | git add k8s.yaml git diff --cached --quiet && echo "No changes to commit" || (git commit -m "chore: Update image tags to ${{ gitea.sha }} [skip ci]" && git push)