#!/bin/bash
#
# Copyright 2015-2020 The OpenZipkin Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
#


set -v

if [[ "$DOCKER_REPO" == "index.docker.io/openzipkin/zipkin" ]]; then
  echo Pushing zipkin-slim and test images
  IFS=',' read -ra TAGS <<< "$DOCKER_TAG"
  for tag in ${TAGS[@]}; do
    docker push "openzipkin/zipkin-slim:$tag"
    docker push "openzipkin/zipkin-ui:$tag"

    for collector in kafka; do
      docker push "openzipkin/zipkin-${collector}:$tag"
    done

    for storage in cassandra elasticsearch6 elasticsearch7 mysql; do
      docker push "openzipkin/zipkin-${storage}:$tag"
    done
  done

  if [[ "$DOCKER_TAG" == "master" ]]; then
    # We repush the builder image on master push, not on release pushes.
    echo Building zipkin-builder
    docker build -f "$DOCKERFILE_PATH" -t openzipkin/zipkin-builder --target zipkin-builder .

    echo Pushing zipkin-builder
    # zipkin-builder is just a cache of maven / npm dependencies, there's no need to version it
    # with docker tags.
    docker push openzipkin/zipkin-builder
  fi
fi
