Skip to content

add workflow

add workflow #1

Workflow file for this run

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