import dedent from 'dedent' ; import { TemplateContext } from '../template_context' ; function generator ( { imageTag , imageFlavor , dockerPush , dockerTagQualifier , version , dockerTargetFilename , baseOSImage , architecture , } ) { const dockerTargetName = `${ imageTag }${ imageFlavor }:${ version }${ dockerTagQualifier ? '-' + dockerTagQualifier : '' }` ; return dedent ( `
  #!/usr/bin/env bash
  #
  # ** THIS IS AN AUTO-GENERATED FILE **
  #
  set -euo pipefail

  retry_docker_pull() {
    image=$1
    attempt=0
    max_retries=5

    while true
    do
      attempt=$((attempt+1))

      if [ $attempt -gt $max_retries ]
      then
        echo "Docker pull retries exceeded, aborting."
        exit 1
      fi

      if docker pull "$image"
      then
        echo "Docker pull successful."
        break
      else
        echo "Docker pull unsuccessful, attempt '$attempt'."
      fi

    done
  }

  retry_docker_pull ${ baseOSImage }

  echo "Building: kibana${ imageFlavor }-docker"; \\
  docker build -t ${ dockerTargetName } -f Dockerfile . || exit 1;

  docker save ${ dockerTargetName } | gzip -c > ${ dockerTargetFilename }

  ${ dockerPush } && docker image push ${ dockerTargetName }
  exit 0
  ` ) ; } export const buildDockerSHTemplate = { name : 'build_docker.sh' , generator , } ;