From 9090f695381f02f1bb52bc398cfea3203eb586b7 Mon Sep 17 00:00:00 2001 From: Sudip Bhattarai Date: Thu, 9 May 2024 09:38:36 +0545 Subject: [PATCH] Add ansible --- .github/workflows/build-and-deploy-test.yml | 16 +++++++----- tests/test-infrastructure/inventory.ini | 2 ++ tests/test-infrastructure/playbook.yml | 29 +++++++++++++++++++++ 3 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 tests/test-infrastructure/inventory.ini create mode 100644 tests/test-infrastructure/playbook.yml diff --git a/.github/workflows/build-and-deploy-test.yml b/.github/workflows/build-and-deploy-test.yml index a2c7f6e5..27c8b2a9 100644 --- a/.github/workflows/build-and-deploy-test.yml +++ b/.github/workflows/build-and-deploy-test.yml @@ -15,7 +15,6 @@ jobs: name: Deploy app runs-on: ubuntu-latest env: - DOCKER_HOST: ssh://ec2-user@${{secrets.TEST_STACK_SERVER_IP }} GRAFANA_ADMIN_PASSWORD: ${{ secrets.GRAFANA_ADMIN_PASSWORD }} GRAFANA_SLACK_RECIPIENT: ${{ secrets.GRAFANA_SLACK_RECIPIENT }} GRAFANA_SLACK_OAUTH_TOKEN: ${{ secrets.GRAFANA_SLACK_OAUTH_TOKEN }} @@ -36,10 +35,13 @@ jobs: with: ssh-private-key: ${{ secrets.TEST_STACK_SSH_KEY }} - - name: Update images - working-directory: "./tests/test-infrastructure" + + - name: Install Ansible + run: sudo apt-get update && sudo apt-get install -y ansible + + - name: Run Ansible playbook + env: + SERVER_IP_ADDRESS: ${{ secrets.TEST_STACK_SERVER_IP }} + working-directory: ./tests/test-infrastructure run: | - pwd - ls - set -x; - ./build-and-deploy.sh update-images + ansible-playbook -i inventory.ini playbook.yml diff --git a/tests/test-infrastructure/inventory.ini b/tests/test-infrastructure/inventory.ini new file mode 100644 index 00000000..9308b346 --- /dev/null +++ b/tests/test-infrastructure/inventory.ini @@ -0,0 +1,2 @@ +[server] +server1 ansible_host={{ lookup('env', 'SERVER_IP_ADDRESS') }} ansible_user=myuser diff --git a/tests/test-infrastructure/playbook.yml b/tests/test-infrastructure/playbook.yml new file mode 100644 index 00000000..34a7c632 --- /dev/null +++ b/tests/test-infrastructure/playbook.yml @@ -0,0 +1,29 @@ +--- +- name: Copy files and execute build-and-deploy.sh + hosts: servers + gather_facts: no + tasks: + - name: Copy files to the server + ansible.builtin.copy: + src: "{{ item }}" + dest: "/opt/govtool/{{ item }}" + mode: '0755' + with_items: + - build-and-deploy.sh + - build-images.sh + - configs_template/ + - deploy.sh + - docker-compose-basic-services.yml + - docker-compose-cardano.yml + - docker-compose-govaction-loader.yml + - docker-compose-govtool.yml + - docker-compose-test.yml + - gen-configs.sh + - scripts/ + - secrets_template/ + become: yes + - name: Execute build-and-deploy.sh + ansible.builtin.shell: "/opt/govtool/build-and-deploy.sh update-images" + args: + chdir: "/opt/govtool" + become: yes