From 94e08f2e2db2eb9df4058025de1a8259fb34d0a9 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 6 Apr 2022 19:10:53 +0200 Subject: [PATCH] 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 --- Makefile | 11 +++++++++++ scripts/warn-outside-container | 33 +++++++++++++++++++++------------ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 991d91504a..8dd67d1e75 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,17 @@ all: binary _:=$(shell ./scripts/warn-outside-container $(MAKECMDGOALS)) +.PHONY: dev +dev: ## start a build container in interactive mode for in-container development + @if [ -n "${DISABLE_WARN_OUTSIDE_CONTAINER}" ]; then \ + echo "you are already in the dev container"; \ + else \ + $(MAKE) -f docker.Makefile dev; \ + fi + +.PHONY: shell +shell: dev ## alias for dev + .PHONY: clean clean: ## remove build artifacts rm -rf ./build/* man/man[1-9] docs/yaml diff --git a/scripts/warn-outside-container b/scripts/warn-outside-container index ecbecc0ea2..b4ba8db235 100755 --- a/scripts/warn-outside-container +++ b/scripts/warn-outside-container @@ -3,16 +3,25 @@ set -eu target="${1:-}" -if [ "$target" != "help" ] && [ -z "${DISABLE_WARN_OUTSIDE_CONTAINER:-}" ]; then - ( - echo - echo - echo "WARNING: you are not in a container." - echo "Use \"make -f docker.Makefile $target\" or set" - echo "DISABLE_WARN_OUTSIDE_CONTAINER=1 to disable this warning." - echo - echo "Press Ctrl+C now to abort." - echo - ) >&2 - sleep 10 +if [ -z "${DISABLE_WARN_OUTSIDE_CONTAINER:-}" ]; then + case $target in + clean|dev|help|shell) + # no warning needed for these targets + ;; + *) + ( + echo + echo "\033[1mWARNING\033[0m: you are not in a container." + echo + echo 'Use "\033[1mmake dev\033[0m" to start an interactive development container,' + echo "use \"\033[1mmake -f docker.Makefile $target\033[0m\" to execute this target" + echo "in a container, or set \033[1mDISABLE_WARN_OUTSIDE_CONTAINER=1\033[0m to" + echo "disable this warning." + echo + echo "Press \033[1mCtrl+C\033[0m now to abort, or wait for the script to continue.." + echo + ) >&2 + sleep 5 + ;; + esac fi