-
Notifications
You must be signed in to change notification settings - Fork 117
127 lines (117 loc) · 4.83 KB
/
Copy pathdeploy-playground.yml
File metadata and controls
127 lines (117 loc) · 4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
name: Deploy Playground
on:
workflow_dispatch:
inputs:
gitRepo:
description: 'Code repository'
required: false
default: 'https://github.com/Joystream/joystream.git'
branchName:
description: 'Branch to deploy'
required: false
default: 'master'
runtimeProfile:
description: 'PLAYGROUND | TESTING'
default: 'PLAYGROUND'
required: false
sshPubKey:
description: 'SSH pubkey eg. `ssh-rsa AAAAB3NzaC1yc2EA....0hc3GND8IR mysshkey`'
required: false
stackNamePrefix:
description: 'Additional identifier to include in stack name'
required: false
default: 'playground'
skipChainSetup:
description: 'Optionally skip running newChainSetup script (true or false)'
required: false
default: 'false'
chainSetupScenario:
description: 'Scenario name to run after chain stats'
required: false
default: 'setupNewChainMultiStorage'
treasurySuri:
description: 'SURI of treasury account'
required: false
default: '//Alice'
initialBalances:
description: 'JSON string or http URL to override initial balances and vesting config'
default: ''
required: false
defaults:
run:
working-directory: devops/aws
jobs:
deploy-playground:
name: Deploy Playground Job
runs-on: ubuntu-latest
env:
STACK_NAME: ${{ github.event.inputs.stackNamePrefix }}-${{ github.event.inputs.branchName }}-${{ github.run_number }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Ansible
run: |
pip3 install --upgrade --user ansible
pipx inject ansible-core boto3 botocore
ansible-playbook --version
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# When changing region double check ami image is available in deploy step
aws-region: eu-central-1
- name: Check if CloudFormation stack exists
id: stack_exists
run: |
if aws cloudformation describe-stacks --stack-name ${{ env.STACK_NAME }} >/dev/null 2>/dev/null; then
echo "Stack already exists"
exit 1
else
echo "Stack does not exist"
fi
- name: Deploy to AWS CloudFormation
uses: aws-actions/aws-cloudformation-github-deploy@v1
id: deploy_stack
with:
name: ${{ env.STACK_NAME }}
template: devops/aws/cloudformation/single-instance.yml
no-fail-on-empty-changeset: '1'
# Make sure ami image is available in the region specified in configure aws creds step
parameter-overrides: 'KeyName=joystream-github-action-key-new,EC2InstanceType=t2.xlarge,EC2AMI=ami-06b4d9ba1f23a8da4'
- name: Wait for docker build server to be ready
run: |
sleep 30
- name: Run playbook
uses: dawidd6/action-ansible-playbook@v2
with:
playbook: deploy-playground-playbook.yml
directory: devops/ansible
requirements: requirements.yml
key: ${{ secrets.SSH_PRIVATE_KEY }}
inventory: |
${{ steps.deploy_stack.outputs.PublicIp }}
options: |
--extra-vars "git_repo=${{ github.event.inputs.gitRepo }} \
branch_name=${{ github.event.inputs.branchName }} \
skip_chain_setup=${{ github.event.inputs.skipChainSetup }} \
stack_name=${{ env.STACK_NAME }} \
runtime_profile=${{ github.event.inputs.runtimeProfile }} \
ssh_pub_key='${{ github.event.inputs.sshPubKey }}' \
treasury_suri='${{ github.event.inputs.treasurySuri }}' \
initial_balances='${{ github.event.inputs.initialBalances }}' \
init_chain_scenario='${{ github.event.inputs.chainSetupScenario }}'"
--verbose
- name: Save the endpoints file as an artifact
uses: actions/upload-artifact@v4
with:
name: endpoints
path: devops/ansible/endpoints.json
- name: Delete CloudFormation Stack if any step failed
# Skip only if stack already existed or all steps passed successfully
if: ( failure() || cancelled() ) && steps.stack_exists.outcome != 'failure'
run: |
echo "Deleting ${{ env.STACK_NAME }} stack"
aws cloudformation delete-stack --stack-name ${{ env.STACK_NAME }}
echo "Waiting for ${{ env.STACK_NAME }} to be deleted..."
aws cloudformation wait stack-delete-complete --stack-name ${{ env.STACK_NAME }}