name: Build test containers

on:
  push:
    branches:
      - master
      - develop
      - 'feature/**'
      - hotfix/**
    paths:
      - e2e-tests/containers/**

jobs:
  build-docker-ssh:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout source
        uses: actions/checkout@v3

      - name: Build mysql-ssh-login image
        run: |
          docker build -t dbgate/mysql-ssh-login:latest e2e-tests/containers/mysql-ssh-login

      - name: Build mysql-ssh-keyfile image
        run: |
          docker build -t dbgate/mysql-ssh-keyfile:latest e2e-tests/containers/mysql-ssh-keyfile

      - name: Build dex image
        run: |
          docker build -t dbgate/dex:latest e2e-tests/containers/dex

      - name: Log in to GHCR
        uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Push mysql-ssh-login to GHCR
        run: |
          docker tag dbgate/mysql-ssh-login:latest ghcr.io/dbgate/mysql-ssh-login:latest
          docker push ghcr.io/dbgate/mysql-ssh-login:latest

      - name: Push mysql-ssh-keyfile to GHCR
        run: |
          docker tag dbgate/mysql-ssh-keyfile:latest ghcr.io/dbgate/mysql-ssh-keyfile:latest
          docker push ghcr.io/dbgate/mysql-ssh-keyfile:latest

      - name: Push dex to GHCR
        run: |
          docker tag dbgate/dex:latest ghcr.io/dbgate/dex:latest
          docker push ghcr.io/dbgate/dex:latest
