2019-11-13 19:27:28 +03:00
|
|
|
#!/usr/bin/env bash
|
2020-01-02 23:21:13 +03:00
|
|
|
# Copyright (c) 2020 The DAML Authors. All rights reserved.
|
2019-11-13 19:27:28 +03:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
set -e
|
|
|
|
set -u
|
|
|
|
set -o pipefail
|
|
|
|
|
|
|
|
CANTON_COMMAND=(
|
|
|
|
"$(rlocation com_github_digital_asset_daml/ledger/ledger-api-test-tool-on-canton/canton)"
|
|
|
|
daemon
|
|
|
|
"--config=$(rlocation com_github_digital_asset_daml/ledger/ledger-api-test-tool-on-canton/canton.conf)"
|
|
|
|
"--bootstrap=$(rlocation com_github_digital_asset_daml/ledger/ledger-api-test-tool-on-canton/bootstrap.canton)"
|
|
|
|
)
|
|
|
|
|
2020-01-23 11:04:16 +03:00
|
|
|
PARTICIPANT_1_HOST=localhost
|
2019-11-13 19:27:28 +03:00
|
|
|
PARTICIPANT_1_LEDGER_API_PORT=5011
|
2020-01-23 11:04:16 +03:00
|
|
|
PARTICIPANT_1_MONITORING_PORT=7000
|
|
|
|
PARTICIPANT_2_HOST=localhost
|
2019-11-13 19:27:28 +03:00
|
|
|
PARTICIPANT_2_LEDGER_API_PORT=5021
|
|
|
|
PARTICIPANTS=(
|
2020-01-23 11:04:16 +03:00
|
|
|
"${PARTICIPANT_1_HOST}:${PARTICIPANT_1_LEDGER_API_PORT}"
|
|
|
|
"${PARTICIPANT_2_HOST}:${PARTICIPANT_2_LEDGER_API_PORT}"
|
2019-11-13 19:27:28 +03:00
|
|
|
)
|
|
|
|
|
2020-01-23 11:04:16 +03:00
|
|
|
TIMEOUT=60
|
2019-11-13 19:27:28 +03:00
|
|
|
|
2020-01-23 11:04:16 +03:00
|
|
|
function wait_until() {
|
|
|
|
local start
|
2019-11-13 19:27:28 +03:00
|
|
|
|
|
|
|
start="$(date +%s)"
|
|
|
|
while true; do
|
2020-01-23 11:04:16 +03:00
|
|
|
if [[ "$(("$(date +%s)" - start))" -gt "$TIMEOUT" ]]; then
|
2019-11-13 19:27:28 +03:00
|
|
|
echo >&2 "Timed out after ${TIMEOUT} seconds."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2020-01-23 11:04:16 +03:00
|
|
|
if "$@" >&/dev/null; then
|
2019-11-13 19:27:28 +03:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
command=("${CANTON_COMMAND[@]}")
|
|
|
|
dars=()
|
|
|
|
port_file=''
|
2020-01-23 11:04:16 +03:00
|
|
|
while (($#)); do
|
2019-11-13 19:27:28 +03:00
|
|
|
# extract the port file
|
|
|
|
if [[ "$1" == '--port-file' ]]; then
|
|
|
|
port_file="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
# upload DARs with the DAML assistant
|
|
|
|
elif [[ "$1" =~ \.dar$ ]]; then
|
|
|
|
dars+=("$1")
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
command+=("$1")
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ -z "$port_file" ]]; then
|
|
|
|
# shellcheck disable=SC2016
|
|
|
|
echo >&2 'You must specify a port file with the `--port-file` switch.'
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2020-03-10 19:34:58 +03:00
|
|
|
# Change HOME since Canton uses ammonite in the default configuration
|
|
|
|
# which tries to write to ~/.ammonite/cache which is read-only
|
|
|
|
# when sandboxing is enabled.
|
|
|
|
export HOME=$(mktemp -d)
|
|
|
|
# ammonite calls System.getProperty('user.home') which does not
|
|
|
|
# read $HOME.
|
|
|
|
command+=("--wrapper_script_flag=--jvm_flag=-Duser.home=$HOME")
|
|
|
|
|
2019-11-13 19:27:28 +03:00
|
|
|
# Redirect the Canton logs to a file for now, because they're really, really noisy.
|
|
|
|
echo >&2 'Starting Canton...'
|
2020-01-23 11:04:16 +03:00
|
|
|
"${command[@]}" &
|
2019-11-13 19:27:28 +03:00
|
|
|
pid="$!"
|
|
|
|
|
|
|
|
sleep 1
|
2020-01-23 11:04:16 +03:00
|
|
|
if ! kill -0 "$pid" 2>/dev/null; then
|
2019-11-13 19:27:28 +03:00
|
|
|
echo >&2 'Failed to start Canton.'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-01-23 11:04:16 +03:00
|
|
|
function stop() {
|
2019-11-13 19:27:28 +03:00
|
|
|
local status
|
|
|
|
status=$?
|
2020-01-23 11:04:16 +03:00
|
|
|
kill -INT "$pid" || :
|
2019-11-13 19:27:28 +03:00
|
|
|
rm -f "$port_file" || :
|
2020-03-10 19:34:58 +03:00
|
|
|
rm -rf "$HOME" || :
|
2019-11-13 19:27:28 +03:00
|
|
|
exit "$status"
|
|
|
|
}
|
|
|
|
|
|
|
|
trap stop EXIT INT TERM
|
|
|
|
|
2020-01-23 11:04:16 +03:00
|
|
|
wait_until curl -fsS "http://${PARTICIPANT_1_HOST}:${PARTICIPANT_1_MONITORING_PORT}/health"
|
2019-11-13 19:27:28 +03:00
|
|
|
|
|
|
|
for participant in "${PARTICIPANTS[@]}"; do
|
|
|
|
for dar in "${dars[@]}"; do
|
2020-01-23 11:04:16 +03:00
|
|
|
base64 "$dar" |
|
|
|
|
jq -R --slurp '{"darFile": .}' |
|
|
|
|
grpcurl \
|
2019-11-13 19:27:28 +03:00
|
|
|
-plaintext \
|
|
|
|
-d @ \
|
|
|
|
"$participant" \
|
|
|
|
com.digitalasset.ledger.api.v1.admin.PackageManagementService.UploadDarFile \
|
2020-01-23 11:04:16 +03:00
|
|
|
>/dev/null
|
2019-11-13 19:27:28 +03:00
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
# This should write two ports, but the runner doesn't support that.
|
2020-01-23 11:04:16 +03:00
|
|
|
echo "$PARTICIPANT_1_LEDGER_API_PORT" >"$port_file"
|
2019-11-13 19:27:28 +03:00
|
|
|
|
|
|
|
echo >&2 'Canton is up and running.'
|
|
|
|
|
|
|
|
wait "$pid"
|