github.com/ulule/limiter/v3@v3.11.3-0.20230613131926-4cb9c1da4633/scripts/go-wrapper (about)

     1  #!/bin/bash
     2  
     3  set -eo pipefail
     4  
     5  SOURCE_DIRECTORY=$(dirname "${BASH_SOURCE[0]}")
     6  cd "${SOURCE_DIRECTORY}/.."
     7  
     8  ROOT_DIRECTORY=`pwd`
     9  IMAGE_NAME="limiter-go"
    10  DOCKERFILE="scripts/conf/go/Dockerfile"
    11  CONTAINER_IMAGE="golang:1-bullseye"
    12  
    13  if [[ -n "$REDIS_DISABLE_BOOTSTRAP" ]]; then
    14      REDIS_DISABLE_BOOTSTRAP_OPTS="-e REDIS_DISABLE_BOOTSTRAP=$REDIS_DISABLE_BOOTSTRAP"
    15  fi
    16  
    17  if [[ -n "$REDIS_URI" ]]; then
    18      REDIS_URI_OPTS="-e REDIS_URI=$REDIS_URI"
    19  fi
    20  
    21  create_docker_image() {
    22      declare tag="$1" dockerfile="$2" path="$3"
    23  
    24      echo "[go-wrapper] update golang image"
    25      docker pull ${CONTAINER_IMAGE} || true
    26  
    27      echo "[go-wrapper] build docker image"
    28      docker build -f "${dockerfile}" -t "${tag}" "${path}"
    29  }
    30  
    31  do_command() {
    32      declare command="$@"
    33  
    34      echo "[go-wrapper] run '${command}' in docker container"
    35      docker run --rm --net=host ${REDIS_DISABLE_BOOTSTRAP_OPTS} ${REDIS_URI_OPTS} \
    36          "${IMAGE_NAME}" ${command}
    37  }
    38  
    39  do_usage() {
    40  
    41      echo >&2 "Usage: $0 command"
    42      exit 255
    43  
    44  }
    45  
    46  if [ -z "$1" ]; then
    47      do_usage
    48  fi
    49  
    50  create_docker_image "${IMAGE_NAME}" "${DOCKERFILE}" "${ROOT_DIRECTORY}"
    51  do_command "$@"
    52  
    53  exit 0