name: Build & Deploy

on:
  push:
    branches: [master]

env:
  REGISTRY: gitea.lan
  IMAGE: gitea.lan/shaz/le-site-de-ma-mamounette

jobs:
  build-push-deploy:
    runs-on: homelab

    steps:
      - name: Checkout
        run: |
          rm -rf workspace
          git clone http://192.168.1.18:3000/Shaz/Le-site-de-ma-mamounette.git workspace
          cd workspace && git checkout ${{ gitea.sha }}

      - name: Login au registry Gitea
        run: echo "${{ secrets.REGISTRY_TOKEN }}" | docker login gitea.lan -u shaz --password-stdin

      - name: Build & push image
        run: |
          docker build -t ${{ env.IMAGE }}:latest workspace/
          docker push ${{ env.IMAGE }}:latest

      - name: Déployer sur le serveur
        run: |
          docker compose -f /srv/ssd/stacks/moulin/docker-compose.yml pull
          docker compose -f /srv/ssd/stacks/moulin/docker-compose.yml up -d


          docker compose -f /srv/ssd/stacks/moulin/docker-compose.yml up -d --pull always
