name: docker-aio

on:
  push:
    branches: 
      - 'master'
    tags:
      - '*'
  pull_request:
  workflow_dispatch:

jobs:
  docker:
    name: docker-aio
    runs-on: ubuntu-latest
    if: ${{ github.repository_owner == 'SoftEtherVPN' }}
    steps:
      -
        name: Docker meta vpnserver
        id: metavpnserver
        uses: docker/metadata-action@v5
        with:
          images: ${{ github.repository_owner }}/vpnserver
          tags: |
            type=raw,value=latest,enable={{is_default_branch}}
            type=ref,event=pr
            type=semver,pattern={{version}}
            type=semver,pattern={{major}}.{{minor}}
      - 
        name: Docker meta vpnclient
        id: metavpnclient
        uses: docker/metadata-action@v5
        with:
          images: ${{ github.repository_owner }}/vpnclient
          tags: |
            type=raw,value=latest,enable={{is_default_branch}}
            type=ref,event=pr
            type=semver,pattern={{version}}
            type=semver,pattern={{major}}.{{minor}}
      - 
        name: Docker meta vpnbridge
        id: metavpnbridge
        uses: docker/metadata-action@v5
        with:
          images: ${{ github.repository_owner }}/vpnbridge
          tags: |
            type=raw,value=latest,enable={{is_default_branch}}
            type=ref,event=pr
            type=semver,pattern={{version}}
            type=semver,pattern={{major}}.{{minor}}
      -
        name: Set up QEMU
        uses: docker/setup-qemu-action@v3
        with:
          image: tonistiigi/binfmt:qemu-v9.2.0
#
# TODO: unpin qemu version after default is updated
#
      -
        name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
      -
        name: Login to DockerHub
        if: ${{ github.event_name != 'pull_request' }}
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      -
        name: Build and push vpnserver
        uses: docker/build-push-action@v6
        with:
          file: ./Dockerfile
          target: vpnserver
          push: ${{ github.event_name != 'pull_request' }}
          platforms: linux/amd64,linux/arm64
          tags: ${{ steps.metavpnserver.outputs.tags }}
          labels: ${{ steps.metavpnserver.outputs.labels }}
      -
        name: Build and push vpnclient
        uses: docker/build-push-action@v6
        with:
          file: ./Dockerfile
          target: vpnclient
          push: ${{ github.event_name != 'pull_request' }}
          platforms: linux/amd64,linux/arm64
          tags: ${{ steps.metavpnclient.outputs.tags }}
          labels: ${{ steps.metavpnclient.outputs.labels }}
      -
        name: Build and push vpnbridge
        uses: docker/build-push-action@v6
        with:
          file: ./Dockerfile
          target: vpnbridge
          push: ${{ github.event_name != 'pull_request' }}
          platforms: linux/amd64,linux/arm64
          tags: ${{ steps.metavpnbridge.outputs.tags }}
          labels: ${{ steps.metavpnbridge.outputs.labels }}