port the make list functions and JWT, and expose the framework variables to hooks

lib/str.sh gains firstword, lastword, or, patsubst, filter, filter_out,
addprefix, addsuffix and jwt: what the catalogue .mk files are written in.
The make JWT macro split on the commas of its payload; this one does not.

lib/context.sh registers COMPOSE_PROJECT_NAME, APP, DOCKER_NETWORK_* and the
rest as lazy defaults, so a converted .mk keeps reading them as it did.

Hooks also load a directory-level _stack.env and _stack.sh, for the .mk files
of the catalogue that hold settings for several stacks at once.
This commit is contained in:
Yann Autissier
2026-09-03 21:58:22 +02:00
parent 3e55cdcd14
commit 6192d73cbe
8 changed files with 199 additions and 36 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
make -o docker-stack-build MAKE_OLDFILE=docker-stack-build ENV=local DOCKER_COMPOSE=docker --log-level=error compose docker-compose-build STACK=myos APP_NAME=myos
docker --log-level=error compose --ansi=auto -f @MYOS@/share/compose/networks.yml -p tester-myos-local build --build-arg APP=myos --build-arg BRANCH=lightning --build-arg COMPOSE_VERSION=2.24.4 --build-arg DOCKER_MACHINE=x86_64 --build-arg DOCKER_REPOSITORY=tester/myos/local --build-arg DOCKER_SYSTEM=Linux --build-arg GIT_AUTHOR_EMAIL=tester@example.test --build-arg GIT_AUTHOR_NAME=tester --build-arg SSH_REMOTE_HOSTS=github.com gitlab.com --build-arg USER=tester --build-arg VERSION=legacy-1.0-beta-17-g55fae62 --build-arg SSH_AUTHORIZED_KEYS=https://github.com/tester.keys --build-arg SSH_BASTION_USERNAME=tester --build-arg SSH_PORT=22 --build-arg SSH_PUBLIC_HOSTS= github.com gitlab.com --build-arg SSH_USER=tester --build-arg GID=20 --build-arg UID=502
docker --log-level=error compose --ansi=auto -f @MYOS@/share/compose/networks.yml -p tester-myos-local build --build-arg APP=myos --build-arg BRANCH=@BRANCH@ --build-arg COMPOSE_VERSION=2.24.4 --build-arg DOCKER_MACHINE=x86_64 --build-arg DOCKER_REPOSITORY=tester/myos/local --build-arg DOCKER_SYSTEM=Linux --build-arg GIT_AUTHOR_EMAIL=tester@example.test --build-arg GIT_AUTHOR_NAME=tester --build-arg SSH_REMOTE_HOSTS=github.com gitlab.com --build-arg USER=tester --build-arg VERSION=@VERSION@ --build-arg SSH_AUTHORIZED_KEYS=https://github.com/tester.keys --build-arg SSH_BASTION_USERNAME=tester --build-arg SSH_PORT=22 --build-arg SSH_PUBLIC_HOSTS= github.com gitlab.com --build-arg SSH_USER=tester --build-arg GID=20 --build-arg UID=502
make -o docker-stack-up MAKE_OLDFILE=docker-stack-up ENV=local DOCKER_COMPOSE=docker --log-level=error compose docker-compose-up STACK=myos APP_NAME=myos
sh -c docker network create tester-local >/dev/null 2>&1
sh -c docker network create testhost >/dev/null 2>&1
+2
View File
@@ -39,6 +39,8 @@ myos_normalize() {
-e 's/^APPS .*/APPS @APPS@/' \
-e 's/^BRANCH .*/BRANCH @BRANCH@/' \
-e 's/^VERSION .*/VERSION @VERSION@/' \
-e 's/--build-arg VERSION=[^ ]*/--build-arg VERSION=@VERSION@/' \
-e 's/--build-arg BRANCH=[^ ]*/--build-arg BRANCH=@BRANCH@/' \
-e 's/[[:space:]][[:space:]]*/ /g' \
-e 's/[[:space:]]*$//'
}
+52
View File
@@ -68,3 +68,55 @@ Describe 'lib/str.sh'
End
End
End
# The make list functions the catalogue relies on, ported so that a stack hook
# reads like the .mk it replaces.
Describe 'lib/str.sh list functions'
It 'takes the first and last word'
When call myos_firstword "a b c"
The output should equal "a"
End
It 'takes the last word'
When call myos_lastword "a b c"
The output should equal "c"
End
It 'returns the first argument that is not empty'
When call myos_or "" "" "third"
The output should equal "third"
End
Describe 'myos_patsubst'
Parameters
"%" "pre%" "a b" "prea preb"
"%.yml" "%.yaml" "a.yml b.md" "a.yaml b.md"
"%" "%/" "x y" "x/ y/"
End
It "substitutes $1 -> $2 in $3"
When call myos_patsubst "$1" "$2" "$3"
The output should equal "$4"
End
End
It 'filters a list'
When call myos_filter "a%" "abc bcd axe"
The output should equal "abc axe"
End
It 'filters a list out'
When call myos_filter_out "local master main" "staging"
The output should equal "staging"
End
It 'drops the words it is told to'
When call myos_filter_out "local master main" "master"
The output should equal ""
End
It 'adds a prefix and a suffix'
When call myos_addprefix "x." "a b"
The output should equal "x.a x.b"
End
End
Describe 'lib/str.sh myos_jwt'
It 'signs a token whose payload decodes back'
When call myos_jwt "" '{"role":"anon"}' secret
The output should start with "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9."
The output should include "eyJyb2xlIjoiYW5vbiJ9"
End
End