name: Build, push and restart docker container on Test environment
run-name: ${{ gitea.actor }} is runs ci pipeline

on:
  release:
    types: [ published, edited ]
    
jobs:
  build:
    runs-on: ubuntu-latest
    container: ghcr.io/catthehacker/ubuntu:act-latest    
    steps:  
      - name: Login to Docker Hub
        uses: docker/login-action@v3
        with:
          registry: git.wohlleben.dev
          username: ${{ gitea.actor }}
          password: ${{ vars.REGISTRY_TOKEN }}       
      - name: Restart all Docker Container on Production
        uses: appleboy/ssh-action@v1.0.3
        with:
          host: ${{ vars.STRATO_VPS_HOST_ADDRESS }}
          username: ${{ vars.STRATO_VPS_USER_NAME }}
          key: ${{ vars.STRATO_VPS_ROOT_USER_SSH_KEY }}
          script: |
            docker pull git.wohlleben.dev/itob/rbl-news-webapp:latest
            docker stop rbl-news-webapp
            docker rm rbl-news-webapp        
            docker run --init -d --name rbl-news-webapp -p 8000:8080 --restart=always git.wohlleben.dev/itob/rbl-news-webapp:latest 
            docker system prune -af