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 5, 2017
1 parent 82837ae commit e26b924
Show file tree
Hide file tree
Showing 3 changed files with 30 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
16 changes: 13 additions & 3 deletions tasks
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ dev_image=docker-cli-dev
linter_image=docker-cli-lint
cross_image=docker-cli-cross


function run_task {
local task=$1

Expand Down Expand Up @@ -36,7 +35,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 +56,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 e26b924

Please sign in to comment.