ci: add tests job before deploy, fix namespace to academia
- Add test job that runs Domain, Application, and Integration tests - Deploy job now depends on test job (needs: test) - Fix namespace from student-enrollment to academia - Update sync path from student-enrollment to academia - Always apply kustomize before rollout restart
This commit is contained in:
parent
1455f729b2
commit
d8a01f904d
|
|
@ -1,4 +1,4 @@
|
||||||
name: Deploy to k3s
|
name: Test and Deploy to k3s
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
|
|
@ -8,12 +8,39 @@ on:
|
||||||
env:
|
env:
|
||||||
K3S_HOST: "100.67.198.92"
|
K3S_HOST: "100.67.198.92"
|
||||||
K3S_USER: "andres"
|
K3S_USER: "andres"
|
||||||
NAMESPACE: "student-enrollment"
|
NAMESPACE: "academia"
|
||||||
DOMAIN: "academia.ingeniumcodex.com"
|
DOMAIN: "academia.ingeniumcodex.com"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup .NET
|
||||||
|
uses: actions/setup-dotnet@v4
|
||||||
|
with:
|
||||||
|
dotnet-version: "10.0.x"
|
||||||
|
|
||||||
|
- name: Restore dependencies
|
||||||
|
run: dotnet restore
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: dotnet build --no-restore
|
||||||
|
|
||||||
|
- name: Run Unit Tests
|
||||||
|
run: dotnet test tests/Domain.Tests --no-build --verbosity normal
|
||||||
|
|
||||||
|
- name: Run Application Tests
|
||||||
|
run: dotnet test tests/Application.Tests --no-build --verbosity normal
|
||||||
|
|
||||||
|
- name: Run Integration Tests
|
||||||
|
run: dotnet test tests/Integration.Tests --no-build --verbosity normal
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
needs: test
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
@ -34,14 +61,12 @@ jobs:
|
||||||
--exclude 'bin' \
|
--exclude 'bin' \
|
||||||
--exclude 'obj' \
|
--exclude 'obj' \
|
||||||
--exclude '.angular' \
|
--exclude '.angular' \
|
||||||
--exclude 'tests' \
|
./ ${{ env.K3S_USER }}@${{ env.K3S_HOST }}:~/academia/
|
||||||
--exclude 'docs' \
|
|
||||||
./ ${{ env.K3S_USER }}@${{ env.K3S_HOST }}:~/student-enrollment/
|
|
||||||
|
|
||||||
- name: Build images (parallel)
|
- name: Build images (parallel)
|
||||||
run: |
|
run: |
|
||||||
ssh ${{ env.K3S_USER }}@${{ env.K3S_HOST }} << 'ENDSSH'
|
ssh ${{ env.K3S_USER }}@${{ env.K3S_HOST }} << 'ENDSSH'
|
||||||
cd ~/student-enrollment
|
cd ~/academia
|
||||||
export DOCKER_BUILDKIT=1
|
export DOCKER_BUILDKIT=1
|
||||||
|
|
||||||
echo "${{ secrets.K3S_SUDO_PASS }}" | sudo -S docker build \
|
echo "${{ secrets.K3S_SUDO_PASS }}" | sudo -S docker build \
|
||||||
|
|
@ -68,8 +93,8 @@ jobs:
|
||||||
- name: Setup namespace if needed
|
- name: Setup namespace if needed
|
||||||
run: |
|
run: |
|
||||||
ssh ${{ env.K3S_USER }}@${{ env.K3S_HOST }} << 'ENDSSH'
|
ssh ${{ env.K3S_USER }}@${{ env.K3S_HOST }} << 'ENDSSH'
|
||||||
cd ~/student-enrollment/deploy/k3s
|
cd ~/academia/deploy/k3s
|
||||||
if ! echo "${{ secrets.K3S_SUDO_PASS }}" | sudo -S kubectl get ns student-enrollment &>/dev/null; then
|
if ! echo "${{ secrets.K3S_SUDO_PASS }}" | sudo -S kubectl get ns academia &>/dev/null; then
|
||||||
echo "Creating namespace and resources..."
|
echo "Creating namespace and resources..."
|
||||||
echo "${{ secrets.K3S_SUDO_PASS }}" | sudo -S kubectl apply -k .
|
echo "${{ secrets.K3S_SUDO_PASS }}" | sudo -S kubectl apply -k .
|
||||||
fi
|
fi
|
||||||
|
|
@ -78,22 +103,24 @@ jobs:
|
||||||
- name: Deploy
|
- name: Deploy
|
||||||
run: |
|
run: |
|
||||||
ssh ${{ env.K3S_USER }}@${{ env.K3S_HOST }} << 'ENDSSH'
|
ssh ${{ env.K3S_USER }}@${{ env.K3S_HOST }} << 'ENDSSH'
|
||||||
|
cd ~/academia/deploy/k3s
|
||||||
|
echo "${{ secrets.K3S_SUDO_PASS }}" | sudo -S kubectl apply -k .
|
||||||
echo "${{ secrets.K3S_SUDO_PASS }}" | sudo -S kubectl rollout restart \
|
echo "${{ secrets.K3S_SUDO_PASS }}" | sudo -S kubectl rollout restart \
|
||||||
deployment/student-api deployment/student-frontend -n student-enrollment
|
deployment/student-api deployment/student-frontend -n academia
|
||||||
ENDSSH
|
ENDSSH
|
||||||
|
|
||||||
- name: Wait rollout
|
- name: Wait rollout
|
||||||
run: |
|
run: |
|
||||||
ssh ${{ env.K3S_USER }}@${{ env.K3S_HOST }} << 'ENDSSH'
|
ssh ${{ env.K3S_USER }}@${{ env.K3S_HOST }} << 'ENDSSH'
|
||||||
echo "${{ secrets.K3S_SUDO_PASS }}" | sudo -S kubectl rollout status \
|
echo "${{ secrets.K3S_SUDO_PASS }}" | sudo -S kubectl rollout status \
|
||||||
deployment/student-api -n student-enrollment --timeout=120s
|
deployment/student-api -n academia --timeout=120s
|
||||||
echo "${{ secrets.K3S_SUDO_PASS }}" | sudo -S kubectl rollout status \
|
echo "${{ secrets.K3S_SUDO_PASS }}" | sudo -S kubectl rollout status \
|
||||||
deployment/student-frontend -n student-enrollment --timeout=60s
|
deployment/student-frontend -n academia --timeout=60s
|
||||||
ENDSSH
|
ENDSSH
|
||||||
|
|
||||||
- name: Health check
|
- name: Health check
|
||||||
run: |
|
run: |
|
||||||
sleep 5
|
sleep 10
|
||||||
curl -sf https://${{ env.DOMAIN }}/health || exit 1
|
curl -sf https://${{ env.DOMAIN }}/health || exit 1
|
||||||
curl -sf https://${{ env.DOMAIN }}/ || exit 1
|
curl -sf https://${{ env.DOMAIN }}/ || exit 1
|
||||||
|
|
||||||
|
|
@ -102,5 +129,5 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
ssh ${{ env.K3S_USER }}@${{ env.K3S_HOST }} << 'ENDSSH'
|
ssh ${{ env.K3S_USER }}@${{ env.K3S_HOST }} << 'ENDSSH'
|
||||||
echo "${{ secrets.K3S_SUDO_PASS }}" | sudo -S kubectl rollout undo \
|
echo "${{ secrets.K3S_SUDO_PASS }}" | sudo -S kubectl rollout undo \
|
||||||
deployment/student-api deployment/student-frontend -n student-enrollment 2>/dev/null || true
|
deployment/student-api deployment/student-frontend -n academia 2>/dev/null || true
|
||||||
ENDSSH
|
ENDSSH
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue