summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml1
-rw-r--r--Rocket.toml26
-rw-r--r--docker/Dockerfile12
-rw-r--r--docker/docker-compose.yml3
-rw-r--r--src/main.rs53
5 files changed, 90 insertions, 5 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 40de2c9..6f3a9d5 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,3 +10,4 @@ edition = "2018"
rspotify = "0.7"
rocket = "0.4"
lazy_static = { version = "1.4"}
+noria = {git="https://github.com/mit-pdos/noria"}
diff --git a/Rocket.toml b/Rocket.toml
new file mode 100644
index 0000000..b8aec95
--- /dev/null
+++ b/Rocket.toml
@@ -0,0 +1,26 @@
+[development]
+address = "localhost"
+port = 8008
+#workers = [number of cpus * 2]
+keep_alive = 5
+log = "verbose"
+#secret_key = [randomly generated at launch]
+limits = { forms = 32768 }
+
+[staging]
+address = "0.0.0.0"
+port = 8008
+#workers = [number of cpus * 2]
+keep_alive = 5
+log = "normal"
+#secret_key = [randomly generated at launch]
+limits = { forms = 32768 }
+
+[production]
+address = "0.0.0.0"
+port = 80
+#workers = [number of cpus * 2]
+keep_alive = 5
+log = "critical"
+#secret_key = [randomly generated at launch]
+limits = { forms = 32768 }
diff --git a/docker/Dockerfile b/docker/Dockerfile
index 67662c3..8525d7c 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -1,12 +1,14 @@
# composer install
-FROM liuchong/rustup:nightly as build
-COPY ./ /app/
-WORKDIR /app
-RUN cargo build --release
+#FROM liuchong/rustup:nightly as build
+#COPY ./ /app/
+#WORKDIR /app
+#RUN cargo build --release
FROM debian as spotify_intersect
WORKDIR /srv/spotify_intersect
-COPY --from=build /app/target/release/spotify_intersect ./
+#COPY --from=build /app/target/release/spotify_intersect ./
+RUN apt-get update && apt-get -y install libssl-dev
+COPY ./target/release/spotify_intersect ./
COPY .env /srv/spotify_intersect/.env
CMD ./spotify_intersect
diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml
index f388575..477176b 100644
--- a/docker/docker-compose.yml
+++ b/docker/docker-compose.yml
@@ -3,6 +3,8 @@ services:
spotify_intersect:
image: spotify_intersect
container_name: spotify_intersect
+ ports:
+ - 8000:8000
build:
context: ..
dockerfile: docker/Dockerfile
@@ -12,6 +14,7 @@ services:
- hostnet
depends_on:
- track_db
+ - zookeeper
track_db:
image: noria
build:
diff --git a/src/main.rs b/src/main.rs
index 8b7af53..d9a8272 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -20,6 +20,59 @@ fn main() {
// .client_secret("this-is-my-client-secret")
// .redirect_uri("http://localhost:8888/callback")
// .build();
+ //
+ let mut db = noria::ControllerHandle::from_zk("127.0.0.1:2181").unwrap();
+
+ //db.ready();
+ println!("test {:?}", db.url());
+ db.install_recipe(
+ "
+ CREATE TABLE Article (aid int, title varchar(255), url text, PRIMARY KEY(aid));
+ CREATE TABLE Vote (aid int, uid int);
+",
+ );
+ println!("test");
+ // we can then get handles that let us insert into the new tables
+ let mut article = db.table("Article").unwrap();
+ let mut vote = db.table("Vote").unwrap();
+
+ // let's make a new article
+ let aid = 42;
+ let title = "I love Soup";
+ let url = "https://pdos.csail.mit.edu";
+ article
+ .insert(vec![aid.into(), title.into(), url.into()])
+ .unwrap();
+
+ // and then vote for it
+ vote.insert(vec![aid.into(), 1.into()]).unwrap();
+ println!("test");
+
+ // we can also declare views that we want want to query
+ db.extend_recipe(
+ "
+ VoteCount: \
+ SELECT Vote.aid, COUNT(uid) AS votes \
+ FROM Vote GROUP BY Vote.aid;
+ QUERY ArticleWithVoteCount: \
+ SELECT Article.aid, title, url, VoteCount.votes AS votes \
+ FROM Article LEFT JOIN VoteCount ON (Article.aid = VoteCount.aid) \
+ WHERE Article.aid = ?;",
+ );
+
+ // and then get handles that let us execute those queries to fetch their results
+ let mut awvc = db.view("ArticleWithVoteCount").unwrap();
+ // looking up article 42 should yield the article we inserted with a vote count of 1
+ assert_eq!(
+ awvc.lookup(&[aid.into()], true).unwrap(),
+ vec![vec![
+ noria::DataType::from(aid),
+ title.into(),
+ url.into(),
+ 1.into()
+ ]]
+ );
+
rocket::ignite()
.mount("/", routes![serve::token, serve::get_tracks])
.launch();