name: "serverstatus docker build"

env:
  PROJECT: serverstatus

on:
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      ACTIONS_ALLOW_UNSECURE_COMMANDS: true
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Set tag
        id: tag
        run: |
          TAG=$(cat Dockerfile | awk 'NR==4 {print $3}')
          echo "::set-env name=TAG::$TAG"
      - name: Docker Hub login
        env:
          DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
          DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
        run: |
          echo "${DOCKER_PASSWORD}" | docker login --username ${DOCKER_USERNAME} --password-stdin
      - name: Set up Docker Buildx
        id: buildx
        uses: crazy-max/ghaction-docker-buildx@v1
        with:
          buildx-version: latest
      - name: Build Dockerfile
        env:
          DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
        run: |
          docker buildx build \
          --platform=linux/amd64,linux/arm64 \
          --output "type=image,push=true" \
          --file Dockerfile . \
          --tag $(echo "${DOCKER_USERNAME}" | tr '[:upper:]' '[:lower:]')/${{ env.PROJECT }}:latest \
          --tag $(echo "${DOCKER_USERNAME}" | tr '[:upper:]' '[:lower:]')/${{ env.PROJECT }}:${TAG}
