create-ami.yml 2.5 KB

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