From ff225070e43907e3939c08257c45042265f024a3 Mon Sep 17 00:00:00 2001 From: ayham Date: Fri, 30 Jul 2021 07:04:54 +0300 Subject: [PATCH] add drone ci support --- .drone.yml | 39 ++++++++++++++++++++++++++ README.md | 2 +- scripts/deploy_sandbox_client.sh | 2 +- scripts/deploy_sandbox_server.sh | 2 +- scripts/env.sh | 4 ++- src/libtrader/client/initializer.rs | 19 +++++++++++-- src/libtrader/server/db/initializer.rs | 1 + todo/v1.libtrader.md | 16 +++++++++-- 8 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 .drone.yml diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..4451ccc --- /dev/null +++ b/.drone.yml @@ -0,0 +1,39 @@ +kind: pipeline +name: papertrader + +steps: + - name: database_init + image: postgres + commands: + - sleep 10 + - echo "database:5432:pt_db:pt_usr:PASSWORD" > ~/.pgpass + - chmod 0600 ~/.pgpass + - export DIR="$(pwd)/src/libtrader/server/db/sql" + - for file in $DIR/*; do psql -w -U pt_usr -d pt_db -a -h database -f "$${file}"; done + + - name: server + image: rust + detach: true + commands: + - sleep 15 + - export CI_DEPLOY=1 + - ./scripts/deploy_sandbox_server.sh server:4000 + depends: + - database_init + + - name: client + image: rust + commands: + - sleep 75 + - ./scripts/deploy_sandbox_client.sh server:4000 + +services: + - name: database + image: postgres + volumes: + - name: dockersock + path: /var/run + environment: + POSTGRES_DB: pt_db + POSTGRES_USER: pt_usr + POSTGRES_PASSWORD: PASSWORD diff --git a/README.md b/README.md index 768bfa3..1516353 100755 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Rust](https://github.com/realaltffour/PaperTrader/workflows/Rust/badge.svg) +[![Build Status](https://drone.tildegit.org/api/badges/ayham/PaperTrader/status.svg)](https://drone.tildegit.org/ayham/PaperTrader) # PaperTrader The opensource cross-platform paper trader for learning to trade assets. # Getting Started diff --git a/scripts/deploy_sandbox_client.sh b/scripts/deploy_sandbox_client.sh index 562a5d8..947a856 100755 --- a/scripts/deploy_sandbox_client.sh +++ b/scripts/deploy_sandbox_client.sh @@ -1,3 +1,3 @@ #!/bin/sh -cargo run --no-default-features --features "client,tls_no_verify" +cargo run --no-default-features --features "client,tls_no_verify" -- ${1:-0.0.0.0:4000} diff --git a/scripts/deploy_sandbox_server.sh b/scripts/deploy_sandbox_server.sh index 419864c..f1a6ece 100755 --- a/scripts/deploy_sandbox_server.sh +++ b/scripts/deploy_sandbox_server.sh @@ -1,3 +1,3 @@ #!/bin/sh -. ./scripts/env.sh && cargo run --no-default-features --features "server" -- 0.0.0.0:4000 --cert certs/certificate.crt --key certs/private.key +. ./scripts/env.sh && cargo run --no-default-features --features "server" -- ${1:-0.0.0.0:4000} --cert certs/certificate.crt --key certs/private.key diff --git a/scripts/env.sh b/scripts/env.sh index 06f2739..9bb1966 100755 --- a/scripts/env.sh +++ b/scripts/env.sh @@ -1,6 +1,8 @@ #!/bin/sh -export DB_HOST="localhost" +export DB_HOST="database" +[ -z "$CI_DEPLOY" ] && export DB_HOST="localhost" + export DB_HOST_PORT="5432" export DB_NAME="pt_db" diff --git a/src/libtrader/client/initializer.rs b/src/libtrader/client/initializer.rs index ad1ec9c..28787c7 100644 --- a/src/libtrader/client/initializer.rs +++ b/src/libtrader/client/initializer.rs @@ -10,6 +10,16 @@ use crate::client::network::gen_tls_client_config::gen_tls_client_config; use rand::distributions::Alphanumeric; use rand::{thread_rng, Rng}; +use argh::FromArgs; + +/// Client Options +#[derive(FromArgs)] +struct Options { + /// bind addr + #[argh(positional)] + addr: String, +} + /// Initializes global logger. /// /// Private function used by libtrader_init() to initialize the logger. Log destinations are @@ -94,10 +104,15 @@ pub async fn libtrader_init_client() -> std::io::Result<()> { // Initialize log. libtrader_init_log()?; - let addr = ("0.0.0.0", 4000) + // Initialize arguments + let options: Options = argh::from_env(); + + let addr = options + .addr .to_socket_addrs()? .next() - .ok_or_else(|| std::io::Error::from(std::io::ErrorKind::NotFound))?; + .ok_or_else(|| std::io::Error::from(std::io::ErrorKind::AddrNotAvailable))?; + let domain = "localhost"; let config = gen_tls_client_config()?; diff --git a/src/libtrader/server/db/initializer.rs b/src/libtrader/server/db/initializer.rs index caf0d5c..7af1cef 100644 --- a/src/libtrader/server/db/initializer.rs +++ b/src/libtrader/server/db/initializer.rs @@ -19,6 +19,7 @@ pub async fn db_connect( pass: String, ) -> Result { /* Generate the requested string */ + println!("{}", std::env::var("DB_HOST").unwrap()); let db_connect_str = format!( "host={} port={} dbname={} user={} password={}", std::env::var("DB_HOST").unwrap(), diff --git a/todo/v1.libtrader.md b/todo/v1.libtrader.md index e5f8665..6ee4cba 100644 --- a/todo/v1.libtrader.md +++ b/todo/v1.libtrader.md @@ -1,8 +1,8 @@ ## To do - -## In progress - +- use env.sh or arguments +- server move network code to somewhere plausable. +- create correct modules - data implmentation stuff * [ ] implement buy & sell * [ ] impl on client @@ -12,6 +12,16 @@ * [ ] ret data on server * [ ] transaction data retrieval * [ ] split data into multiple writes +- add testing suite + * [ ] configure ci to run those tests + * [ ] add tests for all server functions + * [ ] add tests for all client functions + +## In progress + +- configure drone ci + * [ ] wrap server deployment commands in docker + * [ ] wrap client deployment commands in docker ## Done