ccp.docs/source/methods_development/02.1_basic_docker_image.md

159 lines
4.8 KiB
Markdown
Raw Normal View History

# Implementation of simple algorithms
Simple algorithms can be implemented using a generic unix docker image, and totally defined in the json script.
Examples of this algorithms are parametric `curl` or `wget` operations on external APIs, shell for file processing, etc
2024-10-10 17:02:03 +02:00
## Default ccpimage for simple algorithms
2024-10-07 19:59:13 +02:00
To implement methods that doesn't need any particular library or configuration, we can leave empty the `ccpimage` value, to use a basic Linux Docker image.
2024-10-10 17:02:03 +02:00
![ccpimage bash](../_static/imgs/methods_development/input_ccpimage_bash.png)
```json
{
"inputs": {
"ccpimage": {
"id": "ccpimage",
"title": "Runtime",
"description": "`bash`, a basic unix docker image.",
"minOccurs": 1,
2024-10-10 17:02:03 +02:00
"maxOccurs": 1,
"schema": {
"type": "string",
"format": "url",
"contentMediaType": "text/plain",
2024-10-07 19:59:13 +02:00
"default": "",
"readOnly": true
}
}
}
}
```
2024-10-10 17:02:03 +02:00
## Execution Parameters
all the parameters and configurations needed for the execution of the algorithms are defined in the inputs section
```json
{
"inputs": {
"baseurl": {
"id": "baseurl",
"title": "Base URL",
"description": "The base URL of the REST API",
"minOccurs": 1,
"maxOccurs": 1,
"schema": {
"type": "string",
"format": "url",
"contentMediaType": "text/plain",
"default": "https://REST_API_URL/process/",
"readOnly": true
}
},
"service": {
"id": "service",
"title": "Service name",
"description": "The name of the service",
"minOccurs": 1,
"maxOccurs": 1,
"schema": {
"type": "string",
"format": null,
"contentMediaType": "text/plain",
"default": "my_custom_service"
}
},
"file": {
"id": "file",
"title": "Input file",
"description": "The input file to be annotated",
"minOccurs": 1,
"maxOccurs": 1,
"schema": {
"type": "string",
"format": "file",
"contentMediaType": "text/plain",
"default": ""
}
},
"contenttype": {
"id": "contenttype",
"title": "Content type",
"description": "The content type of the input file",
"minOccurs": 1,
"maxOccurs": 1,
"schema": {
"type": "string",
"format": null,
"contentMediaType": "text/plain",
"default": "text/plain",
"enum": [
"text/plain",
"application/pdf",
"text/html"
]
}
},
"credentials": {
"id": "credentials",
"title": "Credentials",
"description": "The Basic auth credentials",
"minOccurs": 1,
"maxOccurs": 1,
"schema": {
"type": "string",
"format": "secret",
"contentMediaType": "text/plain",
"default": "XXXYYYZZZ"
}
}
}
}
```
the "readOnly": true/false parameter defines what is binded in the definiton of the ccp method (readonly=true, only the `baseurl` input in the given example)
and what is parametric (readonly=false, or not defined in the input schema)
the given example uses special input parameters that will be explained in next sections
2024-10-10 17:02:03 +02:00
* [credentials](./03_5_credentials.md)
2024-10-07 19:59:13 +02:00
2024-10-10 17:02:03 +02:00
![secret input credentials](../_static/imgs/methods_development/input_secret_credentials.png)
2024-10-07 19:59:13 +02:00
2024-10-10 17:02:03 +02:00
* [file upload](./03_1_input_file.md
2024-10-10 17:02:03 +02:00
![input file](../_static/imgs/methods_development/input_file.png)
2024-10-07 19:59:13 +02:00
2024-10-10 17:02:03 +02:00
## Execution
the implementation of the algorithms is totally defined in the deploy-script and in the execute-script
```json
{
"additionalParameters": {
"parameters": [
{
"name": "deploy-script",
"value": [
"echo {{file}} | base64 -d > /ccp_data/input"
]
},
{
"name": "execute-script",
"value": [
"wget {{baseurl}}/{{service}}?annotations={{annotations}} --post-file /ccp_data/input --header \"Authorization: Basic {{credentials}}\" --header \"Content-Type: {{contenttype}}\" --header \"Accept: application/json\" -O /ccp_data/annotated.json"
]
},
{
"name": "undeploy-script",
"value": []
}
]
}
}
```
2024-10-07 19:59:13 +02:00
example: [bash example ](../methods_examples/Bash%20Example-1.0.0.json)