From 28356c3bfe43b8db7ceb140fbfbc59978624da95 Mon Sep 17 00:00:00 2001 From: Ivy Fan-Chiang Date: Sun, 15 Oct 2023 07:38:50 -0400 Subject: [PATCH] add workflow --- .github/workflows/deploy_bundle.yml | 51 +++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .github/workflows/deploy_bundle.yml diff --git a/.github/workflows/deploy_bundle.yml b/.github/workflows/deploy_bundle.yml new file mode 100644 index 0000000..70e5b3a --- /dev/null +++ b/.github/workflows/deploy_bundle.yml @@ -0,0 +1,51 @@ +name: Deploy Bundle +on: [push] +permissions: + contents: write + +jobs: + Deploy-Bundle: + name: Deploy Bundle + runs-on: ubuntu-latest + permissions: write-all + steps: + - name: Check out repository code + uses: actions/checkout@v4 + - name: Install Deployment Tools + run: wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg && echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list && sudo apt-get update && sudo apt-get install -y ansible terraform + - name: Versions + run: ansible --version && terraform --version + - name: Create SSH Key + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ssh_priv: ${{ secrets.SSH_PRIV_KEY }} + REPO: ${{ github.event.repository.name }} + if: ${{ env.ssh_priv == '' }} + run: ssh-keygen -q -t rsa -f ~/.ssh/id_rsa -N "" && cp ~/.ssh/id_rsa.pub deploy_bundle/pub_key #&& cat ~/.ssh/id_rsa | gh secret -R $GITHUB_REPOSITORY set SSH_PRIV_KEY + - name: Terraform Init + run: cd deploy_bundle && terraform init && ls -a -l + - name: Get Google Cloud Platform Credentials + env: + GCP_CREDS: ${{ secrets.GCP_CREDS }} + run: cd deploy_bundle && echo $GCP_CREDS > gcp_creds.json + - name: Terraform Plan + run: cd deploy_bundle && terraform plan + - name: Terraform Apply + run: cd deploy_bundle && terraform apply -auto-approve + - name: Commit Terraform State File + run: | + cd deploy_bundle + git add *.tfstate + git config user.name "Deploy Bundle Action" --global + git config user.email "github-actions[bot]@users.noreply.github.com" --global + git commit --message "Commit State File" + git push + - name: Generate Ansible Configuration + run: | + cd deploy_bundle + python3 ansible.py + - name: Run Ansible Playbook + run: | + cd deploy_bundle + ansible-playbook nginx.yml +