deploy-playground.yml 3.5 KB

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