87 lines
2.8 KiB
YAML
87 lines
2.8 KiB
YAML
name: Build & Deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
env:
|
|
REGISTRY: git.arthurbarre.fr
|
|
IMAGE_SERVER: ordinarthur/anydrop-server
|
|
IMAGE_WEB: ordinarthur/anydrop-web
|
|
NAMESPACE: anydrop
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Login to Gitea Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ordinarthur
|
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
|
|
|
- name: Build and push server
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: server/Dockerfile
|
|
push: true
|
|
tags: |
|
|
${{ env.REGISTRY }}/${{ env.IMAGE_SERVER }}:latest
|
|
${{ env.REGISTRY }}/${{ env.IMAGE_SERVER }}:${{ github.sha }}
|
|
|
|
- name: Build and push web
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: web/Dockerfile
|
|
push: true
|
|
tags: |
|
|
${{ env.REGISTRY }}/${{ env.IMAGE_WEB }}:latest
|
|
${{ env.REGISTRY }}/${{ env.IMAGE_WEB }}:${{ github.sha }}
|
|
build-args: |
|
|
VITE_WS_URL=wss://anydrop.arthurbarre.fr/ws
|
|
|
|
- name: Install kubectl
|
|
run: |
|
|
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
|
|
chmod +x kubectl
|
|
mv kubectl /usr/local/bin/
|
|
|
|
- name: Deploy to K3s
|
|
run: |
|
|
mkdir -p ~/.kube
|
|
echo "${{ secrets.KUBECONFIG }}" | base64 -d > ~/.kube/config
|
|
chmod 600 ~/.kube/config
|
|
|
|
# Create namespace if needed
|
|
kubectl apply -f k8s/namespace.yml
|
|
|
|
# Create registry secret if needed
|
|
kubectl -n $NAMESPACE create secret docker-registry gitea-registry \
|
|
--docker-server=$REGISTRY \
|
|
--docker-username=ordinarthur \
|
|
--docker-password=${{ secrets.REGISTRY_PASSWORD }} \
|
|
--dry-run=client -o yaml | kubectl apply -f -
|
|
|
|
# Apply manifests (data layer first, app last)
|
|
kubectl apply -f k8s/postgres.yml
|
|
kubectl apply -f k8s/maddy.yml
|
|
kubectl -n $NAMESPACE rollout status statefulset/postgres --timeout=180s
|
|
kubectl apply -f k8s/server.yml
|
|
kubectl apply -f k8s/web.yml
|
|
|
|
# Force rollout with new images
|
|
kubectl -n $NAMESPACE set image deployment/anydrop-server \
|
|
anydrop-server=$REGISTRY/$IMAGE_SERVER:${{ github.sha }}
|
|
kubectl -n $NAMESPACE set image deployment/anydrop-web \
|
|
anydrop-web=$REGISTRY/$IMAGE_WEB:${{ github.sha }}
|
|
|
|
# Wait for rollout
|
|
kubectl -n $NAMESPACE rollout status deployment/anydrop-server --timeout=120s
|
|
kubectl -n $NAMESPACE rollout status deployment/anydrop-web --timeout=120s
|