Instance: Workflow Sandbox #28
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 | |
- uses: actions/checkout@v4 | |
- name: Create instance | |
id: instance_create | |
run: | | |
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" | |
echo Creating instance "$instance_name" | |
openstack server create "$instance_name" \ | |
--nic net-id="auto_allocated_network" \ | |
--security-group "default" \ | |
--security-group "exosphere" \ | |
--flavor $INSTANCE_FLAVOR \ | |
--image "Featured-Ubuntu22" \ | |
--key-name "jcfr" \ | |
--property "exoGuac={\"v\":1,\"ssh\":true,\"vnc\":true}" \ | |
--property "exoClientUuid=67296a2e-069b-49ca-9ca4-5dd296869ada" \ | |
--property "exoServerVersion=5" \ | |
--property "[email protected]" \ | |
--property "exoFloatingIpOption=automatic" \ | |
--user-data ./cloud-config \ | |
--wait \ | |
--column created \ | |
--column flavor \ | |
--column image \ | |
--column name \ | |
--column status | |
openstack server set "$instance_name" \ | |
--property "exoSetup={\"status\":\"complete\",\"epoch\":$EPOCHSECONDS}" | |
echo "instance_name=$instance_name" >> $GITHUB_OUTPUT | |
env: | |
NUMBER: ${{ github.event.issue.number }} | |
INSTANCE_FLAVOR: ${{ steps.extract.outputs.instance_flavor }} | |
- 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 ${{ | |
steps.instance_create.outputs.instance_name }} created" | |
body: | |
Instance ${{ steps.instance_create.outputs.instance_name }} 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, | |
labels: ["instance:created"] | |
}) |