Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
List of MorphoCloudWorkflow changes:

```
$ git shortlog b459137..eb6b737 --no-merges
Jean-Christophe Fillion-Robin (2):
      doc(README): Fix runner instructions to grant instance user access to docker
      feat: Refactor send-email composite action to remove duplicated code
```

See MorphoCloud/MorphoCloudWorkflow@b459137...eb6b737
  • Loading branch information
jcfr committed Sep 12, 2024
1 parent d218bf5 commit 9ec533b
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 178 deletions.
5 changes: 0 additions & 5 deletions .github/actions/comment-progress/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ inputs:
attach_volume:
description: "Template input set to '', ✅ or ⏳"
required: true
retrieve_connection_url:
description: "Template input set to '', ✅ or ⏳"
required: true
send_email:
description: "Template input set to '', ✅ or ⏳"
required: true
Expand All @@ -45,7 +42,6 @@ runs:
"{{ inputs.associate_ip }}" == "✅" && \
"{{ inputs.setup_instance }}" == "✅" && \
"{{ inputs.attach_volume }}" == "✅" && \
"{{ inputs.retrieve_connection_url }}" == "✅" && \
"{{ inputs.send_email }}" == "✅" \
]]; then
value="✅"
Expand All @@ -67,7 +63,6 @@ runs:
associate_ip: ${{ inputs.associate_ip }}
setup_instance: ${{ inputs.setup_instance }}
attach_volume: ${{ inputs.attach_volume }}
retrieve_connection_url: ${{ inputs.retrieve_connection_url }}
send_email: ${{ inputs.send_email }}
status: ${{ steps.status.outputs.value }}
Expand Down
93 changes: 78 additions & 15 deletions .github/actions/send-email/action.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
name: "Send email"
description: "Send email with instance connection details"
inputs:
to:
description: "Recipient of the instance connection details"
os_cloud:
description:
"Name of the OpenStack cloud allocation to select openstack auth settings
defined in '.config/openstack/clouds.yaml'"
required: true
token:
description: "GITHUB_TOKEN or repo scoped PAT"
required: true
string_encryption_key:
description: "Encryption key to encode and decode the email address"
required: true
mail_server_username:
description: "mail server username"
Expand All @@ -16,18 +24,57 @@ inputs:
instance_issue_number:
description: "Reference of the GitHub issue associated with the instance"
required: true
connection_url:
description: "Guacamole Connection URL"
required: true
instance_ip:
description: "Public IP associated with the instance"
required: true
instance_pwd:
description: "Passphrase associated with the instance"
required: true
outputs:
error_message:
description: "Error message describing which steps failed"
value: ${{ steps.set_error_message.outputs.error_message }}
runs:
using: "composite"
steps:
- name: Extract fields
id: extract
uses: ./.github/actions/extract-issue-fields
with:
token: ${{ inputs.token }}
repository: ${{ github.repository }}
issue_number: ${{ inputs.instance_issue_number }}

- name: Retrieve metadata
id: instance_metadata
uses: ./.github/actions/retrieve-metadata
with:
os_cloud: ${{ inputs.os_cloud }}
instance_name: ${{ inputs.instance_name }}

- name: Generate Guacamole Connection URL
if: ${{ steps.instance_poll.outputs.status == 'complete' }}
id: guacamole
uses: ./.github/actions/generate-connection-url
with:
instance_ip: ${{ steps.instance_metadata.outputs.instance_ip }}

- name: Check if email is encoded
id: check_email_encryption
shell: bash
run: |
if [[ "$EMAIL" != *"@"* ]]; then
encoded="true"
else
encoded="false"
fi
echo "encoded=$encoded" >> $GITHUB_OUTPUT
env:
EMAIL: ${{ steps.extract.outputs.email }}

- name: Decode email
id: decode_email
uses: ./.github/actions/encode-decode-string
with:
input_string: ${{ steps.extract.outputs.email }}
encryption_key: ${{ inputs.string_encryption_key }}
operation: "decode"
skip: ${{ steps.check_email_encryption.outputs.encoded == 'false' }}

- name: Send mail
uses: dawidd6/action-send-mail@2cea9617b09d79a095af21254fbcb7ae95903dde # v3.12.0
with:
Expand All @@ -37,7 +84,7 @@ runs:
username: ${{ inputs.mail_server_username }}
password: ${{ inputs.mail_server_password }}
from: MorphoCloudPortal
to: ${{ inputs.to }}
to: ${{ steps.decode_email.outputs.output_string }}
subject:
"[${{ github.event.repository.name }}] Instance ${{
inputs.instance_name }} created"
Expand All @@ -63,10 +110,26 @@ runs:
**Connection Methods:**
- Web connect: ${{ inputs.connection_url }}
- SSH: `ssh exouser@${{ inputs.instance_ip }}`
- Web connect: ${{ steps.guacamole.outputs.connection_url }}
- SSH: `ssh exouser@${{ steps.instance_metadata.outputs.instance_ip }}`
**Credentials:**
- Username: **exouser**
- Passphrase: `${{ inputs.instance_pwd }}`
- Passphrase: `${{ steps.instance_metadata.outputs.instance_pwd }}`
- name: Set error message
id: set_error_message
if: ${{ failure() }}
shell: bash
run: |
if [[ $INSTANCE_METADATA_OUTCOME == "failure" ]]; then
error_message="Failed to retrieve metadata"
elif [[ $GUACAMOLE_OUTCOME == "failure" ]]; then
error_message="Failed to generate connection URL"
fi
echo "error_message=$error_message" >> $GITHUB_OUTPUT
env:
# Step outcome
INSTANCE_METADATA_OUTCOME: ${{ steps.instance_metadata.outcome }}
GUACAMOLE_OUTCOME: ${{ steps.guacamole.outcome }}
6 changes: 3 additions & 3 deletions .github/instance-creation-progress-template.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
### Instance Creation Progress {{ .status }}

| Create IP | Create Volume | Create Instance | Associate IP | Setup Instance | Attach volume | Retrieve Connection URL | Send Email |
| :--------------: | :------------------: | :--------------------: | :-----------------: | :-------------------: | :------------------: | :---------------------------: | :---------------: |
| {{ .create_ip }} | {{ .create_volume }} | {{ .create_instance }} | {{ .associate_ip }} | {{ .setup_instance }} | {{ .attach_volume }} | {{ .retrieve_connection_url}} | {{ .send_email }} |
| Create IP | Create Volume | Create Instance | Associate IP | Setup Instance | Attach volume | Send Email |
| :--------------: | :------------------: | :--------------------: | :-----------------: | :-------------------: | :------------------: | :---------------: |
| {{ .create_ip }} | {{ .create_volume }} | {{ .create_instance }} | {{ .associate_ip }} | {{ .setup_instance }} | {{ .attach_volume }} | {{ .send_email }} |

See details at {{ .details_url }}
102 changes: 13 additions & 89 deletions .github/workflows/create-instance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,8 @@ jobs:
associate_ip: ""
setup_instance: ""
attach_volume: ""
retrieve_connection_url: ""
send_email: ""

- name: Extract fields
id: extract
uses: ./.github/actions/extract-issue-fields
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
issue_number: ${{ github.event.issue.number }}

- name: Extract labels
id: labels
run: |
Expand Down Expand Up @@ -150,7 +141,6 @@ jobs:
associate_ip: ""
setup_instance: ""
attach_volume: ""
retrieve_connection_url: ""
send_email: ""

- name: Define volume name
Expand Down Expand Up @@ -212,7 +202,6 @@ jobs:
associate_ip: ""
setup_instance: ""
attach_volume: ""
retrieve_connection_url: ""
send_email: ""

- name: Create instance
Expand Down Expand Up @@ -278,7 +267,6 @@ jobs:
associate_ip:
setup_instance: ""
attach_volume: ""
retrieve_connection_url: ""
send_email: ""

- name: Associate floating IP with created instance
Expand Down Expand Up @@ -323,7 +311,6 @@ jobs:
associate_ip:
setup_instance:
attach_volume: ""
retrieve_connection_url: ""
send_email: ""

- name: Poll instance setup status
Expand Down Expand Up @@ -388,7 +375,6 @@ jobs:
associate_ip:
setup_instance:
attach_volume:
retrieve_connection_url: ""
send_email: ""

- name: Attach Volume
Expand Down Expand Up @@ -444,44 +430,30 @@ jobs:
associate_ip:
setup_instance:
attach_volume:
retrieve_connection_url:
send_email: ""
send_email:

- name: Retrieve metadata
id: instance_metadata
uses: ./.github/actions/retrieve-metadata
- name: Send mail
id: send_email
if: ${{ steps.instance_poll.outputs.status == 'complete' }}
uses: ./.github/actions/send-email
with:
os_cloud: ${{ vars.MORPHOCLOUD_OS_CLOUD }}
token: ${{ secrets.GITHUB_TOKEN }}
string_encryption_key: ${{ secrets.STRING_ENCRYPTION_KEY }}
mail_server_username: ${{secrets.MAIL_USERNAME}}
mail_server_password: ${{secrets.MAIL_PASSWORD}}
instance_name: ${{ steps.define.outputs.instance_name }}
instance_issue_number: ${{ github.event.issue.number }}

- name: comment (failed to retrieve instance metadata)
if: ${{ steps.instance_metadata.outcome == 'failure' && failure() }}
uses: peter-evans/[email protected]
with:
issue-number: ${{ github.event.issue.number }}
body: |
### Instance Creation Results ❌
Failed to retrieve metadata for instance **${{ steps.define.outputs.instance_name }}**.
See details at https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
- name: Generate Guacamole Connection URL
if: ${{ steps.instance_poll.outputs.status == 'complete' }}
id: guacamole
uses: ./.github/actions/generate-connection-url
with:
instance_ip: ${{ steps.instance_metadata.outputs.instance_ip }}

- name: comment (failed to generate connection URL)
if: ${{ steps.guacamole.outcome == 'failure' && failure() }}
- name: comment (failed to send email)
if: ${{ steps.send_connection_email.outcome == 'failure' && failure() }}
uses: peter-evans/[email protected]
with:
issue-number: ${{ github.event.issue.number }}
body: |
### Instance Creation Results ❌
Failed to generate connection URL for instance **${{ steps.define.outputs.instance_name }}**.
Failed to send connection email for instance **${{ steps.define.outputs.instance_name }}**. ${{ steps.send_email.outputs.error_message }}
See details at https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
Expand All @@ -495,52 +467,4 @@ jobs:
associate_ip:
setup_instance:
attach_volume:
retrieve_connection_url:
send_email:

- name: Check if email is encoded
id: check_email_encryption
run: |
if [[ "$EMAIL" != *"@"* ]]; then
encoded="true"
else
encoded="false"
fi
echo "encoded=$encoded" >> $GITHUB_OUTPUT
env:
EMAIL: ${{ steps.extract.outputs.email }}

- name: Decode email
id: decode_email
uses: ./.github/actions/encode-decode-string
with:
input_string: ${{ steps.extract.outputs.email }}
encryption_key: ${{ secrets.STRING_ENCRYPTION_KEY }}
operation: "decode"
skip: ${{ steps.check_email_encryption.outputs.encoded == 'false' }}

- name: Send mail (completed)
if: ${{ steps.instance_poll.outputs.status == 'complete' }}
uses: ./.github/actions/send-email
with:
to: ${{ steps.decode_email.outputs.output_string }}
mail_server_username: ${{secrets.MAIL_USERNAME}}
mail_server_password: ${{secrets.MAIL_PASSWORD}}
instance_name: ${{ steps.define.outputs.instance_name }}
instance_issue_number: ${{ github.event.issue.number }}
connection_url: ${{ steps.guacamole.outputs.connection_url }}
instance_ip: ${{ steps.instance_metadata.outputs.instance_ip }}
instance_pwd: ${{ steps.instance_metadata.outputs.instance_pwd }}

- name: comment (progress)
uses: ./.github/actions/comment-progress
with:
comment-id: ${{ steps.couc_progress.outputs.comment-id }}
create_ip:
create_volume:
create_instance:
associate_ip:
setup_instance:
attach_volume:
retrieve_connection_url:
send_email:
Loading

0 comments on commit 9ec533b

Please sign in to comment.