[v6.0.28] #252
This file contains 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: ManualWorkflow | |
env: | |
ARM_CLIENT_ID: ${{ secrets.TF_ARM_CLIENT_ID }} | |
ARM_CLIENT_SECRET: ${{ secrets.TF_ARM_CLIENT_SECRET }} | |
ARM_SUBSCRIPTION_ID: ${{ secrets.TF_ARM_SUBSCRIPTION_ID }} | |
ARM_TENANT_ID: ${{ secrets.TF_ARM_TENANT_ID }} | |
PRIVATE_KEY: ${{ secrets.VMPRIV }} | |
BOT_TOKEN: ${{secrets.NODE_DISC_API_KEY}} | |
OPENAI_API_KEY: ${{secrets.NODE_OPENAI_API_KEY}} | |
botDiscId: ${{secrets.NODE_DISC_BOT_ID}} | |
channelId: ${{secrets.NODE_DISC_CHANNEL_ID}} | |
guildId: ${{secrets.NODE_DISC_GUILD_ID}} | |
on: | |
push: | |
branches: ["main"] | |
workflow_dispatch: | |
inputs: | |
name: | |
type: choice | |
description: "What do you want to do?" | |
options: | |
- CreateInfra | |
- Destroy | |
- UpdateImage | |
permissions: | |
contents: readF | |
jobs: | |
buildImage: | |
if: ${{ github.event.inputs.name == 'UpdateImage' }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Push to GitHub Container Registry | |
uses: docker/build-push-action@v2 | |
with: | |
push: true | |
tags: ghcr.io/${{ github.repository_owner }}/discbot:latest | |
env: | |
BOT_TOKEN: ${{secrets.NODE_DISC_API_KEY}} | |
startDocker: | |
needs: buildImage | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- run: echo "$PRIVATE_KEY" > infra/ansible/VMPriv.pem | |
- run: chmod 600 infra/ansible/VMPriv.pem | |
- run: # get latest chars of infra/ansible/VMPriv.pem | |
- name: Ansible Playbook | |
run: ansible-playbook -i infra/ansible/inventory infra/ansible/main.yaml --extra-vars "BOT_TOKEN=$BOT_TOKEN OPENAI_API_KEY=$OPENAI_API_KEY botDiscId=$botDiscId channelId=$channelId guildId=$guildId" | |
- name: Upload Ansible Artifact | |
uses: actions/upload-artifact@master | |
with: | |
name: ansible.out | |
path: infra/ansible/ansible.out | |
plan: | |
if: ${{ github.event.inputs.name == 'CreateInfra' }} | |
runs-on: ubuntu-latest | |
#must have terraform installed. After installing, init the "infra" folder using -chdir flag, and run terraform plan | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: hashicorp/setup-terraform@v2 | |
- name: Terraform Init | |
run: terraform -chdir=infra init | |
- name: Terraform Plan ## save play.out as artifact | |
run: terraform -chdir=infra plan -out=plan.out | |
- name: Upload Artifact | |
uses: actions/upload-artifact@master | |
with: | |
name: plan.out | |
path: infra | |
apply: # run only if plan is successful | |
needs: plan | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: hashicorp/setup-terraform@v2 | |
- name: Terraform Init | |
run: terraform -chdir=infra init | |
- name: Download Artifact | |
uses: actions/download-artifact@master | |
with: | |
name: plan.out | |
path: infra | |
- name: Terraform Apply | |
run: terraform -chdir=infra apply -auto-approve plan.out | |
- name: Upload Artifact | |
uses: actions/upload-artifact@master | |
with: | |
name: terraform.tfstate | |
path: infra | |
# destroy: # run after apply | |
# if: ${{ github.event.inputs.name == 'Destroy' }} | |
# runs-on: ubuntu-latest | |
# steps: | |
# - uses: actions/checkout@v2 | |
# - uses: hashicorp/setup-terraform@v2 | |
# - name: Terraform Init | |
# run: terraform -chdir=infra init | |
# #Destroy only VM, NIC, and Public IP | |
# - name: Terraform Destroy | |
# run: terraform -chdir=infra destroy -auto-approve --target azurerm_virtual_machine.vm --target=azurerm_network_interface.nic --target=azurerm_public_ip.ip | |
# |