From fe938afa3ff20967aae1f0d9f9d48641e5f1d852 Mon Sep 17 00:00:00 2001 From: Jurgis Sakalauskas Date: Fri, 4 Aug 2023 16:06:47 +0300 Subject: [PATCH] dockerise server --- .env.sample | 34 ++++++++++++------- Dockerfile | 17 ++++++++++ docker-compose.yaml | 19 +++++++++++ dockerignore | 3 ++ src/KodiApi/Torrent/torrent.service.ts | 5 ++- src/Torrent/SeedClient/torrent-seed.client.ts | 5 ++- src/config/config.service.ts | 2 +- src/config/paths.config.ts | 7 ++-- src/config/recent-searches.config.ts | 4 +-- src/config/type-orm.config.ts | 3 +- src/config/video-files.config.ts | 10 +++--- 11 files changed, 81 insertions(+), 28 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yaml create mode 100644 dockerignore diff --git a/.env.sample b/.env.sample index c4f17c7..1285876 100644 --- a/.env.sample +++ b/.env.sample @@ -1,17 +1,25 @@ PORT=3000 -STATIC_SERVE_FOLDER="data/static" -LOG_FILE_REQUESTS="data/static/static_log.txt" -DB_PATH="./data/db/db.db" -RECENT_SEARCHES_FOLDER="./data/recent_searches" + +STATIC_SERVE_FOLDER='/mnt/hdd/videos' +LOG_FILE_REQUESTS_FOLDER='/mnt/hdd/videos' +LOG_FILE_REQUESTS_NAME="static_log.txt" + +DB_FOLDER='/mnt/hdd/videos/db' +DB_FILENAME="db.db" + +RECENT_SEARCHES_FOLDER="/mnt/hdd/videos/recent-searches" RECENT_SEARCHES_LIMIT=20 -VIDEO_FILES_FOLDERS='[ - "/home/user/videos", - "/mnt/hdd/videos" -]' + +VIDEO_FILES_FOLDER='/mnt/hdd/videos' #also torrent download dir + VIDEO_FILES_EXT='[".mkv", ".mp4", ".avi"]' + PATTERNS_TO_IGNORE='["AOE1/"]' #file path patterns to ignore from video files scan -LINKOMANIJA_USERNAME=usern -LINKOMANIJA_PASSWORD=password -LINKOMANIJA_PASSKEY=some123long321passkey -TORRENT_DOWNLOAD_DIR='/mnt/hdd/videos' -TRANSMISSION_CLIENT_HOST=192.168.1.133 + +LINKOMANIJA_USERNAME=user +LINKOMANIJA_PASSWORD=passw +LINKOMANIJA_PASSKEY=123pass456key789 + +TRANSMISSION_CLIENT_HOST=host.docker.internal +TRANSMISSION_CLIENT_USER=user +TRANSMISSION_CLIENT_PASSWORD=password diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3cf57bc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM node:18 + +RUN apt-get update +RUN apt-get install ffmpeg -y + +WORKDIR /srv/app +COPY ./ /srv/app +RUN npm install +RUN npm run typeorm:run-migrations + +EXPOSE $PORT + +# serve dev +CMD ["npm", "run", "start:dev"] + +#serve prod +#CMD ["npm", "run", "start"] diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..697b218 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,19 @@ +services: + server: + build: + context: . + dockerfile: ./Dockerfile +# working_dir: /srv/app/ + volumes: + - .:/srv/app/ + - $VIDEO_FILES_FOLDER:$VIDEO_FILES_FOLDER + - $LOG_FILE_REQUESTS_FOLDER:/srv/data/requests-log + - $STATIC_SERVE_FOLDER:/srv/data/static + - $DB_FOLDER:/srv/data/db + - $RECENT_SEARCHES_FOLDER:/srv/data/recent-searches + env_file: + - .env + ports: + - $PORT:$PORT + extra_hosts: + - "host.docker.internal:host-gateway" diff --git a/dockerignore b/dockerignore new file mode 100644 index 0000000..98c92a5 --- /dev/null +++ b/dockerignore @@ -0,0 +1,3 @@ +**/node_modules +**/data +**/dist diff --git a/src/KodiApi/Torrent/torrent.service.ts b/src/KodiApi/Torrent/torrent.service.ts index f97eb7d..11fcf97 100644 --- a/src/KodiApi/Torrent/torrent.service.ts +++ b/src/KodiApi/Torrent/torrent.service.ts @@ -322,7 +322,10 @@ export class TorrentService { const torrId = parseInt(id); const result = await this.torrSeedClient .addTorrentById(torrId) - .catch(() => false); + .catch((e) => { + console.log(e); + return false; + }); return new NotificationResponse( result ? 'torrent added to transmission' : 'adding failed', diff --git a/src/Torrent/SeedClient/torrent-seed.client.ts b/src/Torrent/SeedClient/torrent-seed.client.ts index 9af5416..b28d3da 100644 --- a/src/Torrent/SeedClient/torrent-seed.client.ts +++ b/src/Torrent/SeedClient/torrent-seed.client.ts @@ -29,7 +29,10 @@ export class TorrentSeedClient { return Promise.reject('torrent not found'); } - const torrInfo = await this.addTorrent(torrentEntity).catch(() => null); + const torrInfo = await this.addTorrent(torrentEntity).catch((e) => { + console.log(e); + return null; + }); if (torrInfo) { await this.torrentRepository.update( diff --git a/src/config/config.service.ts b/src/config/config.service.ts index 9348f3b..716b55f 100644 --- a/src/config/config.service.ts +++ b/src/config/config.service.ts @@ -13,7 +13,7 @@ export class ConfigService { private videoFilesConfig: VideoFilesConfig = new VideoFilesConfig(this); private recentSearches: RecentSearchesConfig = new RecentSearchesConfig(this); - public getEnv(key: string): any { + public getEnv(key: string): string { return process.env[key]; } diff --git a/src/config/paths.config.ts b/src/config/paths.config.ts index f2875c3..9b40d3c 100644 --- a/src/config/paths.config.ts +++ b/src/config/paths.config.ts @@ -7,11 +7,14 @@ export class PathsConfig { } public getStaticRequestsLogPath(): string { - return this.getPathByEnvKey('LOG_FILE_REQUESTS'); + return join( + '/srv/data/requests-log', + this.configService.getEnv('LOG_FILE_REQUESTS_NAME'), + ); } public getStaticFolder(): string { - return this.getPathByEnvKey('STATIC_SERVE_FOLDER'); + return '/srv/data/static'; } public getPathByEnvKey(key: string) { diff --git a/src/config/recent-searches.config.ts b/src/config/recent-searches.config.ts index a7c082a..9130b44 100644 --- a/src/config/recent-searches.config.ts +++ b/src/config/recent-searches.config.ts @@ -6,9 +6,7 @@ export class RecentSearchesConfig { } public getRecentSearchesFolder(): string { - return this.configService - .getPaths() - .getPathByEnvKey('RECENT_SEARCHES_FOLDER'); + return '/srv/data/recent-searches'; } public getRecentSearchesLimit(): number { diff --git a/src/config/type-orm.config.ts b/src/config/type-orm.config.ts index 0c3687e..d0ef9b3 100644 --- a/src/config/type-orm.config.ts +++ b/src/config/type-orm.config.ts @@ -4,11 +4,12 @@ import { EntityClassOrSchema } from '@nestjs/typeorm/dist/interfaces/entity-clas import { TitleEntity } from '../Shared/Entity/title.entity'; import { FileEntity } from '../Shared/Entity/file.entity'; import { TorrentEntity } from '../Shared/Entity/torrent.entity'; +import { join } from 'path'; export class TypeOrmConfig { constructor(configService: ConfigService) { this.type = 'sqlite'; - this.database = configService.getEnv('DB_PATH'); + this.database = join('/srv/data/db', configService.getEnv('DB_FILENAME')); this.entities = [LrtCategory, TitleEntity, FileEntity, TorrentEntity]; } type: 'sqlite'; diff --git a/src/config/video-files.config.ts b/src/config/video-files.config.ts index fec6103..fdf8c6d 100644 --- a/src/config/video-files.config.ts +++ b/src/config/video-files.config.ts @@ -6,7 +6,7 @@ export class VideoFilesConfig { } public getVideoFilesFolders(): string[] { - return JSON.parse(this.configService.getEnv('VIDEO_FILES_FOLDERS')); + return [this.configService.getEnv('VIDEO_FILES_FOLDER')]; } public getVideoFilesExt(): string[] { @@ -18,17 +18,15 @@ export class VideoFilesConfig { } public getTorrentDownloadDir(): string { - return this.configService - .getPaths() - .getPathByEnvKey('TORRENT_DOWNLOAD_DIR'); + return this.configService.getEnv('VIDEO_FILES_FOLDER'); } public getTransmissionOptions() { return { host: this.configService.getEnv('TRANSMISSION_CLIENT_HOST'), // # default 'localhost' //port: 9091, // # default 9091 - //username: "username", // # default blank - //password: "password", // # default blank + username: this.configService.getEnv('TRANSMISSION_CLIENT_USER'), // # default blank + password: this.configService.getEnv('TRANSMISSION_CLIENT_PASSWORD'), // # default blank //ssl: true, //# default false use https //url: "/my/other/url" // # default '/transmission/rpc' };