From 10e0572c47af3e10ddf1e726b8c636b84e2de886 Mon Sep 17 00:00:00 2001 From: Richard Hao Date: Mon, 7 Mar 2022 11:40:56 +1100 Subject: [PATCH 1/3] updated deploy.sh for substrate-node --- deploy.sh | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 141 insertions(+), 2 deletions(-) diff --git a/deploy.sh b/deploy.sh index 43562c0..864cbc8 100644 --- a/deploy.sh +++ b/deploy.sh @@ -1,2 +1,141 @@ -DOCKER_BUILDKIT=1 docker build . -t delphinus-node -f packages/substrate-node/Dockerfile -docker-compose -f packages/substrate-node/docker-compose.yml up + +#!/usr/bin/env bash +set -ueo pipefail + +local_repo_path="$(cd "$(dirname "$(dirname "${BASH_SOURCE[0]}")")" && pwd)" +machine= +domain= +repo="$local_repo_path" +private_key_file= +dry_run= +verbose= +logs_only= + +function usage() { + cat <&2 + usage + exit 1 + ;; + esac +done + +use_ssh="$machine" +repo_name="$(basename "$repo")" +repo_path="$local_repo_path" +if [[ -n "$use_ssh" ]]; then + repo_path="$repo_name" +fi + +function quote_command() { + python3 -c 'import shlex; import sys; print(shlex.join(sys.argv[1:]))' "$@" +} + +function run_command() { + command=("${@}") + if [[ -n "$dry_run" ]]; then + quote_command "${command[@]}" + else + if [[ -n "$verbose" ]]; then + quote_command "${command[@]}" + fi + "${command[@]}" + fi +} + +function run_maybe_remote_command() { + command=("${@}") + if [[ -n "$use_ssh" ]]; then + # ssh requires a single argument + command=(ssh "$machine" "$(quote_command "$@")") + fi + run_command "${command[@]}" +} + +function copy_repo() { + if [[ -z "$use_ssh" ]]; then + return + fi + run_command rsync -avz --progress --exclude target --cvs-exclude -h "$repo/" "$machine:$repo_name/" +} + +function start_node() { + + dockerfile_path="${repo_path}/packages/substrate-node/" + run_maybe_remote_command env DOCKER_BUILDKIT=1 docker build . -t delphinus-node -f "${dockerfile_path}/Dockerfile" + env=() + if [[ -n "$domain" ]]; then + env+=(NODE_DOMAIN="$domain") + fi + run_maybe_remote_command env "${env[@]}" docker-compose -f "$dockerfile_path/docker-compose.yml" up -d +} + +function follow_node_logs() { + run_maybe_remote_command docker-compose -f "$dockerfile_path/docker-compose.yml" logs -f +} + +function sanity_check() { + local_tools=(rsync python3) + remote_tools=(docker docker-compose) + if ! command -v "${local_tools[@]}" >/dev/null; then + echo "You need ${local_tools[*]} installed in the local machine." >&2 + exit 1 + fi + if ! run_maybe_remote_command command -v "${remote_tools[@]}" >/dev/null; then + echo "You need ${remote_tools[*]} installed in the remote machine." >&2 + exit 1 + fi + run_maybe_remote_command mkdir -p "$repo_name" + run_maybe_remote_command bash -c "docker network inspect caddy || docker network create caddy" >/dev/null 2>&1 +} + +function deploy() { + sanity_check + if [[ -z "$logs_only" ]]; then + copy_repo + start_node + fi + follow_node_logs +} + +deploy From 04ddab0f2a3e73d9ccb7ec8f8879c76c128a224a Mon Sep 17 00:00:00 2001 From: Richard Hao Date: Wed, 9 Mar 2022 18:08:54 +1100 Subject: [PATCH 2/3] deploy.sh updated with info --- README.md | 20 ++++++++++++++++++++ deploy.sh | 10 +++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f4a0378..a2bf56f 100644 --- a/README.md +++ b/README.md @@ -16,3 +16,23 @@ After finish install the environment, please open a new terminal to continue. Th All done! All delphinus packages are in packages directory. + + +## Deploying the Delphinus Substrate Node + +From the delphinus-lerna directory, execute the deploy script +`bash deploy.sh` +to start the process for deploying a substrate node. + +For this script to run successfully, ensure that `Dockerfile` and `docker-compose.yaml` are in the `packages/substrate-node` directory. + +The script will first build the docker image which may take up to a few minutes to complete. +If you encounter any errors during the docker image build process, some things to check are: + - Ensure delphinus-lerna environment is setup properly as there are several common packages required. + - Check relative paths of the `Dockerfile` in relation to the `deploy.sh` script. + +Once the docker image successfully builds, the script will execute `docker-compose` on the `docker-compose.yaml` file. + +If successful the node should be operational and you should be able to see the logs of blocks being submitted, block hashes etc. + + diff --git a/deploy.sh b/deploy.sh index 864cbc8..a9a9a8c 100644 --- a/deploy.sh +++ b/deploy.sh @@ -11,6 +11,7 @@ dry_run= verbose= logs_only= + function usage() { cat < Date: Wed, 9 Mar 2022 18:12:16 +1100 Subject: [PATCH 3/3] deploy.sh updated with info --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a2bf56f..0c23164 100644 --- a/README.md +++ b/README.md @@ -26,13 +26,16 @@ to start the process for deploying a substrate node. For this script to run successfully, ensure that `Dockerfile` and `docker-compose.yaml` are in the `packages/substrate-node` directory. -The script will first build the docker image which may take up to a few minutes to complete. +The script will first build the docker image which may take up to a few minutes to complete. + If you encounter any errors during the docker image build process, some things to check are: - Ensure delphinus-lerna environment is setup properly as there are several common packages required. - Check relative paths of the `Dockerfile` in relation to the `deploy.sh` script. -Once the docker image successfully builds, the script will execute `docker-compose` on the `docker-compose.yaml` file. +Once the docker image successfully builds, the script will execute `docker-compose` on the `docker-compose.yaml` file to start the container. + +If successful, the node should be operational and you should be able to see the logs of blocks being submitted, block hashes etc. + -If successful the node should be operational and you should be able to see the logs of blocks being submitted, block hashes etc.