mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
The call to IMDSv1 has been failing since we switched to v2 which meant the UI e2e script attempted to use the service IP address for its tests. The service IP address is the Nomad client's private address which is not routable from the e2e test runner which means the test fails. This change updates the IP discovery to use IMDSv2 which means the address is correctly populated and routable. The change also makes this discovery method by a job action within the proxy job. This exercises that feature and utilizes it in a way for which it was designed.
117 lines
2.8 KiB
Bash
Executable File
117 lines
2.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Copyright (c) HashiCorp, Inc.
|
|
# SPDX-License-Identifier: BUSL-1.1
|
|
|
|
set -eu
|
|
|
|
help() {
|
|
cat <<EOF
|
|
Usage: run.sh [subcommand] [options] [--help]
|
|
|
|
Runs playwright tests in a Docker container against your shell's configured
|
|
Nomad target.
|
|
|
|
Subcommands:
|
|
test Run the tests (default behavior if no subcommand is provided). Options:
|
|
--no-install Don't run npm install because you've already done so.
|
|
|
|
shell Run a bash shell with the environment already set up. Maybe useful
|
|
for debugging.
|
|
|
|
proxy Deploy a reverse proxy. When the cluster is using mTLS, you will need
|
|
this so that we don't need to load a CA certificate into the browser.
|
|
This reverse proxy uses a self-signed cert. Will print a new NOMAD_ADDR
|
|
address for you to use for test runs.
|
|
|
|
ci For use in CI: runs the proxy, then tests, then stops the proxy.
|
|
|
|
Environment Variables:
|
|
NOMAD_ADDR Address of Nomad cluster or reverse proxy.
|
|
NOMAD_TOKEN Authentication token.
|
|
|
|
EOF
|
|
}
|
|
|
|
|
|
IMAGE="mcr.microsoft.com/playwright:v1.55.0-jammy"
|
|
pushd $(dirname "${BASH_SOURCE[0]}") > /dev/null
|
|
|
|
run_tests() {
|
|
run bash script.sh $@
|
|
}
|
|
|
|
run_shell() {
|
|
run bash $@
|
|
}
|
|
|
|
run() {
|
|
local tty_args=''
|
|
[ -t 1 ] && tty_args='-it'
|
|
docker run $tty_args --rm \
|
|
-v $(pwd):/src \
|
|
-w /src \
|
|
-e NOMAD_ADDR=$NOMAD_ADDR \
|
|
-e NOMAD_TOKEN=$NOMAD_TOKEN \
|
|
--ipc=host \
|
|
--net=host \
|
|
"$IMAGE" \
|
|
$@
|
|
}
|
|
|
|
run_proxy() {
|
|
# sending these outputs to stderr so that 'export NOMAD_ADDR=' is the
|
|
# only stdout line, for users to eval, or this script to write then source.
|
|
nomad namespace apply proxy 1>&2
|
|
nomad job run ./input/proxy.nomad 1>&2
|
|
set +e
|
|
IP="$(_get_aws_ip)"
|
|
[ -n "$IP" ] || {
|
|
>&2 echo 'falling back to service IP'
|
|
IP="$(_get_svc_ip)"
|
|
}
|
|
set -e
|
|
[ -n "$IP" ] || {
|
|
>&2 echo 'unable to get an IP for nomad proxy...'
|
|
exit 1 # bad form to exit from a function, but this is essential (and eval'd)
|
|
}
|
|
echo "export NOMAD_ADDR=https://$IP:6464"
|
|
}
|
|
|
|
_get_aws_ip(){
|
|
nomad action -namespace=proxy -job=nomad-proxy -group=proxy -task=nginx get_proxy_public_address
|
|
}
|
|
|
|
_get_svc_ip() {
|
|
nomad service info -namespace=proxy \
|
|
-t '{{ range . }}{{ .Address }}{{ end }}' \
|
|
nomad-proxy
|
|
}
|
|
|
|
stop_proxy() {
|
|
# make sure addr isn't still pointed at the proxy
|
|
export NOMAD_ADDR="${NOMAD_ADDR/6464/4646}"
|
|
nomad job stop -purge -namespace=proxy nomad-proxy
|
|
nomad namespace delete proxy
|
|
}
|
|
|
|
run_ci() {
|
|
set -x
|
|
run_proxy > /tmp/proxy_addr.env
|
|
source /tmp/proxy_addr.env
|
|
run_tests
|
|
rc=$?
|
|
stop_proxy
|
|
exit $rc
|
|
}
|
|
|
|
opt="$1"
|
|
case $opt in
|
|
help|--help|-h) help ;;
|
|
proxy|--proxy) run_proxy ;;
|
|
test|--test) shift ; run_tests "$@" ;;
|
|
stop|--stop) stop_proxy ;;
|
|
ci|--ci) run_ci ;;
|
|
shell) shift ; run_shell "$@" ;;
|
|
*) run_tests "$@" ;;
|
|
esac
|