Skip to content

Commit

Permalink
Add ansible
Browse files Browse the repository at this point in the history
Use dawidd6/action-ansible-playbook@v2
Remove verbose commands
Set GOVTOOL_TAG env-variable
  • Loading branch information
mesudip committed May 9, 2024
1 parent b5fd880 commit 5ad580a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 12 deletions.
22 changes: 13 additions & 9 deletions .github/workflows/build-and-deploy-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -30,16 +29,21 @@ jobs:
with:
fetch-depth: 0


- name: Setup SSH agent
uses: webfactory/ssh-agent@v0.8.0
with:
ssh-private-key: ${{ secrets.TEST_STACK_SSH_KEY }}

- name: Update images
working-directory: "./tests/test-infrastructure"
run: |
pwd
ls
set -x;
./build-and-deploy.sh update-images
- name: Run Ansible playbook
uses: dawidd6/action-ansible-playbook@v2
with:
playbook: playbook.yml
directory: ./tests/test-infrastructure
key: ${{ secrets.TEST_STACK_SSH_KEY }}
inventory: |
[test_server]
${{ secrets.TEST_STACK_SERVER_IP }} ansible_user=ec2-user
options: |
--verbose
env:
GOVTOOL_TAG: ${{ github.sha }}
7 changes: 5 additions & 2 deletions tests/test-infrastructure/build-and-deploy.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/usr/bin/env bash
set -vx;
export BASE_IMAGE_NAME=govtool
export GOVTOOL_TAG="$(git rev-parse HEAD)"
export PROJECT_NAME=govtool
export CARDANO_NETWORK=sanchonet
export BASE_DOMAIN=govtool.cardanoapi.io

if [ -z "$GOVTOOL_TAG" ]; then
GOVTOOL_TAG="$(git rev-parse HEAD)"
fi
export GOVTOOL_TAG

. ./scripts/deploy-stack.sh

check_env
Expand Down
1 change: 0 additions & 1 deletion tests/test-infrastructure/build-images.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env bash
set -e
set -vx;
export BASE_IMAGE_NAME="govtool"
BASE_IMAGE_EXISTS=$(docker images -q "$BASE_IMAGE_NAME"/backend-base)

Expand Down
39 changes: 39 additions & 0 deletions tests/test-infrastructure/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
- name: Update deployed images.
hosts: test_server
gather_facts: no
tasks:
- name: Create /opt/govtool directory if it does not exist
ansible.builtin.file:
path: /opt/govtool
state: directory
become: yes

- 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/
- .env.example
become: yes

- name: Execute build-and-deploy.sh
ansible.builtin.shell: "/opt/govtool/build-and-deploy.sh update-images"
args:
chdir: "/opt/govtool"
environment:
GOVTOOL_TAG: "{{ lookup('env', 'GOVTOOL_TAG') }}"
become: yes

0 comments on commit 5ad580a

Please sign in to comment.