diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 2491ac1..0000000 --- a/Dockerfile +++ /dev/null @@ -1,41 +0,0 @@ -FROM node:10-jessie as node -#If encounter Invalid cross-device error -run on host 'echo N | sudo tee /sys/module/overlay/parameters/metacopy' -COPY server/ui /app/server/ui -WORKDIR /app/server/ui -RUN yarn -RUN yarn build - -FROM rust:latest as rust -WORKDIR /app/server -# cache the build -RUN USER=root cargo new service -WORKDIR /app/server/service -# copy over your manifests -COPY server/service/Cargo.toml server/service/Cargo.lock ./ -RUN cargo build --release -RUN rm src/*.rs -COPY server/service/src ./src -RUN rm -r ./target/release/.fingerprint/torrents-csv-* -RUN cargo build --release - -FROM debian:jessie-slim as volume -COPY torrents.csv /db/ -COPY torrent_files.csv /db/ - -FROM debian:jessie-slim -RUN apt update && apt install -y sqlite3 curl -RUN curl -LO https://github.com/BurntSushi/ripgrep/releases/download/0.10.0/ripgrep_0.10.0_amd64.deb -RUN dpkg -i ripgrep_0.10.0_amd64.deb -RUN curl -LO https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 -RUN chmod +x jq-linux64 -RUN mv jq-linux64 /usr/bin/jq - -COPY --from=node /app/server/ui/dist /app/dist -COPY --from=rust /app/server/service/target/release/torrents-csv-service /app/ -COPY --from=volume /db/torrents.csv /app/ -COPY --from=volume /db/torrent_files.csv /app/ -COPY scripts /app/scripts -WORKDIR /app/scripts/ -RUN ["/bin/bash", "./build_sqlite.sh"] -EXPOSE 8080 -WORKDIR /app/ diff --git a/README.md b/README.md index 5724b89..36f711f 100644 --- a/README.md +++ b/README.md @@ -15,21 +15,34 @@ 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://gitlab.com/dessalines/torrents.csv/issues). 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/). + ## Webserver + `Torrents.csv` comes with a simple webserver. [Demo Server](https://torrents-csv.ml) ### Docker ``` git clone https://gitlab.com/dessalines/torrents.csv -cd torrents.csv -docker-compose up +cd torrents.csv/scripts && ./build_sqlite.sh && cd .. +cd docker/prod +docker-compose up -d ``` +### Docker Development + +git clone https://gitlab.com/dessalines/torrents.csv +cd torrents.csv/scripts && ./build_sqlite.sh && cd .. +cd docker/dev +docker-compose up -d + ### Local + #### Requirements + - [Rust](https://www.rust-lang.org/) - [Yarn](https://yarnpkg.com/en/) - [SQLite3](https://www.sqlite.org/index.html) -- [jq command line JSON parser: Needs at least jq-1.6](https://stedolan.github.io/jq/) + #### Running + ``` git clone https://gitlab.com/dessalines/torrents.csv cd torrents.csv/scripts @@ -62,6 +75,7 @@ bleh season 1 (1993-) link: magnet:?xt=urn:btih:INFO_HASH_HERE ``` ## Uploading / Adding Torrents from a Directory + An *upload*, consists of making a pull request after running the `scan_torrents.sh` script, which adds torrents from a directory you choose to the `.csv` file, after checking that they aren't already there, and that they have seeders. It also adds their files to `torrent_files.csv`. ### Requirements diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index d5a24c0..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,13 +0,0 @@ -version: '3' - -services: - torrents-csv: - build: - context: . - command: /bin/sh -c /app/torrents-csv-service - restart: always - ports: - - "8902:8080" - environment: - TORRENTS_CSV_DB_FILE: /app/torrents.db - TORRENTS_CSV_FRONT_END_DIR: /app/dist diff --git a/docker/dev/Dockerfile b/docker/dev/Dockerfile new file mode 100644 index 0000000..c98ac6d --- /dev/null +++ b/docker/dev/Dockerfile @@ -0,0 +1,43 @@ +FROM node:10-jessie as node +WORKDIR /app/ui + +# Cache deps +COPY server/ui/package.json server/ui/yarn.lock ./ +RUN yarn install --pure-lockfile + +# Build +COPY server/ui /app/ui +RUN yarn build + +FROM rust:1.37 as rust + +# Install musl +RUN apt-get update +RUN apt-get install musl-tools -y +RUN rustup target add x86_64-unknown-linux-musl + +# Cache deps +WORKDIR /app +RUN USER=root cargo new server +WORKDIR /app/server/service +COPY server/service/Cargo.toml server/service/Cargo.lock ./ +RUN mkdir -p ./src/bin \ + && echo 'fn main() { println!("Dummy") }' > ./src/bin/main.rs +RUN RUSTFLAGS=-Clinker=musl-gcc cargo build --release --target=x86_64-unknown-linux-musl +RUN rm -f ./target/x86_64-unknown-linux-musl/release/deps/torrents-csv-* +COPY server/service/src ./src/ + +# build for release +RUN RUSTFLAGS=-Clinker=musl-gcc cargo build --frozen --release --target=x86_64-unknown-linux-musl + +FROM alpine:3.10 + +# Copy resources +COPY --from=rust /app/server/service/target/x86_64-unknown-linux-musl/release/torrents-csv-service /app/ +COPY --from=node /app/ui/dist /app/dist +RUN addgroup -g 1000 torrents-csv-service +RUN adduser -D -s /bin/sh -u 1000 -G torrents-csv-service torrents-csv-service +RUN chown torrents-csv-service:torrents-csv-service /app/torrents-csv-service +USER torrents-csv-service +EXPOSE 8080 +CMD ["/app/torrents-csv-service"] diff --git a/docker/dev/docker-compose.yml b/docker/dev/docker-compose.yml new file mode 100644 index 0000000..66c6d8f --- /dev/null +++ b/docker/dev/docker-compose.yml @@ -0,0 +1,16 @@ +version: '3.7' + +services: + torrents-csv: + build: + context: ../../ + dockerfile: docker/dev/Dockerfile + ports: + - "8902:8080" + environment: + TORRENTS_CSV_DB_FILE: /app/torrents.db + TORRENTS_CSV_FRONT_END_DIR: /app/dist + volumes: + - type: bind + source: ../../torrents.db + target: /app/torrents.db diff --git a/docker/prod/docker-compose.yml b/docker/prod/docker-compose.yml new file mode 100644 index 0000000..f38bc6a --- /dev/null +++ b/docker/prod/docker-compose.yml @@ -0,0 +1,14 @@ +version: '3.7' + +services: + torrents-csv: + image: dessalines/torrents-csv:0.0.1 + ports: + - "8902:8080" + environment: + TORRENTS_CSV_DB_FILE: /app/torrents.db + TORRENTS_CSV_FRONT_END_DIR: /app/dist + volumes: + - type: bind + source: ../../torrents.db + target: /app/torrents.db diff --git a/docker_update.sh b/docker_update.sh deleted file mode 100755 index 4a52b52..0000000 --- a/docker_update.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -set -e - -git pull -docker-compose up -d --no-deps --build diff --git a/scripts/build_sqlite.sh b/scripts/build_sqlite.sh index b0f1b93..1bfb379 100755 --- a/scripts/build_sqlite.sh +++ b/scripts/build_sqlite.sh @@ -38,7 +38,8 @@ echo "Building files DB from $torrent_files_csv ..." sed 's/\"//g' $torrent_files_csv > torrent_files_removed_quotes.csv # Removing those with too many ; -rg "^([^;]*;){3}[^;]+$" torrent_files_removed_quotes.csv > torrent_files_temp_2 +awk -F \; 'NF == 4' torrent_files_temp_2 + rm torrent_files_removed_quotes.csv mv torrent_files_temp_2 torrent_files_temp