Skip to content

Commit bbe553d

Browse files
committed
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 <dnephin@docker.com>
1 parent 2d03cfc commit bbe553d

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#
44
all: binary
55

6+
_:=$(shell ./scripts/warn-outside-container $(MAKECMDGOALS))
7+
68
# remove build artifacts
79
.PHONY: clean
810
clean:

scripts/warn-outside-container

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
set -eu
3+
4+
target="${1:-}"
5+
6+
if [[ -z "${DISABLE_WARN_OUTSIDE_CONTAINER:-}" ]]; then
7+
(
8+
echo
9+
echo
10+
echo "WARNING: you are not in a container. Use \"./tasks $target\" or set"
11+
echo "DISABLE_WARN_OUTSIDE_CONTAINER=1 to disable this warning."
12+
echo
13+
echo
14+
) >&2
15+
fi

tasks

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env bash
2-
2+
#
3+
# Run a development task
4+
#
35
set -eu -o pipefail
46

57
unique_id=${TASK_UNIQUE_ID:-$USER}
@@ -36,7 +38,11 @@ function docker_build_and_run {
3638
local dockerfile_source=
3739
local cidfile=
3840
local remove="--rm"
39-
local envvars="-e VERSION -e GITCOMMIT -e BUILDTIME -e LDFLAGS"
41+
local envvars="-e VERSION \
42+
-e GITCOMMIT \
43+
-e BUILDTIME \
44+
-e LDFLAGS \
45+
-e DISABLE_WARN_OUTSIDE_CONTAINER=1"
4046
# Use an array to preserve whitespace in $PWD
4147
local mounts=(-v "$PWD:/go/src/github.com/docker/cli")
4248
if [ -t 1 ] ; then local use_tty="-ti"; else local use_tty=""; fi
@@ -53,7 +59,14 @@ function docker_build_and_run {
5359
fi
5460

5561
echo "$dockerfile_source" | docker build -t "$image" -f "$dockerfile" .
56-
docker run $remove $envvars $cidfile $use_tty ${mounts[@]+"${mounts[@]}"} "$image" $cmd
62+
docker run \
63+
$remove \
64+
$envvars \
65+
$cidfile \
66+
$use_tty \
67+
${mounts[@]+"${mounts[@]}"} \
68+
"$image" \
69+
$cmd
5770
}
5871

5972
function usage {

0 commit comments

Comments
 (0)