create-ami.yml 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Creates an AWS AMI (system image) with compiled joystream-node and subkey
  2. #
  3. name: Create AWS AMI
  4. on:
  5. workflow_dispatch:
  6. inputs:
  7. runtimeProfile:
  8. description: 'STAGING | TESTING - leave blank for production build'
  9. required: false
  10. jobs:
  11. build:
  12. name: Build the code and run setup
  13. runs-on: ubuntu-latest
  14. env:
  15. STACK_NAME: create-joystream-node-ami-ga-${{ github.run_number }}
  16. KEY_NAME: joystream-github-action-key-new
  17. steps:
  18. - name: Extract branch name
  19. shell: bash
  20. run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
  21. id: extract_branch
  22. - name: Set AMI Name environment variable
  23. shell: bash
  24. run: echo "ami_name=joystream-node-${{ steps.extract_branch.outputs.branch }}-${{ github.run_number }}" >> $GITHUB_ENV
  25. id: ami_name
  26. - name: Checkout
  27. uses: actions/checkout@v2
  28. - name: Configure AWS credentials
  29. uses: aws-actions/configure-aws-credentials@v1
  30. with:
  31. aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
  32. aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  33. aws-region: us-east-1
  34. - name: Deploy to AWS CloudFormation
  35. uses: aws-actions/aws-cloudformation-github-deploy@v1
  36. id: deploy_stack
  37. with:
  38. name: ${{ env.STACK_NAME }}
  39. template: devops/aws/cloudformation/single-instance.yml
  40. no-fail-on-empty-changeset: '1'
  41. parameter-overrides: 'KeyName=${{ env.KEY_NAME }}'
  42. - name: Install Ansible dependencies
  43. run: pipx inject ansible-core boto3 botocore
  44. - name: Run playbook
  45. uses: dawidd6/action-ansible-playbook@v2
  46. with:
  47. playbook: create-joystream-node-ami-playbook.yml
  48. directory: devops/aws
  49. requirements: requirements.yml
  50. key: ${{ secrets.SSH_PRIVATE_KEY }}
  51. inventory: |
  52. [all]
  53. ${{ steps.deploy_stack.outputs.PublicIp }}
  54. options: |
  55. --extra-vars "git_repo=https://github.com/${{ github.repository }} \
  56. branch_name=${{ steps.extract_branch.outputs.branch }} \
  57. instance_id=${{ steps.deploy_stack.outputs.InstanceId }} \
  58. ami_name=${{ env.ami_name }} \
  59. runtime_profile=${{ github.event.inputs.runtimeProfile }}"
  60. - name: Delete CloudFormation Stack
  61. if: always()
  62. continue-on-error: true
  63. run: |
  64. echo "Deleting ${{ env.STACK_NAME }} stack"
  65. aws cloudformation delete-stack --stack-name ${{ env.STACK_NAME }}
  66. echo "Waiting for ${{ env.STACK_NAME }} to be deleted..."
  67. aws cloudformation wait stack-delete-complete --stack-name ${{ env.STACK_NAME }}