App Development
With the App SDK Platform, we want to make deploying an app simple. This is why we have made creating Datastore tables, Functions, and Triggers configuration-driven using
serverless.yml
.DroneDeploy App SDK consists of four components:
- Functions: Serverless architecture running on the DroneDeploy Platform. Write Node.js code to enable backend functionality.
Deploying these components separately can be a pain, thus we've created a CLI for managing Apps and their deployments.
You will find instructions on how all of these pieces fit together below.
This is what the directory structure of your DroneDeploy App might look like. You can see an actual example with our IFTTT sample app.
├── app
│ ├── css
│ │ └── styles.css
│ ├── index.html
│ └── js
│ └── script.js
├── functions
│ └── webhook
│ ├── config.json
│ ├── dronedeploy.js
│ ├── handler.js
│ └── package.json
├── package.json
└── serverless.yml
Note that at the top level we have an
app
directory. This directory is where your frontend UI code will live. You will find your HTML, Javascript, CSS here. Note that if you have multiple UIs in different App Zones, you many want to have subdirectories for each App Zone.The functions directory is where you put all of your DroneDeploy Functions. Note that you can have multiple Functions per App; however, we recommend that you use one Function with multiple routes to handle multiple actions.
The
package.json
file is where you define your NPM dependencies.It is important to have the
"main"
field be dronedeploy.js
as that is how the platform knows which file to run.{
"name": "ifttt",
"version": "0.1.0",
"main": "dronedeploy.js",
"author": "dronedeploy",
"devDependencies": {
"@dronedeploy/dronedeploy-cli": "2.1.0"
}
}
You will also need to make sure that your have the dronedeploy-cli installed as a development dependency to be able to deploy correctly using the CLI. If you do not already have the CLI defined as a dependency in
package.json
, you can install it by running the following command. $ npm install --save-dev @dronedeploy/dronedeploy-cli
The serverless.yml file is the blueprint to your App. This file is where you will define Datastore tables, Triggers, and your Functions. This is the entrypoint for the DroneDeploy CLI to understand what you want to do with your App. The next section will talk in depth about the serverless.yml file.
The
dronedeploy-cli
is built using the Serverless framework. The serverless framework uses the serverless.yml
file for configuration.service: IFTTT
provider:
name: dronedeploy
app: # APP ID GOES HERE
plugins:
- "@dronedeploy/dronedeploy-cli"
functions:
ifttt-webhook:
handlerPath: functions/webhook
handler: dronedeploy
memory: 128
events:
-trigger
object-type: Export
type: complete
resources:
tables:
webhook-table:
description: "stores endpoint for IFTTT webhook"
columns:
- name: endpoint
type: Text
encrypted: false
length: 255
description: "webhook endpoint for IFTTT"
service should be set to a reasonable name for your app.
provider should always be
dronedeploy
since you are deploying your serverless functions on the DroneDeploy Platform.app is where you put the App Id of your DroneDeploy App. You can find your App Id by navigating to the App description page on the DroneDeploy App Market.
plugins should always be set to
@dronedeploy/dronedeploy-cli
. This lets the serverless framework know to use the dronedeploy-cli
as the plugin.functions is where you define your functions.
- The key is used as the name of the function. In the example above, the name is
ifttt-webhook
. - The
handlerPath
lets the CLI know where to find your function files. - The
handler
defines the module to run in yourdronedeploy.js
function file. Typically this field should stay asdronedeploy
. - Under events you can define your DroneDeploy Triggers. You can learn more about Triggers here. Note that you can have more than one Trigger defined.
- Finally you can define Datastore Tables under
resources
. Each table can have multiple columns. You can learn more about Datastore tables here.
With the DroneDeploy CLI, you can deploy your Functions, Datastore tables, and Triggers with one command:
$ serverless deploy
Once you run
serverless deploy
, your app is now ready for use.Once your Function has been deployed, you can check its status by running:
$ sls status
cd
into your actual function folder $ npm install @google-cloud/functions-framework
$ npm install
Add a start script to
package.json
, with configuration passed via command-line arguments: "scripts": {
"start": "functions-framework --target=dronedeploy"
}
Note that your
package.json
will look something like below. Note the main
and scripts
fields, they indicate the entry file and point for your function. {
"name": "ifttt-webhook",
"version": "0.1.0",
"description": "",
"main": "dronedeploy.js",
"author": "dronedeploy",
"license": "MIT",
"dependencies": {
"@dronedeploy/function-wrapper": "1.3.2",
"@google-cloud/functions-framework": "^3.1.3",
"dotenv": "16.0.3"
},
"scripts": {
"start": "functions-framework --target=dronedeploy"
}
}
Next, run the following:
$ npm start
...
Serving function...
Function: dronedeploy
URL: http://localhost:8080/
You should be able to send requests to this function using curl from another terminal window. Note that you can generate an authentication token from the CLI which you can pass in as a bearer token to authenticate your function request.
$ sls getAuth
Once your Function is up and running, you can check its logs with the following command:
$ sls logs --functionName ifttt-webhook --tail
You can find all CLI commands by running the following:
$ sls help
Last modified 8mo ago