69 lines
2.2 KiB
YAML
69 lines
2.2 KiB
YAML
name: Build and Deploy
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Login to Gitea Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ secrets.REGISTRY_URL }}
|
|
username: ${{ secrets.REGISTRY_USER }}
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
|
|
- name: Build and push postgres image
|
|
uses: docker/build-push-action@v5
|
|
if: |
|
|
contains(github.event.commits[0].modified, 'infra/docker/postgres-pg-cron') ||
|
|
contains(github.event.commits[0].added, 'infra/docker/postgres-pg-cron')
|
|
with:
|
|
context: .
|
|
file: infra/docker/postgres-pg-cron/Dockerfile
|
|
push: true
|
|
tags: |
|
|
${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/familyhub-postgres:latest
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
- name: Build and push app image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: infra/application/Dockerfile
|
|
push: true
|
|
tags: |
|
|
${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/familyhub:latest
|
|
${{ secrets.REGISTRY_URL }}/${{ secrets.REGISTRY_USER }}/familyhub:${{ github.sha }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
- 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
|
|
sudo mv kubectl /usr/local/bin/
|
|
|
|
- name: Deploy to k3s
|
|
env:
|
|
KUBECONFIG_DATA: ${{ secrets.KUBECONFIG }}
|
|
run: |
|
|
mkdir -p ~/.kube
|
|
echo "$KUBECONFIG_DATA" > ~/.kube/config
|
|
chmod 600 ~/.kube/config
|
|
kubectl rollout restart deployment/application -n family-hub
|
|
kubectl rollout restart deployment/postgres -n family-hub
|
|
kubectl rollout status deployment/application -n family-hub --timeout=120s
|
|
kubectl rollout status deployment/postgres -n family-hub --timeout=120s
|