mirror of https://github.com/apibillme/broker
Snap (#5)
This commit is contained in:
parent
ee569abc74
commit
152f79f677
|
@ -9,8 +9,7 @@ tmp
|
|||
parts/
|
||||
prime/
|
||||
stage/
|
||||
*.snap
|
||||
*.xdelta3
|
||||
*.snap*
|
||||
|
||||
# Snapcraft global state tracking data(automatically generated)
|
||||
# https://forum.snapcraft.io/t/location-to-save-global-state/768
|
||||
|
|
|
@ -399,7 +399,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "broker"
|
||||
version = "1.3.1"
|
||||
version = "1.4.0"
|
||||
dependencies = [
|
||||
"actix-cors 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"actix-rt 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -410,6 +410,7 @@ dependencies = [
|
|||
"env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"envy 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"go-flag 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"json 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"jsonwebtoken 6.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"reqwest 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -789,6 +790,14 @@ dependencies = [
|
|||
"wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "go-flag"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "h2"
|
||||
version = "0.2.1"
|
||||
|
@ -2096,6 +2105,7 @@ dependencies = [
|
|||
"checksum fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
|
||||
"checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec"
|
||||
"checksum getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb"
|
||||
"checksum go-flag 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6b4a40c9ca507513f573aabaf6a8558173a1ac9aa1363d8de30c7f89b34f8d2b"
|
||||
"checksum h2 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b9433d71e471c1736fd5a61b671fc0b148d7a2992f666c958d03cd8feb3b88d1"
|
||||
"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
|
||||
"checksum hermit-abi 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "eff2656d88f158ce120947499e971d743c05dbcbed62e5bd2f38f1698bbc3772"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "broker"
|
||||
version = "1.3.1"
|
||||
version = "1.4.0"
|
||||
authors = ["Bevan Hunt <bevan@bevanhunt.com>"]
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
|
@ -22,10 +22,11 @@ serde_json = "1"
|
|||
serde_derive = "1"
|
||||
json = "0.12"
|
||||
sled = "0.30"
|
||||
envy = "0.4"
|
||||
env_logger = "0.6"
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
uuid = { version = "0.8", features = ["serde", "v4"] }
|
||||
bcrypt = "0.6"
|
||||
jsonwebtoken = "6"
|
||||
reqwest = { version = "0.10", features = ["json", "blocking"] }
|
||||
go-flag = "0.1"
|
||||
envy = "0.4"
|
||||
|
|
8
Makefile
8
Makefile
|
@ -1,10 +1,12 @@
|
|||
run:
|
||||
PORT=8080 SAVE_PATH=./tmp ORIGIN=http://localhost:3000 EXPIRY=3600 SECRET=secret cargo run
|
||||
release:
|
||||
PORT=8080 SAVE_PATH=./tmp ORIGIN=http://localhost:3000 EXPIRY=3600 SECRET=secret cargo run --release
|
||||
SAVE_PATH=./tmp/broker_data cargo run
|
||||
build:
|
||||
sudo snapcraft
|
||||
edge:
|
||||
sudo snapcraft push --release edge *.snap
|
||||
publish:
|
||||
sudo snapcraft push --release stable *.snap
|
||||
cover:
|
||||
cargo tarpaulin
|
||||
purge:
|
||||
sudo multipass delete snapcraft-broker && sudo multipass purge
|
||||
|
|
18
README.md
18
README.md
|
@ -3,6 +3,7 @@
|
|||
[![crates.io](https://meritbadge.herokuapp.com/broker)](https://crates.io/crates/broker)
|
||||
[![Build Status](https://travis-ci.org/apibillme/broker.svg?branch=master)](https://travis-ci.org/apibillme/broker)
|
||||
[![codecov](https://codecov.io/gh/apibillme/broker/branch/master/graph/badge.svg)](https://codecov.io/gh/apibillme/broker)
|
||||
[![broker](https://snapcraft.io//broker/badge.svg)](https://snapcraft.io/broker)
|
||||
|
||||
### Purpose
|
||||
|
||||
|
@ -149,12 +150,17 @@ async fn main() -> std::result::Result<(), std::io::Error> {
|
|||
broker_run().await
|
||||
}
|
||||
```
|
||||
- the ORIGIN (CORS) needs to be passed in as an environment variable - wildcard is not supported
|
||||
- the PORT needs to be passed in as an environment variable
|
||||
- the EXPIRY (for jwts) needs to be passed in as an environment variable
|
||||
- the SECRET (for jwts) needs to be passed in as an environment variable
|
||||
- the SAVE_PATH where the embedded database will save needs to be passed in as an environment variable
|
||||
- example: PORT=8080 SAVE_PATH=./tmp ORIGIN=http://localhost:3000 EXPIRY=3600 SECRET=secret broker
|
||||
- the origin (CORS) needs to be passed in as a flag with wildcard not supported
|
||||
- the port needs to be passed in as a flag
|
||||
- the expiry (for jwts) needs to be passed in as a flag
|
||||
- the secret (for jwts) needs to be passed in as a flag
|
||||
- the save_path where the embedded database will save needs to be passed in as an environment variable (not for snap)
|
||||
- example: SAVE_PATH=./tmp/broker_data broker -port 8080 -origin http://localhost:3000 -expiry 3600 -secret secret
|
||||
|
||||
## Install (Linux)
|
||||
``` sudo snap install broker ```
|
||||
- does not run as a daemon as requires flags
|
||||
- the snap saves the database in $HOME/broker_data - this cannot be changed
|
||||
|
||||
### Run Example
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: broker # you probably want to 'snapcraft register <name>'
|
||||
base: core18 # the base snap is the execution environment for this snap
|
||||
version: '1.3.1' # just for humans, typically '1.2+git' or '1.3.2'
|
||||
version: '1.4.0' # just for humans, typically '1.2+git' or '1.3.2'
|
||||
summary: Real-time Zero-Code API Server # 79 char long summary
|
||||
description: |
|
||||
The purpose of this library is to be your real-time zero-code API server.
|
||||
|
@ -15,8 +15,10 @@ parts:
|
|||
broker:
|
||||
plugin: rust
|
||||
source: .
|
||||
|
||||
build-packages:
|
||||
- libssl-dev
|
||||
- pkg-config
|
||||
apps:
|
||||
broker:
|
||||
command: env PATH=$SNAP/bin:$PATH SAVE_PATH=$HOME/.broker/data broker
|
||||
plugs: [home, network]
|
||||
command: env PATH=$SNAP/bin:$PATH SAVE_PATH=$HOME/broker_data broker
|
||||
plugs: [home, network, network-bind]
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
extern crate metadeps;
|
||||
|
||||
fn main() {
|
||||
metadeps::probe().unwrap();
|
||||
}
|
21
src/lib.rs
21
src/lib.rs
|
@ -20,6 +20,11 @@ pub struct Config {
|
|||
pub save_path: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
pub struct Cfg {
|
||||
pub save_path: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct MyData {
|
||||
db: sled::Db,
|
||||
|
@ -395,9 +400,23 @@ async fn login(data: web::Data<MyData>, json: web::Json<Login>) -> Result<HttpRe
|
|||
|
||||
#[cfg_attr(tarpaulin, skip)]
|
||||
pub async fn broker_run() -> Result<(), std::io::Error> {
|
||||
let config = envy::from_env::<Config>().unwrap();
|
||||
let mut port = "8080".to_owned();
|
||||
let mut expiry : i64 = 3600;
|
||||
let mut origin = "http://localhost:3000".to_owned();
|
||||
let mut secret = "secret".to_owned();
|
||||
let _ : Vec<String> = go_flag::parse(|flags| {
|
||||
flags.add_flag("port", &mut port);
|
||||
flags.add_flag("expiry", &mut expiry);
|
||||
flags.add_flag("origin", &mut origin);
|
||||
flags.add_flag("secret", &mut secret);
|
||||
});
|
||||
|
||||
std::env::set_var("RUST_LOG", "actix_web=debug,actix_server=info");
|
||||
env_logger::init();
|
||||
|
||||
let cfg = envy::from_env::<Cfg>().unwrap();
|
||||
|
||||
let config = Config{port: port, origin: origin, secret: secret, save_path: cfg.save_path, expiry: expiry};
|
||||
server_create(config).await
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue