feat(action): ✨ Initial commit
This commit is contained in:
commit
ef7745c020
2 changed files with 133 additions and 0 deletions
133
deploy/action.yml
Normal file
133
deploy/action.yml
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
name: 'Deploy to Edge Connect'
|
||||
author: 'IPCEI'
|
||||
description: |
|
||||
Deploys something to Edge Connect.
|
||||
|
||||
inputs:
|
||||
region:
|
||||
description: "Application Region e.g. EU"
|
||||
default: EU
|
||||
required: true
|
||||
flavor:
|
||||
description: "Application Flavor e.g. EU.small"
|
||||
default: EU.small
|
||||
required: true
|
||||
cloudlet:
|
||||
description: "Cloudlet locations: Amsterdam-OTC, Hamburg, Leipzig, Munich, Berlin, Frankfurt, Magdeburg-OTC, Bonn, Magdeburg"
|
||||
default: Munich
|
||||
required: true
|
||||
edgexr_platform_username:
|
||||
description: "EdgeXr Platform Username"
|
||||
required: true
|
||||
edgexr_platform_password:
|
||||
description: "EdgeXr Platform Password"
|
||||
required: true
|
||||
edge_url:
|
||||
description: "EdgeXr Platform URL"
|
||||
default: "hub.apps.edge.platform.mg3.mdb.osc.live"
|
||||
required: false
|
||||
|
||||
outputs:
|
||||
url:
|
||||
description: 'The url of the deployed application'
|
||||
value: ${{ steps.createappinstance.outputs.url }}
|
||||
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
- name: Repository meta
|
||||
id: repository
|
||||
shell: bash
|
||||
run: |
|
||||
registry=${{ github.server_url }}
|
||||
registry=${registry##http*://}
|
||||
echo "registry=${registry}" >> "$GITHUB_OUTPUT"
|
||||
echo "registry=${registry}"
|
||||
repository="$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')"
|
||||
echo "repository=${repository}" >> "$GITHUB_OUTPUT"
|
||||
echo "repository=${repository}"
|
||||
- name: Docker meta
|
||||
uses: docker/metadata-action@v5
|
||||
id: docker
|
||||
with:
|
||||
images: ${{ steps.repository.outputs.registry }}/${{ steps.repository.outputs.repository }}
|
||||
- name: Install Dependencies
|
||||
shell: bash
|
||||
run: |
|
||||
sudo apt update
|
||||
sudo apt install -y curl jq
|
||||
-
|
||||
name: Create Edge Connect App
|
||||
shell: bash
|
||||
run: |
|
||||
set -e
|
||||
echo login
|
||||
EDGEXR_TOKEN="$(curl -X POST https://${{ inputs.edge_url }}/api/v1/login -H 'Content-Type: application/json' --data '{"password": "'${{ inputs.edgexr_platform_password }}'","username": "'${{ inputs.edgexr_platform_username }}'"}' -sSf | jq -r .token)"
|
||||
|
||||
CREATEAPP_JSON=$(cat <<EOF
|
||||
{
|
||||
"region": "${{ inputs.region }}",
|
||||
"app": {
|
||||
"key": {
|
||||
"organization": "dev-framework",
|
||||
"name": "$(echo ${{ steps.repository.outputs.repository }} | sed -e 's|^.*/||')",
|
||||
"version": "${{ steps.docker.outputs.version }}"
|
||||
},
|
||||
"deployment": "kubernetes",
|
||||
"image_type": "Docker",
|
||||
"image_path": "${{ steps.repository.outputs.registry }}/${{ steps.repository.outputs.repository }}:${{ steps.docker.outputs.version }}",
|
||||
"allow_serverless": true,
|
||||
"defaultFlavor": {
|
||||
"name": "${{ inputs.flavor }}"
|
||||
},
|
||||
"serverless_config": {},
|
||||
"deployment_generator": "kubernetes-basic",
|
||||
"deployment_manifest": "apiVersion: v1\nkind: Service\nmetadata:\n name: $(echo ${{ steps.repository.outputs.repository }} | sed -e 's|^.*/||')-tcp\n labels:\n run: $(echo ${{ steps.repository.outputs.repository }} | sed -e 's|^.*/||')\nspec:\n type: LoadBalancer\n ports:\n - name: tcp80\n protocol: TCP\n port: 80\n targetPort: 80\n selector:\n run: $(echo ${{ steps.repository.outputs.repository }} | sed -e 's|^.*/||')\n---\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: $(echo ${{ steps.repository.outputs.repository }} | sed -e 's|^.*/||')-deployment\nspec:\n replicas: 1\n selector:\n matchLabels:\n run: $(echo ${{ steps.repository.outputs.repository }} | sed -e 's|^.*/||')\n template:\n metadata:\n labels:\n run: $(echo ${{ steps.repository.outputs.repository }} | sed -e 's|^.*/||')\n mexDeployGen: kubernetes-basic\n spec:\n volumes:\n containers:\n - name: $(echo ${{ steps.repository.outputs.repository }} | sed -e 's|^.*/||')\n image: ${{ steps.repository.outputs.registry }}/${{ steps.repository.outputs.repository }}:${{ steps.docker.outputs.version }}\n imagePullPolicy: Always\n ports:\n - containerPort: 80\n protocol: TCP\n\n"
|
||||
}
|
||||
}
|
||||
EOF
|
||||
)
|
||||
|
||||
echo $CREATEAPP_JSON
|
||||
|
||||
echo requesting app creation...
|
||||
curl -X POST https://${{ inputs.edge_url }}/api/v1/auth/ctrl/CreateApp -H 'Content-Type: application/json' -H "Authorization: Bearer $EDGEXR_TOKEN" -S --data "$CREATEAPP_JSON" --fail-with-body
|
||||
- name: Create Edge Connect App Instance
|
||||
id: createappinstance
|
||||
shell: bash
|
||||
run: |
|
||||
set -e
|
||||
EDGEXR_TOKEN="$(curl -X POST https://${{ inputs.edge_url }}/api/v1/login -H 'Content-Type: application/json' --data '{"password": "'${{ inputs.edgexr_platform_password }}'","username": "'${{ inputs.edgexr_platform_username }}'"}' -sSf | jq -r .token)"
|
||||
|
||||
CREATEAPPINSTANCE_JSON=$(cat <<EOF
|
||||
{
|
||||
"region": "${{ inputs.region }}",
|
||||
"appinst": {
|
||||
"key": {
|
||||
"organization": "dev-framework",
|
||||
"name": "$(echo ${{ steps.repository.outputs.repository }} | sed -e 's|^.*/||')-instance",
|
||||
"cloudlet_key": {
|
||||
"organization": "TelekomOP",
|
||||
"name": "${{ inputs.cloudlet }}"
|
||||
}
|
||||
},
|
||||
"app_key": {
|
||||
"organization": "dev-framework",
|
||||
"name": "$(echo ${{ steps.repository.outputs.repository }} | sed -e 's|^.*/||')",
|
||||
"version": "${{ steps.docker.outputs.version }}"
|
||||
},
|
||||
"flavor": {
|
||||
"name": "${{ inputs.flavor }}"
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
)
|
||||
|
||||
echo $CREATEAPPINSTANCE_JSON
|
||||
|
||||
echo requesting app instance creation...
|
||||
RESPONSE="$(curl -X POST https://${{ inputs.edge_url }}/api/v1/auth/ctrl/CreateAppInst -H 'Content-Type: application/json' -H "Authorization: Bearer $EDGEXR_TOKEN" -S --data "$CREATEAPPINSTANCE_JSON" --fail-with-body)"
|
||||
|
||||
echo $RESPONSE
|
||||
echo "url=$(echo $RESPONSE | jq -r '.data.message | match("https[^ ]*") | .string' >> "$GITHUB_OUTPUT")"
|
||||
0
destroy/action.yml
Normal file
0
destroy/action.yml
Normal file
Reference in a new issue