From 7db4773550e4272779bd88672db19a86bde4a131 Mon Sep 17 00:00:00 2001 From: samoht9277 Date: Thu, 11 Jan 2024 14:10:23 -0300 Subject: [PATCH 1/3] Changed host variable to stardardize name across repos. --- .github/workflows/deploy-testing.yaml | 6 +++--- ansible/inventory.yaml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy-testing.yaml b/.github/workflows/deploy-testing.yaml index 0fc255bd..1af6e495 100644 --- a/.github/workflows/deploy-testing.yaml +++ b/.github/workflows/deploy-testing.yaml @@ -32,12 +32,12 @@ jobs: - name: Create ssh private key file from env var env: SSH_KEY: ${{ secrets.SSH_KEY }} - HOST: ${{ vars.SSH_HOST }} + TS_HOST: ${{ vars.TS_HOST }} run: | mkdir -p ~/.ssh/ sed -E 's/(-+(BEGIN|END) OPENSSH PRIVATE KEY-+) *| +/\1\n/g' <<< "$SSH_KEY" > ~/.ssh/id_ed25519 chmod 400 ~/.ssh/id_ed25519 - ssh-keyscan $HOST >> ~/.ssh/known_hosts + ssh-keyscan $TS_HOST >> ~/.ssh/known_hosts - name: Install ansible run: | @@ -58,7 +58,7 @@ jobs: AWS_REGION: ${{ vars.AWS_REGION }} PROVER_STORAGE: ${{ vars.PROVER_STORAGE }} ANSIBLE_SSH_PKEY_DIR: "~/.ssh/id_ed25519" - SSH_HOST: ${{ vars.SSH_HOST }} + TS_HOST: ${{ vars.TS_HOST }} GIT_BRANCH: ${{ github.head_ref || github.ref_name }} ANSIBLE_STDOUT_CALLBACK: "yaml" ENABLE_MAINNET_SYNC: "true" diff --git a/ansible/inventory.yaml b/ansible/inventory.yaml index 1acf6438..d3c88a6d 100644 --- a/ansible/inventory.yaml +++ b/ansible/inventory.yaml @@ -1,7 +1,7 @@ webservers: hosts: starknet_testing: - ansible_host: "{{ lookup('ansible.builtin.env', 'SSH_HOST') }}" + ansible_host: "{{ lookup('ansible.builtin.env', 'TS_HOST') }}" ansible_user: starknet_explorer ansible_python_interpreter: /usr/bin/python3 ansible_ssh_private_key_file: "{{ lookup('ansible.builtin.env', 'ANSIBLE_SSH_PKEY_DIR') }}" From ae1d25a6231ea4dccb46aa8703daa6cddec922cf Mon Sep 17 00:00:00 2001 From: samoht9277 Date: Thu, 11 Jan 2024 14:45:22 -0300 Subject: [PATCH 2/3] Changed deploy configs to change starkcompass-testing user to dev. --- ansible/playbooks/deployment.yaml | 24 +++++++++---------- .../templates/starknet_explorer.service.j2 | 12 +++++----- entrypoint.sh | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/ansible/playbooks/deployment.yaml b/ansible/playbooks/deployment.yaml index fee8a8e8..0a893fff 100644 --- a/ansible/playbooks/deployment.yaml +++ b/ansible/playbooks/deployment.yaml @@ -4,22 +4,22 @@ gather_facts: false any_errors_fatal: true become: true - become_user: starknet_explorer + become_user: dev pre_tasks: - name: Delete tmp repo file: state: absent - path: /home/starknet_explorer/tmp/madara_explorer + path: /home/dev/tmp/madara_explorer - name: Clone repo in tmp dir ansible.builtin.git: repo: git@github.com:lambdaclass/stark_compass_explorer.git version: "{{ lookup('ansible.builtin.env', 'GIT_BRANCH') }}" - dest: /home/starknet_explorer/tmp/madara_explorer + dest: /home/dev/tmp/stark_compass_explorer ssh_opts: "-o StrictHostKeyChecking=no" - key_file: /home/starknet_explorer/.ssh/id_ed25519 + key_file: /home/dev/.ssh/id_ed25519 register: clone_output - name: Print clone repo output @@ -28,7 +28,7 @@ - name: Build ansible.builtin.shell: | set -ex - export PATH=${PATH}:/home/starknet_explorer/.cargo/bin + export PATH=${PATH}:/home/dev/.cargo/bin mix local.hex --force mix local.rebar --force mix deps.get --only $MIX_ENV @@ -55,7 +55,7 @@ ENABLE_TESTNET_SYNC: "{{ lookup('ansible.builtin.env', 'ENABLE_TESTNET_SYNC') }}" ENABLE_GATEWAY_DATA: "{{ lookup('ansible.builtin.env', 'ENABLE_GATEWAY_DATA') }}" args: - chdir: /home/starknet_explorer/tmp/madara_explorer + chdir: /home/dev/tmp/stark_compass_explorer register: build_output - debug: msg="{{ build_output.stdout_lines + [ build_output.stderr_lines ] }}" @@ -63,18 +63,18 @@ - name: Delete old repo ansible.builtin.file: state: absent - path: /home/starknet_explorer/madara_explorer + path: /home/dev/stark_compass_explorer - name: Copy repo from tmp dir ansible.builtin.copy: remote_src: true - src: /home/starknet_explorer/tmp/madara_explorer - dest: /home/starknet_explorer/ + src: /home/dev/tmp/stark_compass_explorer + dest: /home/dev/stark_compass_explorer - name: Create .env file ansible.builtin.template: src: .env.j2 - dest: /home/starknet_explorer/.env + dest: /home/dev/.env vars: phx_host: "{{ lookup('ansible.builtin.env', 'PHX_HOST') }}" secret_key_base: "{{ lookup('ansible.builtin.env', 'SECRET_KEY_BASE') }}" @@ -97,12 +97,12 @@ - name: Create user systemd directory ansible.builtin.file: state: directory - path: /home/starknet_explorer/.config/systemd/user + path: /home/dev/.config/systemd/user - name: Install systemd service ansible.builtin.template: src: starknet_explorer.service.j2 - dest: /home/starknet_explorer/.config/systemd/user/starknet_explorer.service + dest: /home/dev/.config/systemd/user/starknet_explorer.service - name: Restart starknet_explorer service ansible.builtin.systemd: diff --git a/ansible/playbooks/templates/starknet_explorer.service.j2 b/ansible/playbooks/templates/starknet_explorer.service.j2 index 5c609f9c..890ee069 100644 --- a/ansible/playbooks/templates/starknet_explorer.service.j2 +++ b/ansible/playbooks/templates/starknet_explorer.service.j2 @@ -1,15 +1,15 @@ [Unit] -Description=Madara Explorer +Description=StarkCompass Explorer [Service] -WorkingDirectory=/home/starknet_explorer/madara_explorer +WorkingDirectory=/home/dev/stark_compass_explorer Restart=on-failure -ExecStart=/home/starknet_explorer/madara_explorer/entrypoint.sh +ExecStart=/home/dev/stark_compass_explorer/entrypoint.sh ExecReload=/bin/kill -HUP KillSignal=SIGTERM -EnvironmentFile=/home/starknet_explorer/.env -StandardOutput=append:/home/starknet_explorer/logs/starknet_explorer.log -StandardError=append:/home/starknet_explorer/logs/starknet_explorer.log +EnvironmentFile=/home/dev/.env +StandardOutput=append:/home/dev/logs/starknet_explorer.log +StandardError=append:/home/dev/logs/starknet_explorer.log [Install] WantedBy=multi-user.target diff --git a/entrypoint.sh b/entrypoint.sh index 12ba8080..3e8ec840 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -/home/starknet_explorer/madara_explorer/_build/prod/rel/starknet_explorer/bin/starknet_explorer start +/home/dev/stark_compass_explorer/_build/prod/rel/starknet_explorer/bin/starknet_explorer start From 52ba46e7226279fd31e57d5cd0053ac9e2f8cba2 Mon Sep 17 00:00:00 2001 From: samoht9277 Date: Thu, 11 Jan 2024 15:46:26 -0300 Subject: [PATCH 3/3] Added retires to ssh-keyscan. --- .github/workflows/deploy-testing.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-testing.yaml b/.github/workflows/deploy-testing.yaml index 1af6e495..7fbf8538 100644 --- a/.github/workflows/deploy-testing.yaml +++ b/.github/workflows/deploy-testing.yaml @@ -37,7 +37,7 @@ jobs: mkdir -p ~/.ssh/ sed -E 's/(-+(BEGIN|END) OPENSSH PRIVATE KEY-+) *| +/\1\n/g' <<< "$SSH_KEY" > ~/.ssh/id_ed25519 chmod 400 ~/.ssh/id_ed25519 - ssh-keyscan $TS_HOST >> ~/.ssh/known_hosts + retries=5; until ssh-keyscan $TS_HOST >> ~/.ssh/known_hosts || [ $retries -eq 0 ]; do ((retries--)); sleep 5; done - name: Install ansible run: |