Provision staging (tag: checks) #318
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: Provision Infrastructure | |
| run-name: "Provision ${{ inputs.environment }} (tag: ${{ inputs.tags }})" | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| environment: | |
| description: 'Infrastructure to provision' | |
| required: true | |
| default: 'dev' | |
| type: choice | |
| options: | |
| - staging | |
| - production | |
| - demo1 | |
| tags: | |
| description: 'Tags to apply to the provisioned resources' | |
| required: true | |
| default: all | |
| type: choice | |
| options: | |
| - all | |
| - checks | |
| - updates | |
| - users | |
| - backup | |
| - application | |
| - tools | |
| - fail2ban | |
| - data-partition | |
| - decrypt-on-boot | |
| - containerd-setup | |
| - k8s | |
| - system-preparation | |
| jobs: | |
| approve: | |
| environment: ${{ inputs.environment }} | |
| runs-on: ubuntu-24.04 | |
| timeout-minutes: 60 | |
| steps: | |
| - name: Waiting for manual approval | |
| if: ${{ (vars.APPROVAL_REQUIRED || 'false') == 'true' }} | |
| uses: trstringer/manual-approval@v1 | |
| with: | |
| secret: ${{ github.TOKEN }} | |
| approvers: ${{ vars.GH_APPROVERS }} | |
| minimum-approvals: 1 | |
| issue-title: "Provision ${{ inputs.environment }} (tag: ${{ inputs.tags }})" | |
| issue-body: > | |
| Please approve or deny ${{ inputs.environment }} environment provisioning | |
| initiated from GitHub Actions by @${{ github.actor }}. | |
| exclude-workflow-initiator-as-approver: false | |
| provision: | |
| needs: approve | |
| runs-on: | |
| - self-hosted | |
| - ${{ inputs.environment }} | |
| - node | |
| environment: ${{ inputs.environment }} | |
| steps: | |
| - name: Set variables for ansible | |
| id: ansible-variables | |
| run: | | |
| echo '${{ toJSON(env) }}' > tmp_vars.json | |
| JSON_WITHOUT_EMPTY=$(jq -c 'with_entries(select(.value | type == "string" and length > 0))' tmp_vars.json | jq -R ) | |
| echo "EXTRA_VARS=$JSON_WITHOUT_EMPTY" >> $GITHUB_OUTPUT | |
| env: | |
| encrypted_disk_size: ${{ vars.DISK_SPACE }} | |
| disk_encryption_key: ${{ secrets.ENCRYPTION_KEY }} | |
| k8s_runner_token: ${{ secrets.GH_TOKEN }} | |
| repository: ${{ github.repository }} | |
| k8s_cluster_env: ${{ inputs.environment }} | |
| docker_username: ${{ secrets.DOCKER_USERNAME }} | |
| docker_password: ${{ secrets.DOCKER_TOKEN }} | |
| smtp_host: ${{ secrets.SMTP_HOST }} | |
| smtp_port: ${{ secrets.SMTP_PORT }} | |
| smtp_user: ${{ secrets.SMTP_USERNAME }} | |
| smtp_secure: ${{ secrets.SMTP_SECURE }} | |
| # FIXME: Make this field configurable via secrets | |
| smtp_from: "[email protected]" | |
| smtp_password: ${{ secrets.SMTP_PASSWORD }} | |
| alert_email: ${{ secrets.ALERT_EMAIL }} | |
| - name: checkout repository | |
| uses: actions/checkout@v5 | |
| - name: Run Ansible Playbook | |
| uses: dawidd6/action-ansible-playbook@v4 | |
| env: | |
| ANSIBLE_PERSISTENT_COMMAND_TIMEOUT: 10 | |
| ANSIBLE_SSH_TIMEOUT: 10 | |
| ANSIBLE_SSH_RETRIES: 5 | |
| with: | |
| requirements: galaxy-requirements.yml | |
| playbook: playbook.yml | |
| directory: ./infrastructure/server-setup | |
| # Add --verbose to get more output | |
| options: |- | |
| --inventory inventory/${{ inputs.environment }}.yml | |
| ${{ inputs.tags != 'all' && format('--tags={0}', inputs.tags) || '' }} | |
| --extra-vars ""${{ steps.ansible-variables.outputs.EXTRA_VARS }}"" |