Skip to content

Commit

Permalink
Add a warning when make is run outside of a container.
Browse files Browse the repository at this point in the history
The warning can be disabled by setting the environment variable

Signed-off-by: Daniel Nephin <dnephin@docker.com>
  • Loading branch information
dnephin committed Jul 13, 2017
1 parent 2d03cfc commit b119d74
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#
all: binary

_:=$(shell ./scripts/warn-outside-container $(MAKECMDGOALS))

# remove build artifacts
.PHONY: clean
clean:
Expand Down
15 changes: 15 additions & 0 deletions scripts/warn-outside-container
Original file line number Diff line number Diff line change
@@ -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
19 changes: 16 additions & 3 deletions tasks
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

#
# Run a development task
#
set -eu -o pipefail

unique_id=${TASK_UNIQUE_ID:-$USER}
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit b119d74

Please sign in to comment.