name: Deployment CI/CD

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Stop and remove existing container (if exists)
        run: |
          docker stop stat || true
          docker rm stat || true

      - name: Build Docker image
        run: |
          docker build -t stat .
      
      - name: Deploy to production
        run: |
          docker run -d -p 8080:8080 --name stat stat
