Skip to content

Commit fa2dddf

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 601b8fe commit fa2dddf

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-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: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ dev_image=docker-cli-dev
66
linter_image=docker-cli-lint
77
cross_image=docker-cli-cross
88

9-
109
function run_task {
1110
local task=$1
1211

@@ -36,7 +35,11 @@ function docker_build_and_run {
3635
local dockerfile_source=
3736
local cidfile=
3837
local remove="--rm"
39-
local envvars="-e VERSION -e GITCOMMIT -e BUILDTIME -e LDFLAGS"
38+
local envvars="-e VERSION \
39+
-e GITCOMMIT \
40+
-e BUILDTIME \
41+
-e LDFLAGS \
42+
-e DISABLE_WARN_OUTSIDE_CONTAINER=1"
4043
# Use an array to preserve whitespace in $PWD
4144
local mounts=(-v "$PWD:/go/src/github.com/docker/cli")
4245
if [ -t 1 ] ; then local use_tty="-ti"; else local use_tty=""; fi
@@ -53,7 +56,14 @@ function docker_build_and_run {
5356
fi
5457

5558
echo "$dockerfile_source" | docker build -t "$image" -f "$dockerfile" .
56-
docker run $remove $envvars $cidfile $use_tty ${mounts[@]+"${mounts[@]}"} "$image" $cmd
59+
docker run \
60+
$remove \
61+
$envvars \
62+
$cidfile \
63+
$use_tty \
64+
${mounts[@]+"${mounts[@]}"} \
65+
"$image" \
66+
$cmd
5767
}
5868

5969
function usage {

0 commit comments

Comments
 (0)