#!/usr/bin/env bash # # Execute command within a docker container # # Usage: ci_build.sh [-e ENV_VAR] [-it] # # DOCKER_IMG_NAME: Docker image name # COMMAND: Command to be executed in the docker container # SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # Validate command line arguments. if [ "$#" -lt 1 ] then echo "Usage: $(basename $0) DOCKER_IMG_NAME COMMAND" exit 1 fi DOCKER_IMG_NAME="$1" shift 1 while [[ "$1" == "-e" ]]; do ENV_VAR="$2" CI_DOCKER_EXTRA_PARAMS+=('-e' "${ENV_VAR}") shift 2 done if [[ "$1" == "-it" ]]; then CI_DOCKER_EXTRA_PARAMS+=('-it') shift 1 fi COMMAND=("$@") DOCKER_BINARY="docker" DOCKER_CONTEXT_PATH="${SCRIPT_DIR}" WORKSPACE="${WORKSPACE:-${SCRIPT_DIR}/../../}" # Bash on Ubuntu on Windows UBUNTU_ON_WINDOWS=$([ -e /proc/version ] && grep -l Microsoft /proc/version || echo "") # MSYS, Git Bash, etc. MSYS=$([ -e /proc/version ] && grep -l MINGW /proc/version || echo "") if [[ -z "$UBUNTU_ON_WINDOWS" ]] && [[ -z "$MSYS" ]]; then USER_IDS="-e CI_BUILD_UID=$( id -u ) -e CI_BUILD_GID=$( id -g ) -e CI_BUILD_USER=$( id -un ) -e CI_BUILD_GROUP=$( id -gn ) -e CI_BUILD_HOME=${WORKSPACE}" fi # Print arguments. cat <