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