Instance: Workflow Sandbox #12
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: Remove "instance:approved" label | |
if: ${{ always() }} | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
github.rest.issues.removeLabel({ | |
issue_number: context.payload.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
name: ["instance:approved"] | |
}) | |
- 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 | |
- name: Add "instance:created" label | |
if: ${{ success() }} | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
github.rest.issues.addLabels({ | |
issue_number: context.payload.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
name: ["instance:created"] | |
}) |