added inventory file #18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy API | |
| on: | |
| push: | |
| branches: | |
| - master | |
| jobs: | |
| deploy: | |
| name: Compile, Test and Deploy API | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v3 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: "16" | |
| - name: Install dependencies | |
| run: npm install | |
| working-directory: src/movie-analyst-api | |
| - name: Run tests | |
| run: npm test | |
| working-directory: src/movie-analyst-api | |
| - name: Set up Terraform | |
| uses: hashicorp/setup-terraform@v3 | |
| - name: Terraform Init | |
| run: terraform -chdir=infra/modules/mysql-database init | |
| - name: Terraform Output | |
| id: tf | |
| run: | | |
| json=$(terraform -chdir=infra/modules/mysql-database output -json) | |
| echo "DB_HOST=$(echo $json | jq -r '.mysql_fqdn.value')" >> $GITHUB_ENV | |
| echo "DB_USER=$(echo $json | jq -r '.mysql_admin_user.value')" >> $GITHUB_ENV | |
| echo "DB_PASS=$(echo $json | jq -r '.mysql_admin_pwd.value')" >> $GITHUB_ENV | |
| echo "DB_NAME=$(echo $json | jq -r '.mysql_database_name.value')" >> $GITHUB_ENV | |
| - name: Create SSH key file | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "${{ secrets.VM_SSH_KEY }}" > ~/.ssh/vm_ssh_key | |
| chmod 600 ~/.ssh/vm_ssh_key | |
| env: | |
| VM_SSH_KEY: ${{ secrets.VM_SSH_KEY }} | |
| - name: Add jumpbox to known_hosts (disable host checking for simplicity, or add manually) | |
| run: | | |
| echo -e "Host *\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config | |
| - name: Make script executable | |
| run: chmod +x ./ansible/deploy-api-from-local.sh | |
| - name: Deploy API with Ansible | |
| run: ./ansible/deploy-api-from-local.sh |