From b119d74dcb2a7d038a6b43330a198fff6f70cba5 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Fri, 23 Jun 2017 00:52:34 -0400 Subject: [PATCH] Add a warning when make is run outside of a container. The warning can be disabled by setting the environment variable Signed-off-by: Daniel Nephin --- Makefile | 2 ++ scripts/warn-outside-container | 15 +++++++++++++++ tasks | 19 ++++++++++++++++--- 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100755 scripts/warn-outside-container diff --git a/Makefile b/Makefile index dbb3d3bfefc8..4c836cb8dd30 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,8 @@ # all: binary +_:=$(shell ./scripts/warn-outside-container $(MAKECMDGOALS)) + # remove build artifacts .PHONY: clean clean: diff --git a/scripts/warn-outside-container b/scripts/warn-outside-container new file mode 100755 index 000000000000..6592e5a4a277 --- /dev/null +++ b/scripts/warn-outside-container @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -eu + +target="${1:-}" + +if [[ -z "${DISABLE_WARN_OUTSIDE_CONTAINER:-}" ]]; then + ( + echo + echo + echo "WARNING: you are not in a container. Use \"./tasks $target\" or set" + echo "DISABLE_WARN_OUTSIDE_CONTAINER=1 to disable this warning." + echo + echo + ) >&2 +fi diff --git a/tasks b/tasks index c74900851157..a38a7802dd85 100755 --- a/tasks +++ b/tasks @@ -1,5 +1,7 @@ #!/usr/bin/env bash - +# +# Run a development task +# set -eu -o pipefail unique_id=${TASK_UNIQUE_ID:-$USER} @@ -36,7 +38,11 @@ function docker_build_and_run { local dockerfile_source= local cidfile= local remove="--rm" - local envvars="-e VERSION -e GITCOMMIT -e BUILDTIME -e LDFLAGS" + local envvars="-e VERSION \ + -e GITCOMMIT \ + -e BUILDTIME \ + -e LDFLAGS \ + -e DISABLE_WARN_OUTSIDE_CONTAINER=1" # Use an array to preserve whitespace in $PWD local mounts=(-v "$PWD:/go/src/github.com/docker/cli") if [ -t 1 ] ; then local use_tty="-ti"; else local use_tty=""; fi @@ -53,7 +59,14 @@ function docker_build_and_run { fi echo "$dockerfile_source" | docker build -t "$image" -f "$dockerfile" . - docker run $remove $envvars $cidfile $use_tty ${mounts[@]+"${mounts[@]}"} "$image" $cmd + docker run \ + $remove \ + $envvars \ + $cidfile \ + $use_tty \ + ${mounts[@]+"${mounts[@]}"} \ + "$image" \ + $cmd } function usage {