deploy-playground.yml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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-new'
  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. runtimeProfile:
  30. description: 'STAGING | PLAYGROUND | TESTING - leave balnk for production'
  31. required: false
  32. # TODO: customDomain instead of ip_address.nip.io
  33. # customDomain:
  34. # description: 'DNS hostname to use for deployment'
  35. # required: false
  36. # default: ''
  37. defaults:
  38. run:
  39. working-directory: devops/aws
  40. jobs:
  41. deploy-playground:
  42. name: Deploy Playground Job
  43. runs-on: ubuntu-latest
  44. env:
  45. STACK_NAME: ${{ github.event.inputs.stackNamePrefix }}-${{ github.event.inputs.branchName }}-${{ github.run_number }}
  46. steps:
  47. - name: Checkout
  48. uses: actions/checkout@v2
  49. - name: Install Ansible dependencies
  50. run: pipx inject ansible-core boto3 botocore
  51. - name: Configure AWS credentials
  52. uses: aws-actions/configure-aws-credentials@v1
  53. with:
  54. aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
  55. aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  56. aws-region: us-east-1
  57. - name: Check if CloudFormation stack exists
  58. id: stack_exists
  59. run: |
  60. if aws cloudformation describe-stacks --stack-name ${{ env.STACK_NAME }} >/dev/null 2>/dev/null; then
  61. echo "Stack already exists"
  62. exit 1
  63. else
  64. echo "Stack does not exist"
  65. fi
  66. - name: Deploy to AWS CloudFormation
  67. uses: aws-actions/aws-cloudformation-github-deploy@v1
  68. id: deploy_stack
  69. with:
  70. name: ${{ env.STACK_NAME }}
  71. template: devops/aws/cloudformation/single-instance-docker.yml
  72. no-fail-on-empty-changeset: '1'
  73. parameter-overrides: 'KeyName=${{ github.event.inputs.keyName }},EC2InstanceType=${{ github.event.inputs.instanceType }}'
  74. - name: Run playbook
  75. uses: dawidd6/action-ansible-playbook@v2
  76. with:
  77. playbook: deploy-playground-playbook.yml
  78. directory: devops/aws
  79. requirements: requirements.yml
  80. key: ${{ secrets.SSH_PRIVATE_KEY }}
  81. inventory: |
  82. [all]
  83. ${{ steps.deploy_stack.outputs.PublicIp }}
  84. options: |
  85. --extra-vars "git_repo=${{ github.event.inputs.gitRepo }} \
  86. branch_name=${{ github.event.inputs.branchName }} \
  87. skip_chain_setup=${{ github.event.inputs.skipChainSetup }} \
  88. stack_name=${{ env.STACK_NAME }} \
  89. runtime_profile=${{ github.event.inputs.runtimeProfile }}"
  90. - name: Save the endpoints file as an artifact
  91. uses: actions/upload-artifact@v2
  92. with:
  93. name: endpoints
  94. path: devops/aws/endpoints.json
  95. - name: Delete CloudFormation Stack if any step failed
  96. # Skip only if stack already existed or all steps passed successfully
  97. if: ( failure() || cancelled() ) && steps.stack_exists.outcome != 'failure'
  98. run: |
  99. echo "Deleting ${{ env.STACK_NAME }} stack"
  100. aws cloudformation delete-stack --stack-name ${{ env.STACK_NAME }}
  101. echo "Waiting for ${{ env.STACK_NAME }} to be deleted..."
  102. aws cloudformation wait stack-delete-complete --stack-name ${{ env.STACK_NAME }}