Skip to content

Delete index.js file #84

Delete index.js file

Delete index.js file #84

Workflow file for this run

name: Build and Deploy Infrastructure
on:
push:
branches:
- main
jobs:
format:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Format Terraform files
working-directory: ./terraform
run: terraform fmt
terraform_and_Ansible:
needs: format
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Initialize Terraform
working-directory: ./terraform
run: terraform init
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_PRIVATE_KEY }}
- name: Validate Terraform files
working-directory: ./terraform
run: terraform validate
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_PRIVATE_KEY }}
- name: Apply Terraform configuration
working-directory: ./terraform
run: |
terraform apply -auto-approve
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_PRIVATE_KEY }}
- name: Configure & Deploy with Ansible
run: |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > private_key
eval $(ssh-agent -s)
chmod 400 private_key
ssh-add private_key
mkdir -p ~/.ssh
chmod 700 ~/.ssh
python3 -m pip install docker
ansible-galaxy collection install community.docker
echo "[all]" > inventory.ini
echo "my_instance ansible_host=$(cat ./terraform/hosts) ansible_user=ec2-user ansible_ssh_private_key_file=./private_key" >> inventory.ini
ansible-playbook -i inventory.ini playbook.yml --extra-vars "MONGO_INITDB_ROOT_USERNAME={MONGO_INITDB_ROOT_USERNAME} MONGO_INITDB_ROOT_PASSWORD={MONGO_INITDB_ROOT_PASSWORD} MONGO_INITDB_DATABASE={MONGO_INITDB_DATABASE} MONGODB_USER={MONGODB_USER} MONGODB_USER_PASSWORD={MONGODB_USER_PASSWORD} SITE_ADDRESS=$(cat ./terraform/hosts)"
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
ANSIBLE_HOST_KEY_CHECKING: False
destroy:
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch'
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Navigate to terraform directory
run: cd terraform
- name: Destroy Infrastructure (Manual Trigger)
run: terraform destroy -auto-approve