123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- name: Deploy Playground
- on:
- workflow_dispatch:
- inputs:
- gitRepo:
- description: 'Code repository'
- required: false
- default: 'https://github.com/Joystream/joystream.git'
- branchName:
- description: 'Branch to deploy'
- required: false
- default: 'master'
- keyName:
- description: 'SSH key pair on AWS'
- required: false
- default: 'joystream-github-action-key-new'
- instanceType:
- description: 'AWS EC2 instance type (t2.micro, t2.large)'
- required: false
- default: 't2.micro'
- stackNamePrefix:
- description: 'Additional identifier to include in stack name'
- required: false
- default: 'playground'
- skipChainSetup:
- description: 'Optionally skip running newChainSetup script (true or false)'
- required: true
- default: 'false'
- runtimeProfile:
- description: 'STAGING | PLAYGROUND | TESTING - leave balnk for production'
- required: false
- # TODO: customDomain instead of ip_address.nip.io
- # customDomain:
- # description: 'DNS hostname to use for deployment'
- # required: false
- # default: ''
- defaults:
- run:
- working-directory: devops/aws
- jobs:
- deploy-playground:
- name: Deploy Playground Job
- runs-on: ubuntu-latest
- env:
- STACK_NAME: ${{ github.event.inputs.stackNamePrefix }}-${{ github.event.inputs.branchName }}-${{ github.run_number }}
- steps:
- - name: Checkout
- uses: actions/checkout@v2
- - name: Install Ansible dependencies
- run: pipx inject ansible-core boto3 botocore
- - name: Configure AWS credentials
- uses: aws-actions/configure-aws-credentials@v1
- with:
- aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
- aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- aws-region: us-east-1
- - name: Check if CloudFormation stack exists
- id: stack_exists
- run: |
- if aws cloudformation describe-stacks --stack-name ${{ env.STACK_NAME }} >/dev/null 2>/dev/null; then
- echo "Stack already exists"
- exit 1
- else
- echo "Stack does not exist"
- fi
- - name: Deploy to AWS CloudFormation
- uses: aws-actions/aws-cloudformation-github-deploy@v1
- id: deploy_stack
- with:
- name: ${{ env.STACK_NAME }}
- template: devops/aws/cloudformation/single-instance-docker.yml
- no-fail-on-empty-changeset: '1'
- parameter-overrides: 'KeyName=${{ github.event.inputs.keyName }},EC2InstanceType=${{ github.event.inputs.instanceType }}'
- - name: Run playbook
- uses: dawidd6/action-ansible-playbook@v2
- with:
- playbook: deploy-playground-playbook.yml
- directory: devops/aws
- requirements: requirements.yml
- key: ${{ secrets.SSH_PRIVATE_KEY }}
- inventory: |
- [all]
- ${{ steps.deploy_stack.outputs.PublicIp }}
- options: |
- --extra-vars "git_repo=${{ github.event.inputs.gitRepo }} \
- branch_name=${{ github.event.inputs.branchName }} \
- skip_chain_setup=${{ github.event.inputs.skipChainSetup }} \
- stack_name=${{ env.STACK_NAME }} \
- runtime_profile=${{ github.event.inputs.runtimeProfile }}"
- - name: Save the endpoints file as an artifact
- uses: actions/upload-artifact@v2
- with:
- name: endpoints
- path: devops/aws/endpoints.json
- - name: Delete CloudFormation Stack if any step failed
- # Skip only if stack already existed or all steps passed successfully
- if: ( failure() || cancelled() ) && steps.stack_exists.outcome != 'failure'
- run: |
- echo "Deleting ${{ env.STACK_NAME }} stack"
- aws cloudformation delete-stack --stack-name ${{ env.STACK_NAME }}
- echo "Waiting for ${{ env.STACK_NAME }} to be deleted..."
- aws cloudformation wait stack-delete-complete --stack-name ${{ env.STACK_NAME }}
|