name: push-master
on:
  push:
    branches:
      - master
jobs:
  build:
    name: Docker build
    runs-on: ubuntu-latest
    env:
      DOCKER_CLI_EXPERIMENTAL: enabled
      GO111MODULE: on
      TARGET: amd64
      REPOSITORY: nfvpe/multi-networkpolicy-iptables
      REPOSITORY_USER: nfvperobot
    steps:
      - name: Check out code into the Go module directory
        uses: actions/checkout@v2

      - name: Build latest-amd64
        run: docker build -t ${REPOSITORY}:latest-amd64 .

      - name: Tag snapshot
        run: |
          docker tag ${REPOSITORY}:latest-amd64 ${REPOSITORY}:snapshot-amd64

      - name: Login to registry
        if: github.repository == 'k8snetworkplumbingwg/multi-networkpolicy-iptables'
        run: docker login -u ${REPOSITORY_USER} -p ${{ secrets.REPOSITORY_PASS }}

      - name: Push latest/snapshot images
        if: github.repository == 'k8snetworkplumbingwg/multi-networkpolicy-iptables'
        run: |
          docker push ${REPOSITORY}:latest-amd64
          docker push ${REPOSITORY}:snapshot-amd64

      - name: Create manifest for multi-arch images
        if: github.repository == 'k8snetworkplumbingwg/multi-networkpolicy-iptables'
        run: |
          docker manifest create ${REPOSITORY}:snapshot ${REPOSITORY}:snapshot-amd64
          docker manifest annotate ${REPOSITORY}:snapshot ${REPOSITORY}:snapshot-amd64 --arch amd64
          docker manifest push ${REPOSITORY}:snapshot
          docker manifest create ${REPOSITORY}:latest ${REPOSITORY}:latest-amd64
          docker manifest annotate ${REPOSITORY}:latest ${REPOSITORY}:latest-amd64 --arch amd64
          docker manifest push ${REPOSITORY}:latest

