Skip to content

Commit

Permalink
feat: deploy heroku
Browse files Browse the repository at this point in the history
  • Loading branch information
amerelo committed Jun 30, 2021
1 parent 20a213b commit 695dad3
Show file tree
Hide file tree
Showing 78 changed files with 2,059 additions and 1,227 deletions.
265 changes: 251 additions & 14 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: ENGINE_SERVER_PORT=$PORT ./csml-server-linux-amd64
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ To get started with CSML Studio: https://studio.csml.dev
CSML Studio gives you a free playground to experiment with the language as well as options to deploy your chatbots at scale in one-click.
## Self-hosted / local installation
## Self-hosted / cloud / local installation
CSML is available as a self-hostable web server that you can easily install with one of the options below.
Expand Down Expand Up @@ -118,6 +118,12 @@ DISABLE_SSL_VERIFY=false
DEBUG=true
```
### Deploy on Heroku
<a href="https://heroku.com/deploy?template=https://github.com/CSML-by-Clevy/csml-engine/tree/masters">
<img src="https://www.herokucdn.com/deploy/button.svg" alt="Deploy">
</a>
### Using a ready-to-use binary (Linux and MacOS only)
The easiest way to launch a CSML Engine on your own machine is to use one of our pre-built, optimized binaries (available for both MongoDB and Amazon DynamoDB). These binaries are available as executables on each of CSML's releases since v1.3.0.
Expand Down
47 changes: 47 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "CSML application",
"description": "",
"repository": "https://github.com/CSML-by-Clevy/csml-engine/tree/feat/deploy-to-heroku",
"success_url": "/",
"keywords": ["rust", "csml"],
"website": "https://www.csml.dev/",
"env": {
"ENGINE_DB_TYPE": {
"value": "mongodb",
"required": true
},
"MONGODB_DATABASE": "csml",

"MONGODB_HOST": {
"value": "localhost",
"required": false
},
"MONGODB_PORT": {
"value": "27017",
"required": false
},
"MONGODB_DATABASE": {
"value": "csml",
"required": false
},
"MONGODB_USERNAME": {
"required": false
},
"MONGODB_PASSWORD": {
"required": false
},

"MONGODB_URI": {
"required": false
},

"ENCRYPTION_SECRET": {
"required": false
}
},
"buildpacks": [
{
"url": "https://github.com/CSML-by-Clevy/heroku-buildpack-csml"
}
]
}
16 changes: 9 additions & 7 deletions csml_engine/CSML/flow.csml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ fn add(var1, var2):
return 56

start:
say val
remember val = "42"
say "start"
if (!test) {
say "create test"
remember test = 1
} else {
do test = test + 1
}

remember toto = "tataaa"
hold

goto end
// goto toto
// goto end
goto @flow2

toto:
do vec = [1, 2]
Expand Down
11 changes: 9 additions & 2 deletions csml_engine/CSML/flow2.csml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@ fn pow(var, exp):

start:
say "flow 2 -> {{test}}"
say Button("end", hola = "hola")
goto end
// say Button("end", hola = "hola")
goto toto

toto:
hold
if (test < 2) {
previous flow
}
goto end
14 changes: 12 additions & 2 deletions csml_engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ edition = "2018"

[features]
mongo = ["mongodb", "bson", "futures"]
dynamo = ["rusoto_core", "rusoto_dynamodb", "rusoto_s3", "serde_dynamodb"]
dynamo = ["rusoto_core", "rusoto_dynamodb", "rusoto_s3", "serde_dynamodb", "log", "env_logger"]

[dependencies.mongodb]
version = "1.2.1"
Expand Down Expand Up @@ -60,6 +60,16 @@ default_features = false
features = ["rustls"]
optional = true

[dependencies.log]
version = "0.4.0"
default_features = false
optional = true

[dependencies.env_logger]
version = "0.8.4"
default_features = false
optional = true

[dependencies]
csml_interpreter = { version = "1.6.3", path = "../csml_interpreter" }
multimap = "0.8.2"
Expand All @@ -72,9 +82,9 @@ serde_json = "1.0.64"
openssl = { version = "0.10.31", features = ["vendored"] }
base64 = "0.13.0"
hex = "0.4.2"
curl = { version = "0.4.34", default-features = false, features = ["mesalink"] }
tokio = "1.4.0"

curl = { version = "0.4.34", default-features = false, features = ["mesalink"] }
bincode = "1.3.1"

[[example]]
Expand Down
6 changes: 6 additions & 0 deletions csml_engine/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ use serde_json::Value;
pub const DEBUG: &str = "DEBUG";
pub const DISABLE_SSL_VERIFY: &str = "DISABLE_SSL_VERIFY";

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct FlowTrigger {
pub flow_id: String,
pub step_id: Option<String>
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct RunRequest {
pub bot: Option<CsmlBot>,
Expand Down
21 changes: 18 additions & 3 deletions csml_engine/src/db_connectors/dynamodb/bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ fn query_bot_version(
};

let query = db.client.query(input);
let data = db.runtime.block_on(query)?;
let data = match db.runtime.block_on(query) {
Ok(data) => data,
Err(e) => {
return Err(EngineError::Manager(format!("query_bot_version {:?}", e)))
}
};

Ok(data)
}
Expand Down Expand Up @@ -252,7 +257,12 @@ pub fn get_last_bot_version(
};

let query = db.client.query(input);
let data = db.runtime.block_on(query)?;
let data = match db.runtime.block_on(query) {
Ok(data) => data,
Err(e) => {
return Err(EngineError::Manager(format!("get_last_bot_version {:?}", e)))
}
};

// The query returns an array of items (max 1, based on the limit param above).
// If 0 item is returned it means that there is no open conversation, so simply return None
Expand Down Expand Up @@ -417,7 +427,12 @@ fn query_bot_info(
};

let future = db.client.query(input);
let data = db.runtime.block_on(future)?;
let data = match db.runtime.block_on(future) {
Ok(data) => data,
Err(e) => {
return Err(EngineError::Manager(format!("query_bot_info {:?}", e)))
}
};

Ok(data)
}
Expand Down
36 changes: 28 additions & 8 deletions csml_engine/src/db_connectors/dynamodb/conversations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub fn create_conversation(
let future = client.put_item(input);

db.runtime.block_on(future)?;

Ok(data.id.to_owned())
}

Expand Down Expand Up @@ -176,7 +177,12 @@ fn get_all_open_conversations(
};

let query = db.client.query(input);
let data = db.runtime.block_on(query)?;
let data = match db.runtime.block_on(query) {
Ok(data) => data,
Err(e) => {
return Err(EngineError::Manager(format!("get_all_open_conversations {:?}", e)))
}
};

let keys = match data.items {
Some(items) => items
Expand Down Expand Up @@ -259,7 +265,13 @@ pub fn get_latest_open(
};

let query = db.client.query(input);
let data = db.runtime.block_on(query)?;
let data = match db.runtime.block_on(query) {
Ok(data) => data,
Err(e) => {
return Err(EngineError::Manager(format!("get_latest_open {:?}", e)))
}
};


// The query returns an array of items (max 1, based on the limit param above).
// If 0 item is returned it means that there is no open conversation, so simply return None
Expand Down Expand Up @@ -295,7 +307,7 @@ pub fn update_conversation(

// make sure that if the item does not already exist, it is NOT created automatically
let condition_expr = "#hashKey = :hashVal AND #rangeKey = :rangeVal".to_string();
let expr_attr_names = [
let expr_attr_names: HashMap<String, String> = [
("#hashKey".to_string(), "hash".to_string()),
("#rangeKey".to_string(), "range".to_string()),
]
Expand Down Expand Up @@ -369,9 +381,12 @@ pub fn update_conversation(
};

let future = db.client.update_item(input);
db.runtime.block_on(future)?;

Ok(())
match db.runtime.block_on(future) {
Ok(_) => Ok(()),
Err(e) => {
return Err(EngineError::Manager(format!("update_conversation {:?}", e)))
}
}
}


Expand Down Expand Up @@ -421,7 +436,12 @@ fn query_conversation(
};

let future = db.client.query(input);
let data = db.runtime.block_on(future)?;
let data = match db.runtime.block_on(future) {
Ok(data) => data,
Err(e) => {
return Err(EngineError::Manager(format!("query_conversation {:?}", e)))
}
};

Ok(data)
}
Expand Down Expand Up @@ -519,7 +539,7 @@ pub fn get_client_conversations(
.collect();

let data = query_conversation(
client,
client,
db,
limit,
pagination_key,
Expand Down
21 changes: 18 additions & 3 deletions csml_engine/src/db_connectors/dynamodb/interactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ pub fn init_interaction(
};

let future = db.client.put_item(input);
db.runtime.block_on(future)?;
match db.runtime.block_on(future) {
Ok(_) => {},
Err(e) => {
return Err(EngineError::Manager(format!("init_interaction {:?}", e)))
}
};

Ok(id.to_string())
}
Expand Down Expand Up @@ -126,7 +131,12 @@ pub fn update_interaction(
};

let future = db.client.update_item(input);
db.runtime.block_on(future)?;
match db.runtime.block_on(future) {
Ok(_) => (),
Err(e) => {
return Err(EngineError::Manager(format!("update_interaction {:?}", e)))
}
};

Ok(())
}
Expand Down Expand Up @@ -176,7 +186,12 @@ fn query_interactions(
};

let future = db.client.query(input);
let data = db.runtime.block_on(future)?;
let data = match db.runtime.block_on(future) {
Ok(data) => data,
Err(e) => {
return Err(EngineError::Manager(format!("query_interactions {:?}", e)))
}
};

Ok(data)
}
Expand Down
7 changes: 6 additions & 1 deletion csml_engine/src/db_connectors/dynamodb/memories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ fn query_memories(
};

let future = db.client.query(input);
let data = db.runtime.block_on(future)?;
let data = match db.runtime.block_on(future) {
Ok(data) => data,
Err(e) => {
return Err(EngineError::Manager(format!("query_memories {:?}", e)))
}
};

Ok(data)
}
Expand Down
7 changes: 6 additions & 1 deletion csml_engine/src/db_connectors/dynamodb/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ fn query_messages(
};

let future = db.client.query(input);
let data = db.runtime.block_on(future)?;
let data = match db.runtime.block_on(future) {
Ok(data) => data,
Err(e) => {
return Err(EngineError::Manager(format!("query_messages {:?}", e)))
}
};

Ok(data)
}
Expand Down
14 changes: 12 additions & 2 deletions csml_engine/src/db_connectors/dynamodb/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ pub fn create_node(

let db = get_db(&mut data.db)?;
let future = db.client.put_item(input);
db.runtime.block_on(future)?;
match db.runtime.block_on(future) {
Ok(_) => (),
Err(e) => {
return Err(EngineError::Manager(format!("create_node {:?}", e)))
}
};

Ok(())
}
Expand Down Expand Up @@ -111,7 +116,12 @@ fn query_nodes(
};

let future = db.client.query(input);
let data = db.runtime.block_on(future)?;
let data = match db.runtime.block_on(future) {
Ok(data) => data,
Err(e) => {
return Err(EngineError::Manager(format!("query_nodes {:?}", e)))
}
};

Ok(data)
}
Expand Down
Loading

0 comments on commit 695dad3

Please sign in to comment.