dockerise server

This commit is contained in:
Jurgis Sakalauskas
2023-08-04 16:06:47 +03:00
parent 27f76a08f0
commit fe938afa3f
11 changed files with 81 additions and 28 deletions
+21 -13
View File
@@ -1,17 +1,25 @@
PORT=3000 PORT=3000
STATIC_SERVE_FOLDER="data/static"
LOG_FILE_REQUESTS="data/static/static_log.txt" STATIC_SERVE_FOLDER='/mnt/hdd/videos'
DB_PATH="./data/db/db.db" LOG_FILE_REQUESTS_FOLDER='/mnt/hdd/videos'
RECENT_SEARCHES_FOLDER="./data/recent_searches" 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 RECENT_SEARCHES_LIMIT=20
VIDEO_FILES_FOLDERS='[
"/home/user/videos", VIDEO_FILES_FOLDER='/mnt/hdd/videos' #also torrent download dir
"/mnt/hdd/videos"
]'
VIDEO_FILES_EXT='[".mkv", ".mp4", ".avi"]' VIDEO_FILES_EXT='[".mkv", ".mp4", ".avi"]'
PATTERNS_TO_IGNORE='["AOE1/"]' #file path patterns to ignore from video files scan PATTERNS_TO_IGNORE='["AOE1/"]' #file path patterns to ignore from video files scan
LINKOMANIJA_USERNAME=usern
LINKOMANIJA_PASSWORD=password LINKOMANIJA_USERNAME=user
LINKOMANIJA_PASSKEY=some123long321passkey LINKOMANIJA_PASSWORD=passw
TORRENT_DOWNLOAD_DIR='/mnt/hdd/videos' LINKOMANIJA_PASSKEY=123pass456key789
TRANSMISSION_CLIENT_HOST=192.168.1.133
TRANSMISSION_CLIENT_HOST=host.docker.internal
TRANSMISSION_CLIENT_USER=user
TRANSMISSION_CLIENT_PASSWORD=password
+17
View File
@@ -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"]
+19
View File
@@ -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"
+3
View File
@@ -0,0 +1,3 @@
**/node_modules
**/data
**/dist
+4 -1
View File
@@ -322,7 +322,10 @@ export class TorrentService {
const torrId = parseInt(id); const torrId = parseInt(id);
const result = await this.torrSeedClient const result = await this.torrSeedClient
.addTorrentById(torrId) .addTorrentById(torrId)
.catch(() => false); .catch((e) => {
console.log(e);
return false;
});
return new NotificationResponse( return new NotificationResponse(
result ? 'torrent added to transmission' : 'adding failed', result ? 'torrent added to transmission' : 'adding failed',
@@ -29,7 +29,10 @@ export class TorrentSeedClient {
return Promise.reject('torrent not found'); 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) { if (torrInfo) {
await this.torrentRepository.update( await this.torrentRepository.update(
+1 -1
View File
@@ -13,7 +13,7 @@ export class ConfigService {
private videoFilesConfig: VideoFilesConfig = new VideoFilesConfig(this); private videoFilesConfig: VideoFilesConfig = new VideoFilesConfig(this);
private recentSearches: RecentSearchesConfig = new RecentSearchesConfig(this); private recentSearches: RecentSearchesConfig = new RecentSearchesConfig(this);
public getEnv(key: string): any { public getEnv(key: string): string {
return process.env[key]; return process.env[key];
} }
+5 -2
View File
@@ -7,11 +7,14 @@ export class PathsConfig {
} }
public getStaticRequestsLogPath(): string { 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 { public getStaticFolder(): string {
return this.getPathByEnvKey('STATIC_SERVE_FOLDER'); return '/srv/data/static';
} }
public getPathByEnvKey(key: string) { public getPathByEnvKey(key: string) {
+1 -3
View File
@@ -6,9 +6,7 @@ export class RecentSearchesConfig {
} }
public getRecentSearchesFolder(): string { public getRecentSearchesFolder(): string {
return this.configService return '/srv/data/recent-searches';
.getPaths()
.getPathByEnvKey('RECENT_SEARCHES_FOLDER');
} }
public getRecentSearchesLimit(): number { public getRecentSearchesLimit(): number {
+2 -1
View File
@@ -4,11 +4,12 @@ import { EntityClassOrSchema } from '@nestjs/typeorm/dist/interfaces/entity-clas
import { TitleEntity } from '../Shared/Entity/title.entity'; import { TitleEntity } from '../Shared/Entity/title.entity';
import { FileEntity } from '../Shared/Entity/file.entity'; import { FileEntity } from '../Shared/Entity/file.entity';
import { TorrentEntity } from '../Shared/Entity/torrent.entity'; import { TorrentEntity } from '../Shared/Entity/torrent.entity';
import { join } from 'path';
export class TypeOrmConfig { export class TypeOrmConfig {
constructor(configService: ConfigService) { constructor(configService: ConfigService) {
this.type = 'sqlite'; 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]; this.entities = [LrtCategory, TitleEntity, FileEntity, TorrentEntity];
} }
type: 'sqlite'; type: 'sqlite';
+4 -6
View File
@@ -6,7 +6,7 @@ export class VideoFilesConfig {
} }
public getVideoFilesFolders(): string[] { public getVideoFilesFolders(): string[] {
return JSON.parse(this.configService.getEnv('VIDEO_FILES_FOLDERS')); return [this.configService.getEnv('VIDEO_FILES_FOLDER')];
} }
public getVideoFilesExt(): string[] { public getVideoFilesExt(): string[] {
@@ -18,17 +18,15 @@ export class VideoFilesConfig {
} }
public getTorrentDownloadDir(): string { public getTorrentDownloadDir(): string {
return this.configService return this.configService.getEnv('VIDEO_FILES_FOLDER');
.getPaths()
.getPathByEnvKey('TORRENT_DOWNLOAD_DIR');
} }
public getTransmissionOptions() { public getTransmissionOptions() {
return { return {
host: this.configService.getEnv('TRANSMISSION_CLIENT_HOST'), // # default 'localhost' host: this.configService.getEnv('TRANSMISSION_CLIENT_HOST'), // # default 'localhost'
//port: 9091, // # default 9091 //port: 9091, // # default 9091
//username: "username", // # default blank username: this.configService.getEnv('TRANSMISSION_CLIENT_USER'), // # default blank
//password: "password", // # default blank password: this.configService.getEnv('TRANSMISSION_CLIENT_PASSWORD'), // # default blank
//ssl: true, //# default false use https //ssl: true, //# default false use https
//url: "/my/other/url" // # default '/transmission/rpc' //url: "/my/other/url" // # default '/transmission/rpc'
}; };