#!/bin/bash

echo -e "\E[1;34mCleanup docker build cache to reduce disk usage\E[1;0m"
docker image prune -f
docker container prune -f
docker buildx prune --filter type=regular -f -a
docker buildx prune --filter type=source.local -f -a

function pushImage {
  K8NAMESPACE="flights-ui"
  aspnetcore=${ASPNETCORE_ENVIRONMENT,,}

  echo -e "\E[1;34mPushing $1\E[1;0m"
  docker image tag aeroflot.$K8NAMESPACE/$1:v$VERSION.$BUILD_NUMBER $REGISTRY_SERVER/aeroflot.$K8NAMESPACE.$ENVIRONMENT/$1:v$VERSION.$BUILD_NUMBER
  docker push $REGISTRY_SERVER/aeroflot.$K8NAMESPACE.$ENVIRONMENT/$1:v$VERSION.$BUILD_NUMBER
  docker rmi $REGISTRY_SERVER/aeroflot.$K8NAMESPACE.$ENVIRONMENT/$1:v$VERSION.$BUILD_NUMBER
}

echo -e "\E[1;34mStarting pushImage stage\E[1;0m"

pushImage flights-ui
