Skip to content

Commit 94e08f2

Browse files
committed
Makefile: don't warn "outside container" for some targets
This change allows some make targets to be ran outside the dev-container for easier discovery and use: - `make clean` can be used on the host (as artifacts created from within the development container are usually stored on the host). - `make help` was already allowed - `make dev` and `make shell` are added to the regular Makefile, to make it easier to create and start the development container. - When attempting to run `make dev` from within the development container, a message is printed, and the target is cancelled: root@docker-cli-dev$ make dev you are already in the dev container Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 90b60b5 commit 94e08f2

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ all: binary
99

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

12+
.PHONY: dev
13+
dev: ## start a build container in interactive mode for in-container development
14+
@if [ -n "${DISABLE_WARN_OUTSIDE_CONTAINER}" ]; then \
15+
echo "you are already in the dev container"; \
16+
else \
17+
$(MAKE) -f docker.Makefile dev; \
18+
fi
19+
20+
.PHONY: shell
21+
shell: dev ## alias for dev
22+
1223
.PHONY: clean
1324
clean: ## remove build artifacts
1425
rm -rf ./build/* man/man[1-9] docs/yaml

scripts/warn-outside-container

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,25 @@ set -eu
33

44
target="${1:-}"
55

6-
if [ "$target" != "help" ] && [ -z "${DISABLE_WARN_OUTSIDE_CONTAINER:-}" ]; then
7-
(
8-
echo
9-
echo
10-
echo "WARNING: you are not in a container."
11-
echo "Use \"make -f docker.Makefile $target\" or set"
12-
echo "DISABLE_WARN_OUTSIDE_CONTAINER=1 to disable this warning."
13-
echo
14-
echo "Press Ctrl+C now to abort."
15-
echo
16-
) >&2
17-
sleep 10
6+
if [ -z "${DISABLE_WARN_OUTSIDE_CONTAINER:-}" ]; then
7+
case $target in
8+
clean|dev|help|shell)
9+
# no warning needed for these targets
10+
;;
11+
*)
12+
(
13+
echo
14+
echo "\033[1mWARNING\033[0m: you are not in a container."
15+
echo
16+
echo 'Use "\033[1mmake dev\033[0m" to start an interactive development container,'
17+
echo "use \"\033[1mmake -f docker.Makefile $target\033[0m\" to execute this target"
18+
echo "in a container, or set \033[1mDISABLE_WARN_OUTSIDE_CONTAINER=1\033[0m to"
19+
echo "disable this warning."
20+
echo
21+
echo "Press \033[1mCtrl+C\033[0m now to abort, or wait for the script to continue.."
22+
echo
23+
) >&2
24+
sleep 5
25+
;;
26+
esac
1827
fi

0 commit comments

Comments
 (0)