From 26edb2a77e404afe7d00970844d75e3863f96991 Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Sat, 4 Nov 2023 09:58:19 -0400 Subject: [PATCH 1/7] test(smoketest): correct exposed vs mapped ports --- smoketest/compose/db-viewer.yml | 2 ++ smoketest/compose/jfr-datasource.yml | 2 -- smoketest/compose/s3-localstack.yml | 6 +++--- smoketest/compose/s3-minio.yml | 4 +++- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/smoketest/compose/db-viewer.yml b/smoketest/compose/db-viewer.yml index 4a60a5556..822cb82c1 100644 --- a/smoketest/compose/db-viewer.yml +++ b/smoketest/compose/db-viewer.yml @@ -8,6 +8,8 @@ services: hostname: db-viewer ports: - "8989:8989" + expose: + - "8989" environment: PGADMIN_DEFAULT_EMAIL: admin@cryostat.io PGADMIN_DEFAULT_PASSWORD: admin diff --git a/smoketest/compose/jfr-datasource.yml b/smoketest/compose/jfr-datasource.yml index 54f17541e..2645eb892 100644 --- a/smoketest/compose/jfr-datasource.yml +++ b/smoketest/compose/jfr-datasource.yml @@ -12,8 +12,6 @@ services: limits: cpus: '0.4' memory: 512m - ports: - - "8080:8080" expose: - "8080" labels: diff --git a/smoketest/compose/s3-localstack.yml b/smoketest/compose/s3-localstack.yml index 4969772b8..6b1564f23 100644 --- a/smoketest/compose/s3-localstack.yml +++ b/smoketest/compose/s3-localstack.yml @@ -14,9 +14,9 @@ services: s3: image: docker.io/localstack/localstack:1.4.0 hostname: s3 - ports: - - "4566:4566" - - "4577:4577" + expose: + - "4566" + - "4577" environment: SERVICES: s3 START_WEB: 1 diff --git a/smoketest/compose/s3-minio.yml b/smoketest/compose/s3-minio.yml index 822a6f41e..47ff66b77 100644 --- a/smoketest/compose/s3-minio.yml +++ b/smoketest/compose/s3-minio.yml @@ -16,7 +16,9 @@ services: hostname: s3 ports: - "9001:9001" - - "9000:9000" + expose: + - "9000" + - "9001" command: server /data --console-address ":9001" environment: MINIO_ROOT_USER: minioroot From b31133d667b455a7e5620d02517a3989966a6b79 Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Sat, 4 Nov 2023 09:58:39 -0400 Subject: [PATCH 2/7] test(smoketest): open services in browser tabs when ready --- smoketest.bash | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/smoketest.bash b/smoketest.bash index ab0245d90..a59859e3d 100755 --- a/smoketest.bash +++ b/smoketest.bash @@ -8,6 +8,9 @@ fi FILES=( ./smoketest/compose/db.yml ) +URLS=( + "http://localhost:8181" +) PULL_IMAGES=${PULL_IMAGES:-true} KEEP_VOLUMES=${KEEP_VOLUMES:-false} @@ -32,6 +35,7 @@ while getopts "s:gtOVXc" opt; do ;; g) FILES+=('./smoketest/compose/cryostat-grafana.yml' './smoketest/compose/jfr-datasource.yml') + URLS+=("http://grafana:3000") ;; t) FILES+=('./smoketest/compose/sample-apps.yml') @@ -44,6 +48,7 @@ while getopts "s:gtOVXc" opt; do ;; X) FILES+=('./smoketest/compose/db-viewer.yml') + URLS+=("http://db-viewer:8989") ;; c) ce="${OPTARG}" @@ -57,6 +62,7 @@ done if [ "${s3}" = "minio" ]; then FILES+=('./smoketest/compose/s3-minio.yml') + URLS+=("http://s3:9001") elif [ "${s3}" = "localstack" ]; then FILES+=('./smoketest/compose/s3-localstack.yml') else @@ -82,9 +88,12 @@ for file in "${FILES[@]}"; do CMD+=(-f "${file}") done +PIDS=() + HOSTSFILE="${HOSTSFILE:-$HOME/.hosts}" cleanup() { + set +xe DOWN_FLAGS=('--remove-orphans') if [ "${KEEP_VOLUMES}" != "true" ]; then DOWN_FLAGS+=('--volumes') @@ -94,6 +103,10 @@ cleanup() { down "${DOWN_FLAGS[@]}" # podman kill hoster || true truncate -s 0 "${HOSTSFILE}" + for i in "${PIDS[@]}"; do + kill -0 "${i}" && kill "${i}" + done + set -xe } trap cleanup EXIT cleanup @@ -101,7 +114,6 @@ cleanup setupUserHosts() { # FIXME this is broken: it puts the containers' bridge-internal IP addresses # into the user hosts file, but these IPs are in a subnet not reachable from the host. - # This requires https://github.com/figiel/hosts to work. See README. # podman run \ # --detach \ # --rm \ @@ -111,6 +123,8 @@ setupUserHosts() { # -v "${XDG_RUNTIME_DIR}/podman/podman.sock:/tmp/docker.sock:Z" \ # -v "${HOME}/.hosts:/tmp/hosts" \ # dvdarias/docker-hoster + # + # This requires https://github.com/figiel/hosts to work. See README. truncate -s 0 "${HOSTSFILE}" for file in "${FILES[@]}" ; do hosts="$(yq '.services.*.hostname' "${file}" | grep -v null | sed -e 's/^/localhost /')" @@ -119,6 +133,21 @@ setupUserHosts() { } setupUserHosts +openBrowserTabs() { + for i in "${URLS[@]}"; do + ( + until timeout 1s curl -s -f -o /dev/null "${i}" + do + sleep 5 + done + xdg-open "${i}" + echo "Opened '${i}' in default browser." + ) & + PIDS+=($!) + done +} +openBrowserTabs + if [ "${PULL_IMAGES}" = "true" ]; then IMAGES=() for file in "${FILES[@]}" ; do From cd4aa42b00ee86429823b94208bd6df04476081b Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Sat, 4 Nov 2023 10:07:26 -0400 Subject: [PATCH 3/7] fixup! test(smoketest): correct exposed vs mapped ports --- smoketest/compose/sample-apps.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/smoketest/compose/sample-apps.yml b/smoketest/compose/sample-apps.yml index b05af3b60..4f93679f6 100644 --- a/smoketest/compose/sample-apps.yml +++ b/smoketest/compose/sample-apps.yml @@ -36,8 +36,9 @@ services: # do not add a depends_on:cryostat here, so that we can test that the agent is tolerant of that state hostname: quarkus-test-agent ports: - - "9977:9977" - "10010:10010" + expose: + - "9977" environment: JAVA_OPTS: "-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager -javaagent:/deployments/app/cryostat-agent.jar" QUARKUS_HTTP_PORT: 10010 From 130f066a41819ae530ef9738cf91c99ec0e7bd1d Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Sat, 4 Nov 2023 10:59:10 -0400 Subject: [PATCH 4/7] determine URLs to open from loaded compose files --- smoketest.bash | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/smoketest.bash b/smoketest.bash index a59859e3d..1cc59e370 100755 --- a/smoketest.bash +++ b/smoketest.bash @@ -8,9 +8,6 @@ fi FILES=( ./smoketest/compose/db.yml ) -URLS=( - "http://localhost:8181" -) PULL_IMAGES=${PULL_IMAGES:-true} KEEP_VOLUMES=${KEEP_VOLUMES:-false} @@ -35,7 +32,6 @@ while getopts "s:gtOVXc" opt; do ;; g) FILES+=('./smoketest/compose/cryostat-grafana.yml' './smoketest/compose/jfr-datasource.yml') - URLS+=("http://grafana:3000") ;; t) FILES+=('./smoketest/compose/sample-apps.yml') @@ -48,7 +44,6 @@ while getopts "s:gtOVXc" opt; do ;; X) FILES+=('./smoketest/compose/db-viewer.yml') - URLS+=("http://db-viewer:8989") ;; c) ce="${OPTARG}" @@ -62,7 +57,6 @@ done if [ "${s3}" = "minio" ]; then FILES+=('./smoketest/compose/s3-minio.yml') - URLS+=("http://s3:9001") elif [ "${s3}" = "localstack" ]; then FILES+=('./smoketest/compose/s3-localstack.yml') else @@ -134,14 +128,31 @@ setupUserHosts() { setupUserHosts openBrowserTabs() { - for i in "${URLS[@]}"; do + # TODO find a way to use 'podman wait --condition=healthy $containerId' instead of polling with curl + set +xe + local urls=() + for file in "${FILES[@]}"; do + yaml="$(yq '.services.* | [{"host": .hostname, "ports": .ports}]' "${file}")" + length="$(echo "${yaml}" | yq 'length')" + for (( i=0; i<"${length}"; i+=1 )) + do + host="$(echo "${yaml}" | yq ".[${i}].host" | grep -v null)" + port="$(echo "${yaml}" | yq ".[${i}].ports[0]" | grep -v null | cut -d: -f1)" + if [ -n "${host}" ] && [ -n "${port}" ]; then + urls+=("http://${host}:${port}") + fi + done + done + set -xe + echo "Service URLs:" "${urls[@]}" + for url in "${urls[@]}"; do ( - until timeout 1s curl -s -f -o /dev/null "${i}" + until timeout 1s curl -s -f -o /dev/null "${url}" do sleep 5 done - xdg-open "${i}" - echo "Opened '${i}' in default browser." + xdg-open "${url}" + echo "Opened ${url} in default browser." ) & PIDS+=($!) done From 460abbc027fe3994a38fed42b57caf00e9a6203a Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Mon, 6 Nov 2023 14:10:11 -0500 Subject: [PATCH 5/7] only open tabs if -b flag passed --- smoketest.bash | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/smoketest.bash b/smoketest.bash index 1cc59e370..0336dcf5d 100755 --- a/smoketest.bash +++ b/smoketest.bash @@ -11,21 +11,23 @@ FILES=( PULL_IMAGES=${PULL_IMAGES:-true} KEEP_VOLUMES=${KEEP_VOLUMES:-false} +OPEN_TABS=${OPEN_TABS:-false} display_usage() { echo "Usage:" - echo -e "\t-O \t\t\t\tOffline mode, do not attempt to pull container images." + echo -e "\t-O\t\t\t\tOffline mode, do not attempt to pull container images." echo -e "\t-s [minio|localstack]\t\tS3 implementation to spin up (default \"minio\")." - echo -e "\t-g \t\t\t\tinclude Grafana dashboard and jfr-datasource in deployment." - echo -e "\t-t \t\t\t\tinclude sample applications for Testing." - echo -e "\t-V \t\t\t\tdo not discard data storage Volumes on exit." - echo -e "\t-X \t\t\t\tdeploy additional development aid tools." + echo -e "\t-g\t\t\t\tinclude Grafana dashboard and jfr-datasource in deployment." + echo -e "\t-t\t\t\t\tinclude sample applications for Testing." + echo -e "\t-V\t\t\t\tdo not discard data storage Volumes on exit." + echo -e "\t-X\t\t\t\tdeploy additional development aid tools." echo -e "\t-c [podman|docker]\t\tUse Podman or Docker Container Engine (default \"podman\")." + echo -e "\t-b\t\t\t\tOpen a Browser tab for each running service's first mapped port (ex. Cryostat web client, Minio console)" } s3=minio ce=podman -while getopts "s:gtOVXc" opt; do +while getopts "s:gtOVXcb" opt; do case $opt in s) s3="${OPTARG}" @@ -48,6 +50,9 @@ while getopts "s:gtOVXc" opt; do c) ce="${OPTARG}" ;; + b) + OPEN_TABS=true + ;; *) display_usage exit 1 @@ -157,7 +162,9 @@ openBrowserTabs() { PIDS+=($!) done } -openBrowserTabs +if [ "${OPEN_TABS}" = "true" ]; then + openBrowserTabs +fi if [ "${PULL_IMAGES}" = "true" ]; then IMAGES=() From 1b4ebf8b83f58610afac8dc30514f631608c23ef Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Mon, 6 Nov 2023 15:45:09 -0500 Subject: [PATCH 6/7] add explicit -h (help) flag --- smoketest.bash | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/smoketest.bash b/smoketest.bash index 0336dcf5d..2f216b783 100755 --- a/smoketest.bash +++ b/smoketest.bash @@ -15,6 +15,7 @@ OPEN_TABS=${OPEN_TABS:-false} display_usage() { echo "Usage:" + echo -e "\t-h\t\t\t\tprint this Help text." echo -e "\t-O\t\t\t\tOffline mode, do not attempt to pull container images." echo -e "\t-s [minio|localstack]\t\tS3 implementation to spin up (default \"minio\")." echo -e "\t-g\t\t\t\tinclude Grafana dashboard and jfr-datasource in deployment." @@ -27,8 +28,12 @@ display_usage() { s3=minio ce=podman -while getopts "s:gtOVXcb" opt; do +while getopts "hs:gtOVXcb" opt; do case $opt in + h) + display_usage + exit 0 + ;; s) s3="${OPTARG}" ;; From 6d331c402728b39f2c41b6b5d82b1d029957e898 Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Tue, 7 Nov 2023 14:50:59 -0500 Subject: [PATCH 7/7] make userhosts optional --- smoketest.bash | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/smoketest.bash b/smoketest.bash index 2f216b783..22ef61c96 100755 --- a/smoketest.bash +++ b/smoketest.bash @@ -9,6 +9,7 @@ FILES=( ./smoketest/compose/db.yml ) +USE_USERHOSTS=${USE_USERHOSTS:-true} PULL_IMAGES=${PULL_IMAGES:-true} KEEP_VOLUMES=${KEEP_VOLUMES:-false} OPEN_TABS=${OPEN_TABS:-false} @@ -98,13 +99,13 @@ HOSTSFILE="${HOSTSFILE:-$HOME/.hosts}" cleanup() { set +xe - DOWN_FLAGS=('--remove-orphans') + local downFlags=('--remove-orphans') if [ "${KEEP_VOLUMES}" != "true" ]; then - DOWN_FLAGS+=('--volumes') + downFlags=('--volumes') fi docker-compose \ "${CMD[@]}" \ - down "${DOWN_FLAGS[@]}" + down "${downFlags[@]}" # podman kill hoster || true truncate -s 0 "${HOSTSFILE}" for i in "${PIDS[@]}"; do @@ -131,22 +132,33 @@ setupUserHosts() { # This requires https://github.com/figiel/hosts to work. See README. truncate -s 0 "${HOSTSFILE}" for file in "${FILES[@]}" ; do + local hosts hosts="$(yq '.services.*.hostname' "${file}" | grep -v null | sed -e 's/^/localhost /')" echo "${hosts}" >> "${HOSTSFILE}" done } -setupUserHosts +if [ "${USE_USERHOSTS}" = "true" ]; then + setupUserHosts +fi openBrowserTabs() { # TODO find a way to use 'podman wait --condition=healthy $containerId' instead of polling with curl set +xe local urls=() for file in "${FILES[@]}"; do + local yaml yaml="$(yq '.services.* | [{"host": .hostname, "ports": .ports}]' "${file}")" + local length length="$(echo "${yaml}" | yq 'length')" for (( i=0; i<"${length}"; i+=1 )) do - host="$(echo "${yaml}" | yq ".[${i}].host" | grep -v null)" + local host + local port + if [ "${USE_USERHOSTS}" = "true" ]; then + host="$(echo "${yaml}" | yq ".[${i}].host" | grep -v null)" + else + host="localhost" + fi port="$(echo "${yaml}" | yq ".[${i}].ports[0]" | grep -v null | cut -d: -f1)" if [ -n "${host}" ] && [ -n "${port}" ]; then urls+=("http://${host}:${port}")