deploy-playground.yml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. name: Deploy Playground
  2. on:
  3. workflow_dispatch:
  4. inputs:
  5. gitRepo:
  6. description: 'Code repository'
  7. required: false
  8. default: 'https://github.com/Joystream/joystream.git'
  9. branchName:
  10. description: 'Branch to deploy'
  11. required: false
  12. default: 'master'
  13. keyName:
  14. description: 'SSH key pair on AWS'
  15. required: false
  16. default: 'joystream-github-action-key'
  17. instanceType:
  18. description: 'AWS EC2 instance type (t2.micro, t2.large)'
  19. required: false
  20. default: 't2.micro'
  21. stackNamePrefix:
  22. description: 'Additional identifier to include in stack name'
  23. required: false
  24. default: 'playground'
  25. skipChainSetup:
  26. description: 'Optionally skip running newChainSetup script (true or false)'
  27. required: true
  28. default: 'false'
  29. # TODO: customDomain instead of ip_address.nip.io
  30. # customDomain:
  31. # description: 'DNS hostname to use for deployment'
  32. # required: false
  33. # default: ''
  34. defaults:
  35. run:
  36. working-directory: devops/aws
  37. jobs:
  38. deploy-playground:
  39. name: Deploy Playground Job
  40. runs-on: ubuntu-latest
  41. env:
  42. STACK_NAME: ${{ github.event.inputs.stackNamePrefix }}-${{ github.event.inputs.branchName }}-${{ github.run_number }}
  43. steps:
  44. - name: Checkout
  45. uses: actions/checkout@v2
  46. - name: Install Ansible dependencies
  47. run: pipx inject ansible-core boto3 botocore
  48. - name: Configure AWS credentials
  49. uses: aws-actions/configure-aws-credentials@v1
  50. with:
  51. aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
  52. aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  53. aws-region: us-east-1
  54. - name: Check if CloudFormation stack exists
  55. id: stack_exists
  56. run: |
  57. if aws cloudformation describe-stacks --stack-name ${{ env.STACK_NAME }} >/dev/null 2>/dev/null; then
  58. echo "Stack already exists"
  59. exit 1
  60. else
  61. echo "Stack does not exist"
  62. fi
  63. - name: Deploy to AWS CloudFormation
  64. uses: aws-actions/aws-cloudformation-github-deploy@v1
  65. id: deploy_stack
  66. with:
  67. name: ${{ env.STACK_NAME }}
  68. template: devops/aws/cloudformation/single-instance-docker.yml
  69. no-fail-on-empty-changeset: '1'
  70. parameter-overrides: 'KeyName=${{ github.event.inputs.keyName }},EC2InstanceType=${{ github.event.inputs.instanceType }}'
  71. - name: Run playbook
  72. uses: dawidd6/action-ansible-playbook@v2
  73. with:
  74. playbook: deploy-playground-playbook.yml
  75. directory: devops/aws
  76. requirements: requirements.yml
  77. key: ${{ secrets.SSH_PRIVATE_KEY }}
  78. inventory: |
  79. [all]
  80. ${{ steps.deploy_stack.outputs.PublicIp }}
  81. options: |
  82. --extra-vars "git_repo=${{ github.event.inputs.gitRepo }} \
  83. branch_name=${{ github.event.inputs.branchName }} \
  84. skip_chain_setup=${{ github.event.inputs.skipChainSetup }}"
  85. - name: Save the endpoints file as an artifact
  86. uses: actions/upload-artifact@v2
  87. with:
  88. name: endpoints
  89. path: devops/aws/endpoints.json
  90. - name: Delete CloudFormation Stack if any step failed
  91. # Skip if stack already existed
  92. if: failure() && steps.stack_exists.outcome != 'failure'
  93. run: |
  94. echo "Deleting ${{ env.STACK_NAME }} stack"
  95. aws cloudformation delete-stack --stack-name ${{ env.STACK_NAME }}
  96. echo "Waiting for ${{ env.STACK_NAME }} to be deleted..."
  97. aws cloudformation wait stack-delete-complete --stack-name ${{ env.STACK_NAME }}