name: CI

on:
  push:
    branches:
      - develop

jobs:
  deploy:
    runs-on: ubuntu
    steps:
      - name: Install Docker and Docker Compose
        run: |
          apt-get update
          # Adding docker-compose-v2 installs the 'docker compose' plugin
          apt-get install -y docker.io docker-compose-plugin

      - name: Login to Docker Hub
        run:  echo '${{ secrets.DOCKER_PASSWORD }}' | docker login --username "${{ secrets.DOCKER_USERNAME }}" --password-stdin

      - uses: actions/checkout@v4
     
      - name: Login to Gitea Registry
        run: |
          echo "${{ secrets.THE_GITEA_TOKEN }}" | docker login gitea.gofwd.group -u "${{ secrets.THE_GITEA_USERNAME }}" --password-stdin

      - name: Pull latest images
        run: |
          docker pull gitea.gofwd.group/forward_group/ballistic-builder-spring/spring-api:latest
          docker pull gitea.gofwd.group/sean/shadow-gunbuilder-ai-proto/webui:latest

      - name: Recreate containers with new images
        run: docker compose up -d -f /opt/docker/battlbuilder/docker-compose.yaml