name: Build & Deploy Nuxt (Docker)

on:
  push:
    branches: ["main"]

jobs:
  deploy:
    runs-on: main
    container:
      image: docker:27-cli
    steps:
      - name: Install tools (git + node)
        run: apk add --no-cache git nodejs npm

      - name: Checkout
        uses: actions/checkout@v4

      - name: Define image tag
        run: |
          echo "IMAGE=local/nautilusDesk:${{ gitea.sha }}" >> $GITEA_ENV

      - name: Build image
        run: |
          docker build -t "$IMAGE" .

      - name: Deploy via compose
        run: |
          cd deploy
          IMAGE="$IMAGE" docker compose up -d --remove-orphans

      - name: Cleanup dangling images (optional)
        run: |
          docker image prune -f || true
