name: ocelot.social publish branded CI

on:
  push:
    branches:
      - master
jobs:
  build_branded:
    name: Docker Build Branded
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Build branded images
        run: |
          deployment/scripts/branded-images.build.sh
          docker save "ocelotsocialnetwork/backend-branded" > /tmp/backend-branded.tar
          docker save "ocelotsocialnetwork/webapp-branded" > /tmp/webapp-branded.tar
          docker save "ocelotsocialnetwork/maintenance-branded" > /tmp/maintenance-branded.tar

      - name: Upload Artifact (Backend)
        uses: actions/upload-artifact@v2
        with:
          name: docker-backend-branded
          path: /tmp/backend-branded.tar

      - name: Upload Artifact (Webapp)
        uses: actions/upload-artifact@v2
        with:
          name: docker-webapp-branded
          path: /tmp/webapp-branded.tar

      - name: Upload Artifact (Maintenance)
        uses: actions/upload-artifact@v2
        with:
          name: docker-maintenance-branded
          path: /tmp/maintenance-branded.tar

  upload_to_dockerhub:
    name: Upload to Dockerhub
    runs-on: ubuntu-latest
    needs: [build_branded]
    env:
      DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
      DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Download Docker Image (Backend)
        uses: actions/download-artifact@v2
        with:
          name: docker-backend-branded
          path: /tmp
      - name: Load Docker Image
        run: docker load < /tmp/backend-branded.tar

      - name: Download Docker Image (Webapp)
        uses: actions/download-artifact@v2
        with:
          name: docker-webapp-branded
          path: /tmp
      - name: Load Docker Image
        run: docker load < /tmp/webapp-branded.tar

      - name: Download Docker Image (Maintenance)
        uses: actions/download-artifact@v2
        with:
          name: docker-maintenance-branded
          path: /tmp
      - name: Load Docker Image
        run: docker load < /tmp/maintenance-branded.tar

      - name: Upload to dockerhub
        run: deployment/scripts/branded-images.upload.sh
#      - name: login to dockerhub
#        run: echo "${DOCKERHUB_TOKEN}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin
#
#      - name: Push Backend
#        run: docker push --all-tags ocelotsocialnetwork/backend-branded
#      - name: Push Webapp
#        run: docker push --all-tags ocelotsocialnetwork/webapp-branded
#      - name: Push Maintenance
#        run: docker push --all-tags ocelotsocialnetwork/maintenance-branded