name: build and deploy docs

on:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]  

jobs:

  build:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
      - name: Docker login
        run: docker login 192.168.1.200:3000 -p ${{secrets.docker_password}} -u ${{secrets.docker_username}}
      - name: Build the Docker image
        run: docker build . --tag 192.168.1.200/klein-project/KleinDocs:latest
      - name: Docker push
        run: docker push 192.168.1.200/klein-project/KleinDocs:latest


  publish:
  
   needs: build
  
   runs-on: ubuntu-latest
  
   steps:
     - name: Docker stop
       run: docker stop KleinDocs  || true
     - name: Docker login
       run: docker login 192.168.1.200:3000 -p ${{secrets.docker_password}}
     - name: Docker pull
       run: docker pull 192.168.1.200/klein-project/KleinDocs:latest
     - name: Docker run
       run: docker run --rm -dit -p 9092:80 --name KleinDocs 192.168.1.200/klein-project/KleinDocs:latest
