terraform outputs #34
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 ] | |
| env: | |
| NODE_VERSION: 16 | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: 🟢 Set up Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| - name: 📦 Install dependencies | |
| run: npm ci | |
| 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: 📤 Export Terraform Outputs | |
| 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: 🔑 Configure SSH | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "${{ secrets.VM_SSH_KEY }}" > ~/.ssh/vm_ssh_key | |
| chmod 600 ~/.ssh/vm_ssh_key | |
| echo -e "Host *\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config | |
| - name: 🚀Run Ansible deployment | |
| run: | | |
| ansible-playbook -i ansible/inventory.ini ansible/api-setup.yml \ | |
| -e "db_host=${{ env.DB_HOST }}" \ | |
| -e "db_user=${{ env.DB_USER }}" \ | |
| -e "db_password=${{ env.DB_PASS }}" \ | |
| -e "db_name=${{ env.DB_NAME }}" |