From d7712af41e5df3a6a286add5f0606d46703c7eaa Mon Sep 17 00:00:00 2001 From: klaus993 <18153834+klaus993@users.noreply.github.com> Date: Mon, 31 Jul 2023 17:59:31 -0300 Subject: [PATCH] Add testing deployment (#75) * Parametrize ansible SSH HOST * Add testing deployment * Add testing URL to check_origin --- .github/workflows/deploy-production.yaml | 50 ++++++++++++++++++++++++ .github/workflows/deploy-testing.yaml | 5 ++- ansible/inventory.yaml | 2 +- config/runtime.exs | 3 +- 4 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/deploy-production.yaml diff --git a/.github/workflows/deploy-production.yaml b/.github/workflows/deploy-production.yaml new file mode 100644 index 00000000..0e52620b --- /dev/null +++ b/.github/workflows/deploy-production.yaml @@ -0,0 +1,50 @@ +name: Deploy https://madaraexplorer.com/ +on: + push: + tags: + - v** + +jobs: + + build-deploy: + name: Build and deploy to testing + runs-on: ubuntu-latest + environment: + name: production + url: https://madaraexplorer.com/ + steps: + + - name: Checkout + uses: actions/checkout@v3.3.0 + + - name: Create ssh private key file from env var + env: + SSH_KEY: ${{ secrets.SSH_KEY }} + run: | + set -ex + sed -E 's/(-+(BEGIN|END) OPENSSH PRIVATE KEY-+) *| +/\1\n/g' <<< "$SSH_KEY" > id_ed25519_testing + chmod 400 id_ed25519_production + + - name: Install ansible + run: | + pip install ansible + + - name: "Deploy with ansible" + env: + MIX_ENV: ${{ vars.MIX_ENV }} + DATABASE_URL: ${{ secrets.DATABASE_URL }} + SECRET_KEY_BASE: ${{ secrets.SECRET_KEY_BASE }} + PHX_HOST: ${{ vars.PHX_HOST }} + PHX_SERVER: ${{ vars.PHX_SERVER }} + RPC_API_HOST: ${{ secrets.RPC_API_HOST }} + TESTNET_RPC_API_HOST: ${{ secrets.TESTNET_RPC_API_HOST }} + TESTNET_2_RPC_API_HOST: ${{ secrets.TESTNET_2_RPC_API_HOST }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_REGION: ${{ vars.AWS_REGION }} + PROVER_STORAGE: ${{ vars.PROVER_STORAGE }} + ANSIBLE_SSH_PKEY_DIR: "./id_ed25519_production" + SSH_HOST: ${{ vars.SSH_HOST }} + GIT_BRANCH: ${{ github.head_ref || github.ref_name }} + run: | + ansible-playbook -i ansible/inventory.yaml ansible/playbooks/deployment.yaml diff --git a/.github/workflows/deploy-testing.yaml b/.github/workflows/deploy-testing.yaml index 2a6ce06c..2bbc80d4 100644 --- a/.github/workflows/deploy-testing.yaml +++ b/.github/workflows/deploy-testing.yaml @@ -1,4 +1,4 @@ -name: Deploy https://madaraexplorer.com/ +name: Deploy https://testing.madaraexplorer.com/ on: push: branches: @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest environment: name: testing - url: https://madaraexplorer.com/ + url: https://testing.madaraexplorer.com/ steps: - name: Checkout @@ -45,6 +45,7 @@ jobs: AWS_REGION: ${{ vars.AWS_REGION }} PROVER_STORAGE: ${{ vars.PROVER_STORAGE }} ANSIBLE_SSH_PKEY_DIR: "./id_ed25519_testing" + SSH_HOST: ${{ vars.SSH_HOST }} GIT_BRANCH: ${{ github.head_ref || github.ref_name }} run: | ansible-playbook -i ansible/inventory.yaml ansible/playbooks/deployment.yaml diff --git a/ansible/inventory.yaml b/ansible/inventory.yaml index 79a709ad..1acf6438 100644 --- a/ansible/inventory.yaml +++ b/ansible/inventory.yaml @@ -1,7 +1,7 @@ webservers: hosts: starknet_testing: - ansible_host: "157.90.154.208" + ansible_host: "{{ lookup('ansible.builtin.env', 'SSH_HOST') }}" ansible_user: starknet_explorer ansible_python_interpreter: /usr/bin/python3 ansible_ssh_private_key_file: "{{ lookup('ansible.builtin.env', 'ANSIBLE_SSH_PKEY_DIR') }}" diff --git a/config/runtime.exs b/config/runtime.exs index ee8fe11c..9871a7ea 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -94,7 +94,8 @@ if config_env() == :prod do check_origin: [ "https://madaraexplorer.com", "https://www.madaraexplorer.com", - "https://madaraexplorer.lambdaclass.com" + "https://madaraexplorer.lambdaclass.com", + "https://testing.madaraexplorer.com" ], http: [ # Enable IPv6 and bind on all interfaces.