Skip to content

Commit

Permalink
ci,build: add generic mechanism for passing some Travis-CI envs
Browse files Browse the repository at this point in the history
This mechanism has been roughly adapted from the way it's done for the
Linux build.
A file is used on the mount-point that is passed to the docker, and the
'inside_docker.sh' script will load it if found.

Also added 3 common/variables. Two of them are used in the Linux build.

Signed-off-by: Alexandru Ardelean <[email protected]>
  • Loading branch information
commodo committed Apr 1, 2020
1 parent e2873d9 commit 5a64b64
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CI/travis/inside_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ else
exit 1
fi

if [ -f "/$LIBNAME/inside-travis-ci-docker-env" ] ; then
. /$LIBNAME/inside-travis-ci-docker-env
fi

$CI/travis/before_install_linux "$OS_TYPE"

$CI/travis/make_linux "$OS_TYPE"
Expand Down
24 changes: 24 additions & 0 deletions CI/travis/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ LOCAL_BUILD_DIR=${LOCAL_BUILD_DIR:-build}
HOMEBREW_NO_INSTALL_CLEANUP=1
export HOMEBREW_NO_INSTALL_CLEANUP

# Add here all the common env-vars that should be propagated
# to the docker image, simply by referencing the env-var name.
# The values will be evaluated.
#
# Make sure to not pass certain stuff that are specific to the host
# and not specific to inside-the-docker (like TRAVIS_BUILD_DIR)
#
# If these nothing should be passed, then clear or
#'unset INSIDE_DOCKER_TRAVIS_CI_ENV' after this script is included
INSIDE_DOCKER_TRAVIS_CI_ENV="TRAVIS TRAVIS_COMMIT TRAVIS_PULL_REQUEST"

COMMON_SCRIPTS="inside_docker.sh"

echo_red() { printf "\033[1;31m$*\033[m\n"; }
Expand Down Expand Up @@ -266,11 +277,24 @@ prepare_docker_image() {
sudo docker pull "$DOCKER_IMAGE"
}

__save_env_for_docker() {
local env_file="$1/inside-travis-ci-docker-env"
for env in $INSIDE_DOCKER_TRAVIS_CI_ENV ; do
val="$(eval echo "\$${env}")"
if [ -n "$val" ] ; then
echo "export ${env}=${val}" >> "${env_file}"
fi
done
}

run_docker_script() {
local DOCKER_SCRIPT="$(get_script_path $1)"
local DOCKER_IMAGE="$2"
local OS_TYPE="$3"
local MOUNTPOINT="${4:-docker_build_dir}"

__save_env_for_docker "${TRAVIS_BUILD_DIR}"

sudo docker run --rm=true \
-v "$(pwd):/${MOUNTPOINT}:rw" \
$DOCKER_IMAGE \
Expand Down

0 comments on commit 5a64b64

Please sign in to comment.