create-ami.yml 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. name: Build code and create AMI
  2. on:
  3. push:
  4. branches:
  5. - master
  6. - olympia
  7. - test_branch
  8. jobs:
  9. build:
  10. name: Build the code and run setup
  11. runs-on: ubuntu-latest
  12. env:
  13. STACK_NAME: joystream-github-action-${{ github.run_number }}
  14. KEY_NAME: joystream-github-action-key
  15. steps:
  16. - name: Extract branch name
  17. shell: bash
  18. run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
  19. id: extract_branch
  20. - name: Set AMI Name environment variable
  21. shell: bash
  22. run: echo "ami_name=joystream-${{ steps.extract_branch.outputs.branch }}-${{ github.run_number }}" >> $GITHUB_ENV
  23. id: ami_name
  24. - name: Checkout
  25. uses: actions/checkout@v2
  26. - name: Configure AWS credentials
  27. uses: aws-actions/configure-aws-credentials@v1
  28. with:
  29. aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
  30. aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  31. aws-region: us-east-1
  32. - name: Deploy to AWS CloudFormation
  33. uses: aws-actions/aws-cloudformation-github-deploy@v1
  34. id: deploy_stack
  35. with:
  36. name: ${{ env.STACK_NAME }}
  37. template: devops/infrastructure/single-instance.yml
  38. no-fail-on-empty-changeset: "1"
  39. parameter-overrides: "KeyName=${{ env.KEY_NAME }}"
  40. - name: Install Ansible dependencies
  41. run: pipx inject ansible-base boto3 botocore
  42. - name: Run playbook
  43. uses: dawidd6/action-ansible-playbook@v2
  44. with:
  45. playbook: github-action-playbook.yml
  46. directory: devops/infrastructure
  47. requirements: requirements.yml
  48. key: ${{ secrets.SSH_PRIVATE_KEY }}
  49. inventory: |
  50. [all]
  51. ${{ steps.deploy_stack.outputs.PublicIp }}
  52. options: |
  53. --extra-vars "git_repo=https://github.com/${{ github.repository }} \
  54. branch_name=${{ steps.extract_branch.outputs.branch }} instance_id=${{ steps.deploy_stack.outputs.InstanceId }}
  55. stack_name=${{ env.STACK_NAME }} ami_name=${{ env.ami_name }}"