From d898e6fd987c6cfe2cb946fb5b22ae341046d1ab Mon Sep 17 00:00:00 2001 From: ktechmidas Date: Sun, 25 Jun 2023 06:01:49 +0000 Subject: [PATCH 1/5] Initial multi-stage deployment code --- ansible/continue.yml | 14 ++++++++++ bin/deploy | 66 +++++++++++++++++++++++++------------------- 2 files changed, 52 insertions(+), 28 deletions(-) create mode 100644 ansible/continue.yml diff --git a/ansible/continue.yml b/ansible/continue.yml new file mode 100644 index 00000000..8956589b --- /dev/null +++ b/ansible/continue.yml @@ -0,0 +1,14 @@ +--- +- name: Execute getbestchainlock + hosts: wallet_nodes + tasks: + - name: Run dash-cli getbestchainlock + command: dash-cli getbestchainlock + register: chainlock_output + ignore_errors: true + no_log: true + + - name: Check for chainlock + fail: + msg: "Chainlock failure: no chainlock found." + when: '"error" in chainlock_output.stderr' \ No newline at end of file diff --git a/bin/deploy b/bin/deploy index 6f5c51e6..d3ab3d6d 100755 --- a/bin/deploy +++ b/bin/deploy @@ -14,10 +14,13 @@ Options: -i --only-infrastructure - Only build infrastructure using Terraform -p --only-provisioning - Only provisioning using Ansible -f --force-deployment - Force deployment of a devnet branch on a different devnet + -s --stage - Stage of deployment, defaults to first stage (1) -a= --ansible-args= - Pass extra arguments to ansible-playbook command --ansible-playbook= - Specify custom playbook. Default: deploy -h --help - Show help" + +STAGE=1 #Default for i in "$@" do case ${i} in @@ -36,6 +39,9 @@ case ${i} in --ansible-playbook=*) ansible_playbook="${i#*=}.yml" ;; + -s=*|--stage=*) + STAGE="${i#*=}" + ;; -h|--help) echo "$CMD_USAGE" exit 0 @@ -50,31 +56,35 @@ done . ./lib/cli/terraform.sh . ./lib/cli/ansible.sh -echo "Deploying $NETWORK_NAME network..."; - -# TODO: this fails if not at the HEAD of a given branch -BRANCH=$(git symbolic-ref --short HEAD) -if [[ $BRANCH == "devnet-"* ]]; then - if [[ $BRANCH != $NETWORK_NAME ]] && [[ $FORCED_DEPLOYMENT != 1 ]]; then - echo "Wrong Devnet - Check you're in the correct branch. Use -f to force if you're sure" - exit 1 - fi -fi - -# Setup infrastructure using Terraform - -if [ -z ${ONLY_PROVISIONING} ]; then - terraform_run_command "apply" -else - echo "Skipping Terraform infrastructure deployment" -fi - -# Install software and configure dash network using Ansible - -if [ -z ${ONLY_INFRASTRUCTURE} ]; then - ansible_run_playbook "$ansible_playbook" -else - echo "Skipping Ansible provisioning" -fi - - +case ${STAGE} in + 1) + echo "Deploying $NETWORK_NAME network... stage (1)"; + + # TODO: this fails if not at the HEAD of a given branch + BRANCH=$(git symbolic-ref --short HEAD) + if [[ $BRANCH == "devnet-"* ]]; then + if [[ $BRANCH != $NETWORK_NAME ]] && [[ $FORCED_DEPLOYMENT != 1 ]]; then + echo "Wrong Devnet - Check you're in the correct branch. Use -f to force if you're sure" + exit 1 + fi + fi + + # Setup infrastructure using Terraform + if [ -z ${ONLY_PROVISIONING} ]; then + terraform_run_command "apply" + else + echo "Skipping Terraform infrastructure deployment" + fi + + # Install software and configure dash network using Ansible + if [ -z ${ONLY_INFRASTRUCTURE} ]; then + ansible_run_playbook "$ansible_playbook" + else + echo "Skipping Ansible provisioning" + fi + ;; + 2) + echo "stage 2" + ansible_run_playbook "continue.yml" + ;; +esac From 77bcf695c13ec3d4132260749d5ea32fb45a0b11 Mon Sep 17 00:00:00 2001 From: ktechmidas Date: Sun, 25 Jun 2023 06:13:15 +0000 Subject: [PATCH 2/5] newline --- ansible/continue.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ansible/continue.yml b/ansible/continue.yml index 8956589b..0c623459 100644 --- a/ansible/continue.yml +++ b/ansible/continue.yml @@ -11,4 +11,4 @@ - name: Check for chainlock fail: msg: "Chainlock failure: no chainlock found." - when: '"error" in chainlock_output.stderr' \ No newline at end of file + when: '"error" in chainlock_output.stderr' From 3ce226cad45e37024923c2da816c34163e7b89e4 Mon Sep 17 00:00:00 2001 From: ktechmidas Date: Sun, 25 Jun 2023 06:15:11 +0000 Subject: [PATCH 3/5] FQDN --- ansible/continue.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ansible/continue.yml b/ansible/continue.yml index 0c623459..e6d953f9 100644 --- a/ansible/continue.yml +++ b/ansible/continue.yml @@ -3,7 +3,7 @@ hosts: wallet_nodes tasks: - name: Run dash-cli getbestchainlock - command: dash-cli getbestchainlock + ansible.builtin.command: dash-cli getbestchainlock register: chainlock_output ignore_errors: true no_log: true From cde97409e56e0b4c48a1eed93a5e7f2fa3067a0f Mon Sep 17 00:00:00 2001 From: ktechmidas Date: Sun, 25 Jun 2023 06:16:33 +0000 Subject: [PATCH 4/5] FQDN for fail --- ansible/continue.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ansible/continue.yml b/ansible/continue.yml index e6d953f9..93df0591 100644 --- a/ansible/continue.yml +++ b/ansible/continue.yml @@ -9,6 +9,6 @@ no_log: true - name: Check for chainlock - fail: + ansible.builtin.fail: msg: "Chainlock failure: no chainlock found." when: '"error" in chainlock_output.stderr' From 0a5bcf383044f00f902fbcec5127ab4758d49d74 Mon Sep 17 00:00:00 2001 From: latte Date: Mon, 26 Jun 2023 09:07:54 +0400 Subject: [PATCH 5/5] Renamed file + removed no_log --- ansible/{continue.yml => stage2.yml} | 1 - bin/deploy | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) rename ansible/{continue.yml => stage2.yml} (95%) diff --git a/ansible/continue.yml b/ansible/stage2.yml similarity index 95% rename from ansible/continue.yml rename to ansible/stage2.yml index 93df0591..a0b63a3f 100644 --- a/ansible/continue.yml +++ b/ansible/stage2.yml @@ -6,7 +6,6 @@ ansible.builtin.command: dash-cli getbestchainlock register: chainlock_output ignore_errors: true - no_log: true - name: Check for chainlock ansible.builtin.fail: diff --git a/bin/deploy b/bin/deploy index d3ab3d6d..60792ac7 100755 --- a/bin/deploy +++ b/bin/deploy @@ -84,7 +84,6 @@ case ${STAGE} in fi ;; 2) - echo "stage 2" - ansible_run_playbook "continue.yml" + ansible_run_playbook "stage2.yml" ;; esac