Fixing up docker a little bit

This commit is contained in:
Dessalines 2018-12-02 22:19:03 -07:00
parent 3ffa4e144d
commit a08f0332bc
4 changed files with 38 additions and 26 deletions

View File

@ -2,5 +2,4 @@ server/ui/node_modules
server/ui/dist server/ui/dist
server/service/target server/service/target
new_torrents_fetcher new_torrents_fetcher
scripts
.git .git

View File

@ -1,29 +1,39 @@
# Torrents.csv Dockerfile FROM node:10-jessie as node
#If encounter Invalid cross-device error -run on host 'echo N | sudo tee /sys/module/overlay/parameters/metacopy'
# Build front end resources ENV TORRENTS_CSV_ENDPOINT=http://0.0.0.0:8080
FROM node:10 AS node-builder COPY server/ui /app/server/ui
RUN cd /app/server/ui && yarn && yarn build
ARG UI_PATH=/usr/app/server/ui FROM rust:1.30 as rust
COPY server/ui ${UI_PATH} COPY server/service /app/server/service
WORKDIR ${UI_PATH} RUN cd /app/server/service && cargo build --release && cp ./target/release/torrents-csv-service .
ARG ENDPOINT_NAME=0.0.0.0:8080
RUN echo "export const endpoint = '${ENDPOINT_NAME}';" > src/env.ts FROM debian:jessie-slim as volume
RUN yarn
RUN yarn build
# Build back end COPY torrents.csv /db/
FROM rust:1.30
# Copy the torrents.csv file FROM debian:jessie-slim
COPY torrents.csv /usr/app/
# Creating a directory to work from RUN apt update && apt install -y sqlite3
ARG SERVICE_PATH=/usr/app/server/service
COPY server/service ${SERVICE_PATH}
WORKDIR ${SERVICE_PATH}
COPY --from=node-builder /usr/app/server/ui /usr/app/server/ui 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 scripts /app/scripts
RUN cd /app/scripts && . ./build_sqlite.sh
# Build it EXPOSE 8080
RUN cargo build --release WORKDIR /app/
ENV TORRENTS_CSV_DB_FILE=/app/torrents.db
ENV TORRENTS_CSV_FRONT_END_DIR=/app/dist
RUN sqlite3 ${TORRENTS_CSV_DB_FILE} 'select * from torrents limit 10'
CMD /app/torrents-csv-service
# Running this:
# docker build .
# docker run -p 8080:8080 image_name

View File

@ -1,16 +1,18 @@
#!/bin/bash #!/bin/bash
csv_file="${TORRENTS_CSV_FILE:-../torrents.csv}"
db_file="${TORRENTS_CSV_DB_FILE:-../torrents.db}"
echo "Creating temporary torrents.db file..." echo "Creating temporary torrents.db file..."
# Remove double quotes for csv import # Remove double quotes for csv import
sed 's/\"//g' ../torrents.csv > torrents_removed_quotes.csv sed 's/\"//g' $csv_file > torrents_removed_quotes.csv
# Sort by seeders desc before insert # Sort by seeders desc before insert
sort --field-separator=';' --key=5 -nr -o torrents_removed_quotes.csv torrents_removed_quotes.csv sort --field-separator=';' --key=5 -nr -o torrents_removed_quotes.csv torrents_removed_quotes.csv
rm ../torrents.db rm $db_file
sqlite3 -batch ../torrents.db <<"EOF" sqlite3 -batch $db_file <<"EOF"
create table torrents( create table torrents(
"infohash" TEXT, "infohash" TEXT,
"name" TEXT, "name" TEXT,
@ -24,8 +26,8 @@ create table torrents(
.separator ";" .separator ";"
.import torrents_removed_quotes.csv torrents .import torrents_removed_quotes.csv torrents
UPDATE torrents SET completed=NULL WHERE completed = ''; UPDATE torrents SET completed=NULL WHERE completed = '';
EOF EOF
rm torrents_removed_quotes.csv rm torrents_removed_quotes.csv

View File

@ -1,6 +1,7 @@
# Optionally use environment variables # Optionally use environment variables
# export TORRENTS_CSV_ENDPOINT=http://0.0.0.0:8080 # export TORRENTS_CSV_ENDPOINT=http://0.0.0.0:8080
# export TORRENTS_CSV_FILE=`pwd`/../../torrents.db
# export TORRENTS_CSV_DB_FILE=`pwd`/../../torrents.db # export TORRENTS_CSV_DB_FILE=`pwd`/../../torrents.db
# export TORRENTS_CSV_FRONT_END_DIR=`pwd`/../ui/dist # export TORRENTS_CSV_FRONT_END_DIR=`pwd`/../ui/dist