Move Docker scripts (#138)

Just reorganizing
This commit is contained in:
Cecile Tonglet
2020-07-16 07:46:03 +02:00
committed by GitHub
parent 03205eb601
commit 516ad523c1
10 changed files with 5 additions and 5 deletions
+21
View File
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -e
cd "$(cd "$(dirname "$0")" && git rev-parse --show-toplevel)"
dockerfile="$1"
if [ -z "$dockerfile" ]; then
dockerfile="./docker/test-parachain-collator.dockerfile"
else
shift 1
fi
image_name="$(basename "$dockerfile" | rev | cut -d. -f2- | rev)"
echo "building $dockerfile as $image_name..."
time docker build \
-f "$dockerfile" \
-t "$image_name":latest \
"$@" \
.
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -e
cumulus_repo=$(cd "$(dirname "$0")" && git rev-parse --show-toplevel)
polkadot_repo=$(dirname "$cumulus_repo")/polkadot
if [ ! -d "$polkadot_repo/.git" ]; then
echo "please clone polkadot in parallel to this repo:"
echo " (cd .. && git clone git@github.com:paritytech/polkadot.git)"
exit 1
fi
if [ -z "$BRANCH" ]; then
BRANCH=cumulus-branch
fi
cd "$polkadot_repo"
git fetch
git checkout "$BRANCH"
time docker build \
-f ./docker/Dockerfile \
--build-arg PROFILE=release \
-t polkadot:"$BRANCH" .
+10
View File
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
# helper function to run docker-compose using the docker/docker-compose.yml file while
# retaining a context from the root of the repository
set -e
dc () {
cd "$(cd "$(dirname "$0")" && git rev-parse --show-toplevel)"
docker-compose -f - "$@" < docker/docker-compose.yml
}
+14
View File
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -e
head () {
polkadot-js-api --ws ws://172.28.1.1:9944 query.parachains.heads 100 |\
jq -r .heads
}
start=$(head)
sleep 60
end=$(head)
[ "$start" != "$end" ]
+50
View File
@@ -0,0 +1,50 @@
#!/usr/bin/env bash
# this script runs the cumulus-test-parachain-collator after fetching
# appropriate bootnode IDs
#
# this is _not_ a general-purpose script; it is closely tied to the
# root docker-compose.yml
set -e -o pipefail
ctpc="/usr/bin/cumulus-test-parachain-collator"
if [ ! -x "$ctpc" ]; then
echo "FATAL: $ctpc does not exist or is not executable"
exit 1
fi
# name the variable with the incoming args so it isn't overwritten later by function calls
args=( "$@" )
alice="172.28.1.1"
bob="172.28.1.2"
p2p_port="30333"
rpc_port="9933"
get_id () {
node="$1"
/wait-for-it.sh "$node:$rpc_port" -t 10 -s -- \
curl -sS \
-H 'Content-Type: application/json' \
--data '{"id":1,"jsonrpc":"2.0","method":"system_networkState"}' \
"$node:$rpc_port" |\
jq -r '.result.peerId'
}
bootnode () {
node="$1"
id=$(get_id "$node")
if [ -z "$id" ]; then
echo >&2 "failed to get id for $node"
exit 1
fi
echo "/ip4/$node/tcp/$p2p_port/p2p/$id"
}
args+=( "--" "--bootnodes=$(bootnode "$alice")" "--bootnodes=$(bootnode "$bob")" )
set -x
"$ctpc" "${args[@]}"
+58
View File
@@ -0,0 +1,58 @@
#!/usr/bin/env bash
set -e -o pipefail
sizeof () {
stat --printf="%s" "$1"
}
wait_for_file () {
# Wait for a file to have a stable, non-zero size.
# Takes at least 0.2 seconds per run, but there's no upper bound if the
# file grows continuously. If the file doesn't exist, or stably has 0 size,
# this will take up to 10 seconds by default; this limit can be adjusted by
# the second input parameter.
path="$1"
limit="$2"
if [ -z "$limit" ]; then
limit=10
fi
count=0
while [ "$count" -lt "$limit" ]; do
if [ -s "$path" ]; then
echo "$path found after $count seconds"
# now ensure that the file size is stable: it's not still being written
oldsize=0
size="$(sizeof "$path")"
while [ "$oldsize" -ne "$size" ]; do
sleep 0.2
oldsize="$size"
size="$(sizeof "$path")"
done
return
fi
count=$((count+1))
sleep 1
done
echo "$path not found after $count seconds"
exit 1
}
wait_for_file /runtime/cumulus_test_parachain_runtime.compact.wasm
wait_for_file /genesis/genesis-state
# this is now straightforward: just send the sudo'd tx to the alice node,
# as soon as the node is ready to receive connections
/wait-for-it.sh 172.28.1.1:9944 \
--strict \
--timeout=10 \
-- \
polkadot-js-api \
--ws ws://172.28.1.1:9944 \
--sudo \
--seed "//Alice" \
tx.registrar.registerPara \
100 \
'{"scheduling":"Always"}' \
@/runtime/cumulus_test_parachain_runtime.compact.wasm \
"$(cat /genesis/genesis-state)"
+10
View File
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -e
cd "$(cd "$(dirname "$0")" && git rev-parse --show-toplevel)"
# shellcheck source=dc.sh
source docker/scripts/dc.sh
dc build
dc up -d
+9
View File
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -e
cd "$(cd "$(dirname "$0")" && git rev-parse --show-toplevel)"
# shellcheck source=dc.sh
source docker/scripts/dc.sh
dc down --volumes --remove-orphans