-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support FaaS[Noy fully automated yet] (#10)
* refactor: remove call keyword from the command in the yaml * faas working with no ci yet * Fix the pipeline and create the deploy script * Update requirements.txt --------- Co-authored-by: Vicente Eduardo Ferrer Garcia <[email protected]>
- Loading branch information
1 parent
60cb260
commit 7c0c130
Showing
14 changed files
with
169 additions
and
76 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/bin/bash | ||
|
||
# Accept the repo path as an argument | ||
repo_path=$1 | ||
|
||
# Run the metacall-deploy command and store the output | ||
output=$(metacall-deploy --inspect OpenAPIv3 --dev --workdir "$repo_path") | ||
|
||
# Parse the JSON output using jq to extract the server URL and paths | ||
server_url=$(echo "$output" | jq -r '.[0].servers[0].url') | ||
paths=$(echo "$output" | jq -r '.[0].paths | keys[]') | ||
|
||
# Output the server URL and paths | ||
echo "Server URL: $server_url" | ||
echo "Available Paths:" | ||
for path in $paths; do | ||
echo "$server_url$path" | ||
done | ||
|
||
# Set the server URL as an environment variable | ||
export SERVER_URL=$server_url | ||
|
||
|
||
# multi line comment | ||
: ' Exmaple output | ||
[ | ||
{ | ||
"openapi": "3.0.0", | ||
"info": { | ||
"title": "MetaCall Cloud FaaS deployment 'time-app-web'", | ||
"description": "", | ||
"version": "v1" | ||
}, | ||
"servers": [ | ||
{ | ||
"url": "http://localhost:9000/aa759149a70a/time-app-web/v1", | ||
"description": "MetaCall Cloud FaaS" | ||
} | ||
], | ||
"paths": { | ||
"/call/time": { | ||
"get": { | ||
"summary": "", | ||
"description": "", | ||
"responses": { | ||
"200": { | ||
"description": "", | ||
"content": { | ||
"application/json": { | ||
"schema": {} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"/call/index": { | ||
"get": { | ||
"summary": "", | ||
"description": "", | ||
"responses": { | ||
"200": { | ||
"description": "", | ||
"content": { | ||
"application/json": { | ||
"schema": {} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
] | ||
' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
PyYAML==6.0.1 | ||
config==0.5.1 | ||
metacall==0.5.0 | ||
PyYAML==6.0.2 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,60 @@ | ||
import json | ||
import subprocess | ||
|
||
import os | ||
|
||
from testing.runner.runner_interface import RunnerInterface | ||
|
||
|
||
class FaaSInterface(RunnerInterface): | ||
def __init__(self): | ||
pass | ||
try: | ||
# Get the base URL from the environment variable SERVER_URL | ||
self.base_url = os.environ['SERVER_URL'] | ||
except KeyError: | ||
# If the environment variable is not set, return an error | ||
raise KeyError("SERVER_URL environment variable not set, make sure to run 'source ./deploy.sh /path/to/repo' before running the tests") | ||
|
||
def get_name(self): | ||
return "faas" | ||
|
||
def get_request(self, url): | ||
command = f"curl {url} -X GET" | ||
return command | ||
|
||
def post_request(self, url, params): | ||
try: | ||
params = json.loads(params) | ||
except json.JSONDecodeError: | ||
pass | ||
|
||
data = json.dumps(params) if isinstance(params, dict) else params | ||
command = f"curl {url} -X POST --data '{data}'" | ||
return command | ||
|
||
|
||
def parse_function_call(self, function_call): | ||
if '(' in function_call and ')' in function_call: | ||
function_name = function_call.split('(')[0] | ||
params = function_call.split('(')[1].split(')')[0] | ||
params = params if params else None | ||
else: | ||
function_name = function_call | ||
params = None | ||
|
||
return function_name, params | ||
|
||
def run_test_command(self, file_path, function_call): | ||
function_name, params = self.parse_function_call(function_call) | ||
url = f"{self.base_url}/call/{function_name}" | ||
|
||
if params: | ||
command = self.post_request(url, params) | ||
else: | ||
command = self.get_request(url) | ||
print("Command:", command) | ||
|
||
result = subprocess.run(command, capture_output=True, text=True, shell=True, check=False) | ||
out_str = result.stdout.strip() | ||
|
||
def run_test_command(self, file_path, test_case_command): | ||
# Implement the FaaS call here | ||
# For now, return a placeholder string | ||
return "FaaS output placeholder" | ||
return out_str |
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
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
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