2018-11-11 08:19:04 -08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
2018-05-28 14:07:30 -07:00
|
|
|
|
|
|
|
usage() {
|
2018-08-20 10:17:12 -07:00
|
|
|
echo "Usage: $0 [--nopull] [docker image name] [command]"
|
2018-05-28 14:07:30 -07:00
|
|
|
echo
|
|
|
|
echo Runs command in the specified docker image with
|
2018-08-20 10:17:12 -07:00
|
|
|
echo a CI-appropriate environment.
|
|
|
|
echo
|
|
|
|
echo "--nopull Skip the dockerhub image update"
|
2018-09-21 09:42:50 -07:00
|
|
|
echo "--shell Skip command and enter an interactive shell"
|
2018-05-28 14:07:30 -07:00
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
cd "$(dirname "$0")/.."
|
|
|
|
|
2018-09-21 09:42:50 -07:00
|
|
|
INTERACTIVE=false
|
|
|
|
if [[ $1 = --shell ]]; then
|
|
|
|
INTERACTIVE=true
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
2018-08-20 10:17:12 -07:00
|
|
|
NOPULL=false
|
|
|
|
if [[ $1 = --nopull ]]; then
|
|
|
|
NOPULL=true
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
2018-05-28 14:07:30 -07:00
|
|
|
IMAGE="$1"
|
|
|
|
if [[ -z "$IMAGE" ]]; then
|
|
|
|
echo Error: image not defined
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-08-20 10:17:12 -07:00
|
|
|
$NOPULL || docker pull "$IMAGE"
|
2018-05-28 14:07:30 -07:00
|
|
|
shift
|
|
|
|
|
2018-06-18 13:45:53 -07:00
|
|
|
ARGS=(
|
|
|
|
--workdir /solana
|
|
|
|
--volume "$PWD:/solana"
|
|
|
|
--rm
|
|
|
|
)
|
2018-05-28 14:07:30 -07:00
|
|
|
|
2018-07-30 16:07:58 -07:00
|
|
|
if [[ -n $CI ]]; then
|
2022-08-17 21:33:30 -07:00
|
|
|
if [[ -n $BUILDKITE ]]; then
|
2023-03-08 05:54:19 -08:00
|
|
|
# I hate buildkite-esque echo is leaking into this generic shell wrapper.
|
|
|
|
# but it's easiest to notify to users, and properly guarded under $BUILDKITE_ env
|
|
|
|
# (2 is chosen for third time's the charm).
|
|
|
|
if [[ $BUILDKITE_RETRY_COUNT -ge 2 ]]; then
|
|
|
|
# Disable sccache to create a clean-room environment to preclude any
|
|
|
|
# sccache-related bugs
|
|
|
|
echo "--- $0 ... (with sccache being DISABLED due to many (${BUILDKITE_RETRY_COUNT}) retries)"
|
|
|
|
else
|
2023-04-24 21:11:58 -07:00
|
|
|
echo "--- $0 ... (with sccache enabled with prefix: $SCCACHE_S3_KEY_PREFIX)"
|
2023-03-08 05:54:19 -08:00
|
|
|
# sccache
|
|
|
|
ARGS+=(
|
2023-04-24 20:44:43 -07:00
|
|
|
--env "RUSTC_WRAPPER=/usr/local/cargo/bin/sccache"
|
2023-03-08 05:54:19 -08:00
|
|
|
--env AWS_ACCESS_KEY_ID
|
|
|
|
--env AWS_SECRET_ACCESS_KEY
|
|
|
|
--env SCCACHE_BUCKET
|
|
|
|
--env SCCACHE_REGION
|
2023-03-09 03:29:27 -08:00
|
|
|
--env SCCACHE_S3_KEY_PREFIX
|
2023-03-08 05:54:19 -08:00
|
|
|
)
|
|
|
|
fi
|
2022-08-17 21:33:30 -07:00
|
|
|
fi
|
2018-07-30 16:07:58 -07:00
|
|
|
fi
|
2018-05-28 14:07:30 -07:00
|
|
|
|
|
|
|
# Ensure files are created with the current host uid/gid
|
2018-06-21 12:24:52 -07:00
|
|
|
if [[ -z "$SOLANA_DOCKER_RUN_NOSETUID" ]]; then
|
|
|
|
ARGS+=(--user "$(id -u):$(id -g)")
|
|
|
|
fi
|
2018-05-28 14:07:30 -07:00
|
|
|
|
2020-06-16 09:32:16 -07:00
|
|
|
if [[ -n $SOLANA_ALLOCATE_TTY ]]; then
|
|
|
|
# Colored output, progress bar and Ctrl-C:
|
|
|
|
# https://stackoverflow.com/a/41099052/10242004
|
|
|
|
ARGS+=(--interactive --tty)
|
|
|
|
fi
|
|
|
|
|
2018-05-28 14:07:30 -07:00
|
|
|
# Environment variables to propagate into the container
|
|
|
|
ARGS+=(
|
2018-07-30 15:47:06 -07:00
|
|
|
--env BUILDKITE
|
|
|
|
--env BUILDKITE_AGENT_ACCESS_TOKEN
|
|
|
|
--env BUILDKITE_JOB_ID
|
2023-04-20 23:51:17 -07:00
|
|
|
--env BUILDKITE_PARALLEL_JOB
|
|
|
|
--env BUILDKITE_PARALLEL_JOB_COUNT
|
2018-12-18 00:47:41 -08:00
|
|
|
--env CI
|
2019-06-06 12:20:47 -07:00
|
|
|
--env CI_BRANCH
|
2020-06-18 10:04:37 -07:00
|
|
|
--env CI_BASE_BRANCH
|
2020-03-12 08:36:19 -07:00
|
|
|
--env CI_TAG
|
2019-06-06 12:20:47 -07:00
|
|
|
--env CI_BUILD_ID
|
|
|
|
--env CI_COMMIT
|
|
|
|
--env CI_JOB_ID
|
|
|
|
--env CI_PULL_REQUEST
|
|
|
|
--env CI_REPO_SLUG
|
2018-05-28 14:07:30 -07:00
|
|
|
--env CRATES_IO_TOKEN
|
|
|
|
)
|
|
|
|
|
2020-01-09 10:39:33 -08:00
|
|
|
# Also propagate environment variables needed for codecov
|
|
|
|
# https://docs.codecov.io/docs/testing-with-docker#section-codecov-inside-docker
|
|
|
|
# We normalize CI to `1`; but codecov expects it to be `true` to detect Buildkite...
|
2020-02-13 06:23:10 -08:00
|
|
|
# Unfortunately, codecov.io fails sometimes:
|
|
|
|
# curl: (7) Failed to connect to codecov.io port 443: Connection timed out
|
2023-07-14 02:34:59 -07:00
|
|
|
CODECOV_ENVS=$(CI=true bash <(while ! curl -sS --retry 5 --retry-delay 2 --retry-connrefused --fail https://codecov.io/env; do sleep 10; done))
|
2020-01-09 10:39:33 -08:00
|
|
|
|
2018-09-21 09:42:50 -07:00
|
|
|
if $INTERACTIVE; then
|
|
|
|
if [[ -n $1 ]]; then
|
|
|
|
echo
|
|
|
|
echo "Note: '$*' ignored due to --shell argument"
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
set -x
|
2020-01-09 10:39:33 -08:00
|
|
|
# shellcheck disable=SC2086
|
|
|
|
exec docker run --interactive --tty "${ARGS[@]}" $CODECOV_ENVS "$IMAGE" bash
|
2018-09-21 09:42:50 -07:00
|
|
|
fi
|
|
|
|
|
2018-05-28 14:07:30 -07:00
|
|
|
set -x
|
2020-01-09 10:39:33 -08:00
|
|
|
# shellcheck disable=SC2086
|
2023-03-15 20:58:08 -07:00
|
|
|
exec docker run "${ARGS[@]}" $CODECOV_ENVS -t "$IMAGE" "$@"
|