let a stack compute its settings without make
A stack can now ship <name>.env and <name>.sh next to its compose files. The hook is sourced with the tag helpers available, which is what the computing .mk files of the catalogue were using make for: 29 of its 44 .mk files only exist to build variables like the fabio tags. Converting stack/host/fabio.mk by hand gives byte-identical output for the route tag, and drops a trailing comma the make version left in the listener list. Also: APP_HOST and APP_URI are computed (the tag helpers build on them), --color controls the escape codes rather than always emitting them, and make test-portability runs the CLI under busybox ash and dash.
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
#shellcheck shell=sh
|
||||
# Helper: hooks set variables in the caller's scope, which a subshell loses.
|
||||
[ -n "${4:-}" ] && eval "$3=\$4"
|
||||
myos_stack_hooks "$1" "$2"
|
||||
eval "printf '%s\n' \"\${$3:-}\""
|
||||
@@ -0,0 +1,82 @@
|
||||
#shellcheck shell=sh
|
||||
Include lib/str.sh
|
||||
Include lib/core.sh
|
||||
Include lib/tags.sh
|
||||
Include lib/naming.sh
|
||||
Include lib/config.sh
|
||||
Include lib/hooks.sh
|
||||
|
||||
# A stack ships its computed settings as a shell hook, so the catalogue works
|
||||
# on a machine without make. These check the hook and the uri it builds on.
|
||||
Describe 'lib/hooks.sh'
|
||||
setup() {
|
||||
MYOS_TMP=$(mktemp -d "${TMPDIR:-/tmp}/myos-hook.XXXXXX")
|
||||
MYOS_TMP=$(cd "$MYOS_TMP" && pwd -P)
|
||||
ENV=local; DOMAIN=example.org; USER=tester; HOSTNAME=testhost
|
||||
APP_HOST=demo.example.org; APP_URI=demo.example.org/
|
||||
}
|
||||
cleanup() { rm -rf "$MYOS_TMP"; }
|
||||
BeforeEach setup
|
||||
AfterEach cleanup
|
||||
|
||||
It 'loads plain values from a .env hook'
|
||||
printf 'DEMO_VERSION=1.2.3\n' > "$MYOS_TMP/demo.env"
|
||||
When run source spec/unit/hooks_helper.sh "$MYOS_TMP" demo DEMO_VERSION
|
||||
The output should equal "1.2.3"
|
||||
End
|
||||
|
||||
It 'loads a computed value from a .sh hook'
|
||||
printf 'DEMO_TAGS=$(myos_tagprefix demo 8000)\n' > "$MYOS_TMP/demo.sh"
|
||||
When run source spec/unit/hooks_helper.sh "$MYOS_TMP" demo DEMO_TAGS
|
||||
The output should equal "urlprefix-demo.demo.example.org/*"
|
||||
End
|
||||
|
||||
It 'lets a hook name the service it publishes'
|
||||
printf 'DEMO_SERVICE_8000_NAME=www\nDEMO_TAGS=$(myos_tagprefix demo 8000)\n' > "$MYOS_TMP/demo.sh"
|
||||
When run source spec/unit/hooks_helper.sh "$MYOS_TMP" demo DEMO_TAGS
|
||||
The output should equal "urlprefix-www.demo.example.org/*"
|
||||
End
|
||||
|
||||
It 'lets the environment win over a hook default'
|
||||
printf 'DEMO_VERSION=${DEMO_VERSION:-1.2.3}\n' > "$MYOS_TMP/demo.sh"
|
||||
When run source spec/unit/hooks_helper.sh "$MYOS_TMP" demo DEMO_VERSION 9.9.9
|
||||
The output should equal "9.9.9"
|
||||
End
|
||||
|
||||
It 'is quiet when a stack has no hook'
|
||||
When call myos_stack_hooks "$MYOS_TMP" nothing
|
||||
The status should be success
|
||||
The output should equal ""
|
||||
End
|
||||
End
|
||||
|
||||
Describe 'lib/naming.sh service uris'
|
||||
BeforeEach 'ENV=local; unset APP_HOST_MULTI_APP APP_HOST_MULTI_USER APP_HOST_MULTI_ENV HOST_LB 2>/dev/null || true'
|
||||
|
||||
It 'serves a host stack on <hostname>.<domain>'
|
||||
When call myos_app_host host aya local fabio example.org sonic
|
||||
The output should equal "sonic.example.org"
|
||||
End
|
||||
It 'adds the bare domain when the host is the load balancer'
|
||||
HOST_LB=true
|
||||
When call myos_app_host host aya local fabio example.org sonic
|
||||
The output should equal "sonic.example.org example.org"
|
||||
End
|
||||
It 'does not prefix a main environment'
|
||||
When call myos_app_host app aya master duniter example.org sonic
|
||||
The output should equal "example.org"
|
||||
End
|
||||
It 'prefixes any other environment'
|
||||
When call myos_app_host app aya staging duniter example.org sonic
|
||||
The output should equal "staging.example.org"
|
||||
End
|
||||
It 'prefixes the user when asked to'
|
||||
APP_HOST_MULTI_USER=true
|
||||
When call myos_app_host app aya master duniter example.org sonic
|
||||
The output should equal "aya.example.org"
|
||||
End
|
||||
It 'builds a uri that ends with a slash'
|
||||
When call myos_app_uri "a.example.org b.example.org"
|
||||
The output should equal "a.example.org/ b.example.org/"
|
||||
End
|
||||
End
|
||||
Reference in New Issue
Block a user