name: Docker image

on:
  push:
    branches:
      - "master"
    paths-ignore:
      - ".gitignore"
      - "*.md"

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master

      - uses: actions/setup-node@v2
        with:
          node-version: '14'

      - run: |
          cd web
          npm install
          npm run build

      - name: Log into registry
        run: echo "${{ secrets.CR_PAT }}" | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin

      - name: Build and push image
        run: |
          docker build -t ghcr.io/${{ github.repository_owner }}/next-terminal -f Dockerfile .
          docker push ghcr.io/${{ github.repository_owner }}/next-terminal
      
      - name: Push to Docker Hub
        uses: docker/build-push-action@v1
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
          repository: ${{ github.repository_owner }}/next-terminal
          tag_with_ref: true
