80 lines
2.2 KiB
YAML
80 lines
2.2 KiB
YAML
name: CI/CD Pipeline
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
quality-and-security:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout Code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '20'
|
|
|
|
- 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
|
|
steps:
|
|
- name: Checkout Code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
with:
|
|
driver-opts: network=host
|
|
|
|
- name: Login to Gitea Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: git.88.96.58.76.nip.io
|
|
username: ${{ github.repository_owner }}
|
|
password: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
- name: Build and push API
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: ./api
|
|
push: true
|
|
tags: git.88.96.58.76.nip.io/khalil/tamagotchi-api:${{ github.sha }}
|
|
|
|
- name: Build and push Frontend
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: ./frontend
|
|
push: true
|
|
tags: git.88.96.58.76.nip.io/khalil/tamagotchi-frontend:${{ github.sha }}
|
|
|
|
deploy:
|
|
needs: build-and-push
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout Code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
token: ${{ secrets.GITEA_TOKEN }}
|
|
|
|
- name: Update ArgoCD k8s.yaml Manifest
|
|
run: |
|
|
sed -i "s|image: tamagotchi-api:.*|image: git.88.96.58.76.nip.io/khalil/tamagotchi-api:${{ github.sha }}|g" k8s.yaml
|
|
sed -i "s|image: tamagotchi-frontend:.*|image: git.88.96.58.76.nip.io/khalil/tamagotchi-frontend:${{ github.sha }}|g" k8s.yaml
|
|
|
|
git config user.name "Gitea Actions"
|
|
git config user.email "actions@gitea.local"
|
|
git add k8s.yaml
|
|
git commit -m "chore: Update image tags to ${{ github.sha }} [skip ci]"
|
|
git push
|