Deploying a CDK connector via API
Overview
You can deploy connectors built through CDK using the Connector Deployment API. You can configure your CI/CD pipeline to use this API to deploy connectors on Tray.io platform.
Prerequisites - API token
In order to deploy a connector, you will need an RBAC (Role Based Access Control) API token, you can follow this guide on how to create one.
After deploying a connector using an API token, your connector will be owned by that token. This means you will need to use that same token to share that connector with yourself and any other users you want to issue access to.
The command to do this is tray-cdk permissions add
. Check the reference here.
Deploying to different regions
Tray operates in 3 regions, US, EU and APAC. You will need to call the deployment API, using the region specific base URL and RBAC token, for each region you wish to use the connector in.
Step by step guide
info
Most linux/mac systems come pre-installed with the required commands zip
, base64
and curl
.
1. Delete node_modules
cd into your connector directory and delete the node_modules/ directory
cd my-connector
rm -rf node_modules/
cd ../
2. Zip the connector
zip -r my-connector.zip my-connector/
3. base64 encode the connector zip
Use the command below to get a base64 encoded string that you will use as the payload in the curl request in the next step
base64 -i my-connector.zip
4. POST to the deployment URL
Make a curl POST request to the deployment URL:
https://api.tray.io/cdk/v1/deployments/${connector-name}/versions/${connector-version}/deploy-connector-from-source
including your the connector name and version in the path, the Tray API token in the headers, and the base64 encoded string in the JSON payload:
curl --location 'https://api.tray.io/cdk/v1/deployments/my-connector/versions/1.0/deploy-connector-from-source' \
--header 'Authorization: Bearer <your-tray-api-token>' \
--header 'Content-Type: application/json' \
--data '{
"connectorSourceCode": "<base64-encoded-zip-file-string>"
}'
In the above code block, connector-name is my-connector
and connector-version is 1.0
.
Once your connector code has passed preliminary validation you should recieve a 200 response with a body similar to the one below, this means your connector is now deploying.
{
"id": "3c5e4a2d-ad3a-58e9-8e2d-eff986f62387",
"connectorName": "my-connector",
"connectorVersion": "1.0",
"deploymentStatus": "Deploying"
}
If you instead recieved a body that also includes "repeatDeployment": true
this means a deployment for the same connector is already in progress. Once your current deployment has completed you will be able to deploy again.
{
"id": "3c5e4a2d-ad3a-58e9-8e2d-eff986f62387",
"connectorName": "my-connector",
"connectorVersion": "1.0",
"deploymentStatus": "Deploying",
"repeatDeployment": true
}
5. Check deployment status
You can check the status of the ongoing deployment by polling the following GET request, including your Tray API token, the connector name, version and deployment ID (which you get in the response after calling the deployment API like in the above step)
curl --location 'https://api.tray.io/cdk/v1/deployments/connectors/my-connector/versions/1.0/3c5e4a2d-ad3a-58e9-8e2d-eff986f62387' \
--header 'Authorization: Bearer <your-tray-api-token>' \
--header 'Content-Type: application/json'
You should expect a response similar to the one below with "deploymentStatus": "Deploying"
if your connector is currently deploying:
{
"id": "3c5e4a2d-ad3a-58e9-8e2d-eff986f62387",
"connectorName": "my-connector",
"connectorVersion": "1.0",
"deploymentStatus": "Deploying"
}
Or you will recieve a "deploymentStatus": "Deployed"
if it has finished deploying:
{
"id": "3c5e4a2d-ad3a-58e9-8e2d-eff986f62387",
"connectorName": "my-connector",
"connectorVersion": "1.0",
"deploymentStatus": "Deployed"
}