diff --git a/bin/myos b/bin/myos index 40ad9aa..c16a230 100755 --- a/bin/myos +++ b/bin/myos @@ -44,7 +44,6 @@ myos_is_command() { MYOS_REFS_RAW= MYOS_VARS= MYOS_ARGS= - MYOS_HOSTS= MYOS_COLOR=${MYOS_COLOR:-auto} VERBOSE=${VERBOSE:-} DEBUG=${DEBUG:-} @@ -57,7 +56,6 @@ Usage: myos [options] [stack...] [VAR=value...] [-- args...] Options: -C DIR work in DIR instead of the current directory -e ENV environment (default: local, or ENV from the config) - -H HOSTS run on remote hosts instead (comma separated, or "all") -n, --dry-run print the commands instead of running them --color WHEN always, never or auto (default: colour when on a terminal) -v, --verbose show what myos does @@ -66,7 +64,7 @@ Options: Commands: up down start stop restart recreate manage the containers of a stack - ps logs config exec run inspect and enter them + ps status logs config exec run inspect and enter them ls [--groups] list the stacks myos can see env [VAR...] show resolved variables export every setting of the stacks, as KEY=value @@ -86,7 +84,9 @@ while [ $# -gt 0 ]; do case $1 in -C) WORKDIR=$2; shift 2 ;; -e) ENV=$2; shift 2 ;; - -H) MYOS_HOSTS=$2; shift 2 ;; + # running on remote hosts is not implemented yet; the flag is refused + # rather than silently ignored + -H) myos_die "$MYOS_E_USAGE" "-H is not implemented yet: run myos on the host itself" ;; -n|--dry-run) DRYRUN=true; shift ;; --color) MYOS_COLOR=$2; shift 2 ;; --color=*) MYOS_COLOR=${1#--color=}; shift ;; diff --git a/lib/cmd/recreate.sh b/lib/cmd/recreate.sh new file mode 100644 index 0000000..0ab5617 --- /dev/null +++ b/lib/cmd/recreate.sh @@ -0,0 +1,10 @@ +#shellcheck shell=sh +# myos recreate remove the containers and create them again +# myos reload the same, under the name the make engine used +myos_cmd_recreate() { + # shellcheck source=lib/cmd/_compose.sh + . "$MYOS_ROOT/lib/cmd/_compose.sh" + MYOS_ARGS="--force-recreate ${MYOS_ARGS:-}" + myos_cmd_compose up +} +myos_cmd_reload() { myos_cmd_recreate; } diff --git a/lib/cmd/reload.sh b/lib/cmd/reload.sh new file mode 100644 index 0000000..b37bdb1 --- /dev/null +++ b/lib/cmd/reload.sh @@ -0,0 +1,4 @@ +#shellcheck shell=sh +# myos reload: see lib/cmd/recreate.sh +# shellcheck source=lib/cmd/recreate.sh +. "$MYOS_ROOT/lib/cmd/recreate.sh" diff --git a/lib/cmd/status.sh b/lib/cmd/status.sh new file mode 100644 index 0000000..bf9101a --- /dev/null +++ b/lib/cmd/status.sh @@ -0,0 +1,7 @@ +#shellcheck shell=sh +# myos status what is running, under the name the make engine used for ps +myos_cmd_status() { + # shellcheck source=lib/cmd/_compose.sh + . "$MYOS_ROOT/lib/cmd/_compose.sh" + myos_cmd_compose ps +} diff --git a/share/make/shim.mk b/share/make/shim.mk index 442b8ac..89ab7e0 100644 --- a/share/make/shim.mk +++ b/share/make/shim.mk @@ -39,13 +39,11 @@ endef # The settings of the stacks, read once and evaluated here. # A stack keeps its settings in hooks that only myos reads; asking for them one # at a time costs a process per variable, so they come in a single call. +## Written while this file is read, not as a target: a target would collide +## with the catch-all rule at the bottom, which hands anything else to myos. MYOS_SETTINGS ?= .myos.settings.mk -$(MYOS_SETTINGS): - @$(MYOS_BIN) --color=never $(MYOS_ARGS) export --make > $@ 2>/dev/null || : > $@ --include $(MYOS_SETTINGS) -## regenerated on every run, and the catch-all below must not hand this file -## to myos as if it were a command -.PHONY: $(MYOS_SETTINGS) +MYOS_SETTINGS_FILE := $(shell $(MYOS_BIN) --color=never $(MYOS_ARGS) export --make > $(MYOS_SETTINGS) 2>/dev/null && echo $(MYOS_SETTINGS)) +-include $(MYOS_SETTINGS_FILE) # function myos-var: the value myos resolves for one variable, when a single # lookup is cheaper than the whole set diff --git a/spec/golden/cases.txt b/spec/golden/cases.txt index 64c223c..833f94c 100644 --- a/spec/golden/cases.txt +++ b/spec/golden/cases.txt @@ -87,3 +87,5 @@ chain-print-two | host-project | print-COMPOSE_PROJECT_NAME pri mk-ssh-no-hosts | app-nogit | ssh mk-ssh-with-hosts | app-nogit | ssh SSH_HOSTS=example.test ARGS=id bridge-export | host-project | export STACK=host/consul +cmd-recreate | host-project | recreate host/consul +cmd-status | host-project | status host/consul diff --git a/spec/golden/expected.cli/cmd-recreate.txt b/spec/golden/expected.cli/cmd-recreate.txt new file mode 100644 index 0000000..4b583cf --- /dev/null +++ b/spec/golden/expected.cli/cmd-recreate.txt @@ -0,0 +1,4 @@ +docker network create tester-local +docker network create testhost +docker compose -f @WD@/stack/host/consul.yml -f @MYOS@/share/compose/networks.yml -p testhost --project-directory @WD@/stack/host up -d --force-recreate +[exit 0] diff --git a/spec/golden/expected.cli/cmd-status.txt b/spec/golden/expected.cli/cmd-status.txt new file mode 100644 index 0000000..8a44a14 --- /dev/null +++ b/spec/golden/expected.cli/cmd-status.txt @@ -0,0 +1,2 @@ +docker compose -f @WD@/stack/host/consul.yml -f @MYOS@/share/compose/networks.yml -p testhost --project-directory @WD@/stack/host ps +[exit 0] diff --git a/spec/golden/expected.cli/shim-config.txt b/spec/golden/expected.cli/shim-config.txt deleted file mode 100644 index 418eb93..0000000 --- a/spec/golden/expected.cli/shim-config.txt +++ /dev/null @@ -1,4 +0,0 @@ -@MYOS@/share/make/shim.mk:66: warning: overriding commands for target `.myos.settings.mk' -@MYOS@/share/make/shim.mk:44: warning: ignoring old commands for target `.myos.settings.mk' -docker compose -f @WD@/stack/host/consul.yml -f @MYOS@/share/compose/networks.yml -p testhost --project-directory @WD@/stack/host config -[exit 0] diff --git a/spec/golden/expected.cli/shim-project-target.txt b/spec/golden/expected.cli/shim-project-target.txt deleted file mode 100644 index 7e2b46e..0000000 --- a/spec/golden/expected.cli/shim-project-target.txt +++ /dev/null @@ -1,4 +0,0 @@ -@MYOS@/share/make/shim.mk:66: warning: overriding commands for target `.myos.settings.mk' -@MYOS@/share/make/shim.mk:44: warning: ignoring old commands for target `.myos.settings.mk' -would renew the certificates of host/consul host/fabio -[exit 0] diff --git a/spec/golden/expected.cli/shim-up-group.txt b/spec/golden/expected.cli/shim-up-group.txt deleted file mode 100644 index cbebc28..0000000 --- a/spec/golden/expected.cli/shim-up-group.txt +++ /dev/null @@ -1,6 +0,0 @@ -@MYOS@/share/make/shim.mk:66: warning: overriding commands for target `.myos.settings.mk' -@MYOS@/share/make/shim.mk:44: warning: ignoring old commands for target `.myos.settings.mk' -docker network create tester-local -docker network create testhost -docker compose -f @WD@/stack/host/consul.yml -f @WD@/stack/host/fabio.yml -f @MYOS@/share/compose/networks.yml -p testhost --project-directory @WD@/stack/host up -d -[exit 0] diff --git a/spec/golden/expected/cmd-recreate.txt b/spec/golden/expected/cmd-recreate.txt new file mode 100644 index 0000000..830eece --- /dev/null +++ b/spec/golden/expected/cmd-recreate.txt @@ -0,0 +1,7 @@ +make -o docker-stack-recreate MAKE_OLDFILE=docker-stack-recreate ENV=local DOCKER_COMPOSE=docker --log-level=error compose docker-compose-recreate STACK=myos APP_NAME=myos +docker --log-level=error compose --ansi=auto -f @MYOS@/share/compose/networks.yml -p tester-myos-local rm -fs +sh -c docker network create tester-local >/dev/null 2>&1 +sh -c docker network create testhost >/dev/null 2>&1 +docker --log-level=error compose --ansi=auto -f @MYOS@/share/compose/networks.yml -p tester-myos-local up -d +WARNING: myos[0] host/consul-rule-exists: target host/consul unavailable in app myos +[exit 0] diff --git a/spec/golden/expected/cmd-status.txt b/spec/golden/expected/cmd-status.txt new file mode 100644 index 0000000..28686f4 --- /dev/null +++ b/spec/golden/expected/cmd-status.txt @@ -0,0 +1,4 @@ +make -o docker-stack-ps MAKE_OLDFILE=docker-stack-ps ENV=local DOCKER_COMPOSE=docker --log-level=error compose docker-compose-ps STACK=myos APP_NAME=myos +docker --log-level=error compose --ansi=auto -f @MYOS@/share/compose/networks.yml -p tester-myos-local ps +WARNING: myos[0] host/consul-rule-exists: target host/consul unavailable in app myos +[exit 0]