name: build and deploy portfolio

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 gitea.kleinsense.nl -p ${{secrets.docker_password}} -u ${{secrets.docker_username}}
      - name: Build the Docker image
        run: docker build . --file Writerside/Dockerfile --tag gitea.kleinsense.nl/dariusklein/kleincord-docs
      - name: Docker push
        run: docker push gitea.kleinsense.nl/dariusklein/kleincord-docs


  publish:

    needs: build

    runs-on: ubuntu-latest

    steps:
      - name: Docker stop
        run: docker stop darius-discord-docs  || true
      - name: Docker login
        run: docker login gitea.kleinsense.nl -p ${{secrets.docker_password}} -u ${{secrets.docker_username}}
      - name: Docker pull
        run: docker pull gitea.kleinsense.nl/dariusklein/kleincord-docs
      - name: Docker run
        run: docker run --restart=always -dit -p 9090:80 --name darius-discord-docs gitea.kleinsense.nl/dariusklein/kleincord-docs
