-
Notifications
You must be signed in to change notification settings - Fork 1
104 lines (89 loc) · 3.4 KB
/
create-instance.yml
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
name: Create Instance
on:
issues:
types: [labeled]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
create:
runs-on: self-hosted
if: github.event.label.name == 'instance:approved'
steps:
- name: Issue Forms Body Parser
id: parse
uses: zentered/[email protected]
- name: Display parsed data
run: |
echo ${{ toJSON(steps.parse.outputs.data) }} | jq .
- name: Extract fields
id: extract
run: |
email=$(
echo ${{ toJSON(steps.parse.outputs.data) }} |
jq -r ".email.text"
)
echo "email=$email" >> $GITHUB_OUTPUT
instance_flavor=$(
echo ${{ toJSON(steps.parse.outputs.data) }} |
jq -r '."instance-flavor".text | split(" - ")[0]'
)
echo "instance_flavor=$instance_flavor" >> $GITHUB_OUTPUT
- name: Create instance
id: instance_create
run: |
echo Creating instance associated with issue $NUMBER
source ~/app-cred-morpho-cloud-portal_github-runner-openrc.sh > /dev/null 2>&1
source ~/venv/bin/activate
instance_name="morpho-cloud-portal_instance-$NUMBER"
openstack server create "$instance_name" \
--nic net-id="auto_allocated_network" \
--security-group "default" \
--security-group "exosphere" \
--flavor $INSTANCE_FLAVOR \
--image "antsthings-vgl-gpu-image" \
--wait \
--column created \
--column flavor \
--column image \
--column name \
--column status
echo "instance_name=$instance_name" >> $GITHUB_OUTPUT
env:
NUMBER: ${{ github.event.issue.number }}
INSTANCE_FLAVOR: ${{ steps.extract.outputs.instance_flavor }}
- name: Create floating IP
id: ip_create
run: |
source ~/app-cred-morpho-cloud-portal_github-runner-openrc.sh > /dev/null 2>&1
source ~/venv/bin/activate
json_output=$(openstack floating ip create public -f json)
echo $json_output
floating_ip_address=$(
echo $json_output |
jq -r ".floating_ip_address"
)
echo "floating_ip_address [$floating_ip_address]"
echo "floating_ip_address=$floating_ip_address" >> $GITHUB_OUTPUT
- name: Associate floating IP with created instance
run: |
source ~/app-cred-morpho-cloud-portal_github-runner-openrc.sh > /dev/null 2>&1
source ~/venv/bin/activate
openstack server add floating ip "$INSTANCE_NAME" $IP_ADDRESS
env:
IP_ADDRESS: ${{ steps.ip_create.outputs.floating_ip_address }}
INSTANCE_NAME: ${{ steps.instance_create.outputs.instance_name }}
- name: Send mail
uses: dawidd6/action-send-mail@2cea9617b09d79a095af21254fbcb7ae95903dde # v3.12.0
with:
server_address: smtp.gmail.com
server_port: 465
secure: true
username: ${{secrets.MAIL_USERNAME}}
password: ${{secrets.MAIL_PASSWORD}}
from: MorphoCloudPortal
to: ${{ steps.extract.outputs.email }}
subject:
"[MorphoCloudPortal] Instance ${{ github.event.issue.number }}
created"
body: Instance ${{ github.event.issue.number }} created