83 lines
3.1 KiB
YAML
83 lines
3.1 KiB
YAML
name: Build and Deploy
|
|
run-name: ${{ gitea.actor }} Build and Deploy 🚀
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout Code
|
|
uses: actions/checkout@v3
|
|
|
|
# -----------------------------------------------------------------
|
|
# CI PART
|
|
# -----------------------------------------------------------------
|
|
- name: Setup Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Docker Login (Gitea Registry)
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ vars.GITEA_REGISTRY_URL }}
|
|
username: ${{ secrets.GITEA_REGISTRY_USERNAME }}
|
|
password: ${{ secrets.GITEA_REGISTRY_PASSWORD }}
|
|
|
|
# BACKEND BUILD & PUSH
|
|
- name: Build and Push Backend
|
|
id: docker_build_backend
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: ./backend
|
|
push: true
|
|
tags: ${{ vars.GITEA_REGISTRY_URL }}/${{ github.repository }}/backend:latest
|
|
platforms: linux/amd64,linux/arm64
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
# FRONTEND BUILD & PUSH
|
|
- name: Build and Push Frontend
|
|
id: docker_build_frontend
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: ./frontend
|
|
push: true
|
|
tags: ${{ vars.GITEA_REGISTRY_URL }}/${{ github.repository }}/frontend:latest
|
|
platforms: linux/amd64,linux/arm64
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
# -----------------------------------------------------------------
|
|
# CD PART
|
|
# -----------------------------------------------------------------
|
|
- name: Install Kubectl Binary
|
|
run: |
|
|
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl"
|
|
chmod +x kubectl
|
|
sudo mv kubectl /usr/local/bin/
|
|
|
|
- name: Deploy to Kubernetes and Update
|
|
run: |
|
|
# 1. Write Kubeconfig content to file
|
|
echo "${{ secrets.KUBE_CONFIG }}" > /tmp/kubeconfig.yaml
|
|
|
|
# 2. Get the new image Digests
|
|
BACKEND_DIGEST="${{ vars.GITEA_REGISTRY_URL }}/${{ github.repository }}/backend@${{ steps.docker_build_backend.outputs.digest }}"
|
|
FRONTEND_DIGEST="${{ vars.GITEA_REGISTRY_URL }}/${{ github.repository }}/frontend@${{ steps.docker_build_frontend.outputs.digest }}"
|
|
|
|
# 3. Update Deployment
|
|
kubectl set image deployment/evrak-backend backend=${BACKEND_DIGEST} \
|
|
--kubeconfig=/tmp/kubeconfig.yaml -n default
|
|
|
|
kubectl set image deployment/evrak-frontend frontend=${FRONTEND_DIGEST} \
|
|
--kubeconfig=/tmp/kubeconfig.yaml -n default
|
|
|
|
# 4. Rollout Restart to ensure fresh pods
|
|
kubectl rollout restart deployment/evrak-backend \
|
|
--kubeconfig=/tmp/kubeconfig.yaml -n default
|
|
|
|
kubectl rollout restart deployment/evrak-frontend \
|
|
--kubeconfig=/tmp/kubeconfig.yaml -n default
|