From be6aa179f9d93333aa5d22496eea804a4536750b Mon Sep 17 00:00:00 2001 From: Heretic Date: Mon, 1 May 2023 09:40:13 -0400 Subject: [PATCH] Removing old UI, using new perseus UI. --- .gitmodules | 4 --- README.md | 14 +++++---- docker/dev/Dockerfile | 12 -------- docker/dev/docker-compose.yml | 1 + docker/prod/Dockerfile | 13 -------- docker/prod/docker-compose.yml | 38 +++++++++++++++++++++-- docker/prod/nginx.conf | 55 ++++++++++++++++++++++++++++++++++ src/main.rs | 12 -------- ui | 1 - update_data.sh | 1 - 10 files changed, 100 insertions(+), 51 deletions(-) create mode 100644 docker/prod/nginx.conf delete mode 160000 ui diff --git a/.gitmodules b/.gitmodules index 6abe054..da36d2d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,7 +1,3 @@ -[submodule "ui"] - path = ui - url = https://git.torrents-csv.ml/heretic/torrents-csv-ui - branch = main [submodule "data"] path = data url = https://git.torrents-csv.ml/heretic/torrents-csv-data diff --git a/README.md b/README.md index 4c66854..a1555a6 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ [Demo Server](https://torrents-csv.ml) -`Torrents.csv` is a _collaborative_ repository of torrents and their files, consisting of a searchable `torrents.csv`, and `torrent_files.csv`. With it you can search for torrents, or files within torrents. It aims to be a universal file system for popular data. +`Torrents.csv` is a _collaborative_ repository of torrents, consisting of a searchable `torrents.csv` file. It aims to be a universal file system for popular data. -Its initially populated with a January 2017 backup of the pirate bay, and new torrents are periodically added from various torrents sites. It comes with a self-hostable [Torrents.csv webserver](https://torrents-csv.ml), a command line search, and a folder scanner to add torrents, and their files. +Its initially populated with a January 2017 backup of the pirate bay, and new torrents are periodically added from various torrents sites. It comes with a self-hostable [Torrents.csv webserver](https://torrents-csv.ml), a command line search, and a folder scanner to add torrents. `Torrents.csv` will only store torrents with at least one seeder to keep the file small, will be periodically purged of non-seeded torrents, and sorted by infohash. @@ -14,7 +14,7 @@ Its initially populated with a January 2017 backup of the pirate bay, and new to To request more torrents, or add your own, go [here](https://git.torrents-csv.ml/heretic/torrents-csv-data). -Made with [Rust](https://www.rust-lang.org), [ripgrep](https://github.com/BurntSushi/ripgrep), [Actix](https://actix.rs/), [Inferno](https://www.infernojs.org), [Typescript](https://www.typescriptlang.org/). +Made with [Rust](https://www.rust-lang.org), [ripgrep](https://github.com/BurntSushi/ripgrep), [Actix](https://actix.rs/), [Perseus](https://framesurge.sh/perseus/en-US/), and [Sycamore](https://sycamore-rs.netlify.app/). ## Webserver @@ -24,10 +24,11 @@ Made with [Rust](https://www.rust-lang.org), [ripgrep](https://github.com/BurntS ``` wget https://git.torrents-csv.ml/heretic/torrents-csv-server/raw/branch/main/docker/prod/docker-compose.yml +wget https://git.torrents-csv.ml/heretic/torrents-csv-server/raw/branch/main/docker/prod/nginx.conf docker-compose up -d ``` -And goto http://localhost:8902 +And goto http://localhost:8904 ### Docker Development @@ -35,6 +36,7 @@ And goto http://localhost:8902 git clone --recurse-submodules https://git.torrents-csv.ml/heretic/torrents-csv-server cd torrents-csv-server/docker/dev ./docker_update.sh +# For the front end, check out http://git.torrents-csv.ml/heretic/torrents-csv-ui-perseus ``` ## Command Line Searching @@ -59,8 +61,8 @@ bleh season 1 (1993-) A JSON output of search results is available at: -`http://localhost:8902/service/search?q=[QUERY]&size=[NUMBER_OF_RESULTS]&page=[PAGE]&type=[torrent | file]` +`http://localhost:8904/service/search?q=[QUERY]&size=[NUMBER_OF_RESULTS]&page=[PAGE]` New torrents are at: -`http://localhost:8902/service/new?size=[NUMBER_OF_RESULTS]&page=[PAGE]&type=[torrent | file]` +`http://localhost:8904/service/new?size=[NUMBER_OF_RESULTS]&page=[PAGE]` diff --git a/docker/dev/Dockerfile b/docker/dev/Dockerfile index 2793cc8..2199622 100644 --- a/docker/dev/Dockerfile +++ b/docker/dev/Dockerfile @@ -1,15 +1,4 @@ ARG RUST_BUILDER_IMAGE=clux/muslrust:stable -# Front end -FROM node:alpine as node -WORKDIR /app/ui - -# Cache deps -COPY ui/package.json ui/yarn.lock ./ -RUN yarn install --pure-lockfile - -# Build the UI -COPY ./ui /app/ui -RUN yarn build # Build the torrents.db file FROM alpine:3 as db_file_builder @@ -53,7 +42,6 @@ RUN addgroup -S myuser && adduser -S myuser -G myuser # Copy resources COPY --from=builder /app/torrents-csv-service /app/ -COPY --from=node /app/ui/dist /app/dist COPY --from=db_file_builder /app/torrents.db /app/torrents.db EXPOSE 8080 USER myuser diff --git a/docker/dev/docker-compose.yml b/docker/dev/docker-compose.yml index 7179fd9..92bdd93 100644 --- a/docker/dev/docker-compose.yml +++ b/docker/dev/docker-compose.yml @@ -9,3 +9,4 @@ services: environment: TORRENTS_CSV_DB_FILE: /app/torrents.db TORRENTS_CSV_FRONT_END_DIR: /app/dist +# You should run perseus locally to test diff --git a/docker/prod/Dockerfile b/docker/prod/Dockerfile index 8b7d532..08f9155 100644 --- a/docker/prod/Dockerfile +++ b/docker/prod/Dockerfile @@ -1,17 +1,5 @@ ARG RUST_BUILDER_IMAGE=clux/muslrust:stable -# Front end -FROM node:alpine as node -WORKDIR /app/ui - -# Cache deps -COPY ui/package.json ui/yarn.lock ./ -RUN yarn install --pure-lockfile - -# Build the UI -COPY ./ui /app/ui -RUN yarn build - # Build the torrents.db file FROM alpine:3 as db_file_builder RUN apk add sqlite bash @@ -54,7 +42,6 @@ RUN addgroup -S myuser && adduser -S myuser -G myuser # Copy resources COPY --from=builder /app/torrents-csv-service /app/ -COPY --from=node /app/ui/dist /app/dist COPY --from=db_file_builder /app/torrents.db /app/torrents.db EXPOSE 8080 USER myuser diff --git a/docker/prod/docker-compose.yml b/docker/prod/docker-compose.yml index 3c0cf74..5969335 100644 --- a/docker/prod/docker-compose.yml +++ b/docker/prod/docker-compose.yml @@ -1,11 +1,45 @@ version: '3.7' +networks: + # communication to web and clients + torrentsexternalproxy: + # communication between lemmy services + torrentsinternal: + driver: bridge + internal: true + services: + proxy: + image: nginx:1-alpine + networks: + - torrentsinternal + - torrentsexternalproxy + ports: + # actual and only port facing any connection from outside + - "8904:8904" + volumes: + - ./nginx.conf:/etc/nginx/nginx.conf:ro + restart: always + depends_on: + - torrents-csv + - torrents-csv-ui-perseus + torrents-csv: image: dessalines/torrents-csv-server:latest restart: always - ports: - - "8902:8902" + hostname: torrents-csv + networks: + - torrentsinternal environment: TORRENTS_CSV_DB_FILE: /app/torrents.db TORRENTS_CSV_FRONT_END_DIR: /app/dist + + torrents-csv-ui-perseus: + image: dessalines/torrents-csv-ui-perseus:latest + restart: always + networks: + - torrentsinternal + environment: + PERSEUS_HOST: "0.0.0.0" + TORRENTS_CSV_ENDPOINT: "http://torrents-csv:8902" + diff --git a/docker/prod/nginx.conf b/docker/prod/nginx.conf new file mode 100644 index 0000000..9cf1ee6 --- /dev/null +++ b/docker/prod/nginx.conf @@ -0,0 +1,55 @@ +worker_processes 1; +events { + worker_connections 1024; +} +http { + upstream torrents-csv { + server "torrents-csv:8902"; + } + upstream torrents-csv-ui-perseus { + server "torrents-csv-ui-perseus:8080"; + } + + server { + # this is the port inside docker, not the public one yet + listen 8904; + + # change if needed, this is facing the public web + server_name localhost; + server_tokens off; + + gzip on; + gzip_types text/css application/javascript image/svg+xml; + gzip_vary on; + + add_header X-Frame-Options SAMEORIGIN; + add_header X-Content-Type-Options nosniff; + add_header X-XSS-Protection "1; mode=block"; + + # frontend general requests + location / { + set $proxpass "http://torrents-csv-ui-perseus"; + proxy_pass $proxpass; + + rewrite ^(.+)/+$ $1 permanent; + # Send actual client IP upstream + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + + # backend + location ~ ^/(service) { + proxy_pass "http://torrents-csv"; + # proxy common stuff + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + + # Send actual client IP upstream + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + } +} diff --git a/src/main.rs b/src/main.rs index 04cd289..e56eefb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,8 +6,6 @@ extern crate serde_json; extern crate serde_derive; extern crate rusqlite; -use actix_files as fs; -use actix_files::NamedFile; use actix_web::{middleware, web, App, HttpResponse, HttpServer}; use anyhow::{anyhow, Result}; use rusqlite::params; @@ -25,8 +23,6 @@ async fn main() -> io::Result<()> { HttpServer::new(move || { App::new() .wrap(middleware::Logger::default()) - .service(fs::Files::new("/static", front_end_dir())) - .route("/", web::get().to(index)) .route("/service/search", web::get().to(search)) }) .keep_alive(None) @@ -35,14 +31,6 @@ async fn main() -> io::Result<()> { .await } -async fn index() -> Result { - Ok(NamedFile::open(front_end_dir() + "/index.html")?) -} - -fn front_end_dir() -> String { - env::var("TORRENTS_CSV_FRONT_END_DIR").unwrap_or_else(|_| "./ui/dist".to_string()) -} - fn torrents_db_file() -> String { env::var("TORRENTS_CSV_DB_FILE").unwrap_or_else(|_| "./torrents.db".to_string()) } diff --git a/ui b/ui deleted file mode 160000 index 5961585..0000000 --- a/ui +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5961585fe1fc378c27549786e7e0a7b39f0a7b2d diff --git a/update_data.sh b/update_data.sh index 95d05d8..41fc15f 100755 --- a/update_data.sh +++ b/update_data.sh @@ -1,6 +1,5 @@ #!/bin/bash git submodule update --remote git add data -git add ui git commit -m"Updating torrents-csv-data." git push