Alexis Bruneteau c03360713f fix
2025-05-31 03:11:55 +02:00

70 lines
2.2 KiB
YAML

name: Build and Deploy to k3s
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '22'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build Angular app
run: npm run build --prod
- name: Build Docker image
run: |
docker build -t ${{ secrets.REGISTRY_URL }}/angular-app:${{ github.sha }} .
docker tag ${{ secrets.REGISTRY_URL }}/angular-app:${{ github.sha }} ${{ secrets.REGISTRY_URL }}/angular-app:latest
- name: Login to Container Registry
run: echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login ${{ secrets.REGISTRY_URL }} -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
- name: Push Docker image
run: |
docker push ${{ secrets.REGISTRY_URL }}/angular-app:${{ github.sha }}
docker push ${{ secrets.REGISTRY_URL }}/angular-app:latest
- name: Setup kubectl
uses: azure/setup-kubectl@v3
with:
version: 'latest'
- name: Configure kubectl
run: |
mkdir -p ~/.kube
echo "${{ secrets.KUBECONFIG }}" | base64 -d > ~/.kube/config
chmod 600 ~/.kube/config
- name: Create ConfigMap for app files
run: |
kubectl create configmap angular-app-files \
--from-file=dist/your-angular-app/ \
--namespace=angular-app \
--dry-run=client -o yaml | kubectl apply -f -
- name: Create ConfigMap for nginx config
run: |
kubectl create configmap nginx-config \
--from-file=nginx.conf \
--namespace=angular-app \
--dry-run=client -o yaml | kubectl apply -f -
- name: Deploy to k3s
run: |
kubectl apply -f k8s/
kubectl set image deployment/angular-app angular-app=${{ secrets.REGISTRY_URL }}/angular-app:${{ github.sha }} -n angular-app
kubectl rollout status deployment/angular-app -n angular-app