diff --git a/Dockerfile b/Dockerfile index 8cf94bf..7f5b2ab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:13 +FROM node:20 WORKDIR /usr/app @@ -8,9 +8,8 @@ RUN npm install COPY . . -RUN npm run build:docker - EXPOSE 8080 EXPOSE 3000 +EXPOSE 5173 -CMD [ "npm", "run", "start"] \ No newline at end of file +CMD [ "npm", "run", "dev"] \ No newline at end of file diff --git a/backend/enviroment/env.ts b/backend/enviroment/env.ts index 10f05bf..dcfbc46 100644 --- a/backend/enviroment/env.ts +++ b/backend/enviroment/env.ts @@ -30,6 +30,7 @@ export default { tempVideoThumbnailLimit: process.env.TEMP_VIDEO_THUMBNAIL_LIMIT ? +process.env.TEMP_VIDEO_THUMBNAIL_LIMIT : 0, + docker: process.env.DOCKER === "true", }; module.exports = { @@ -64,4 +65,5 @@ module.exports = { tempVideoThumbnailLimit: process.env.TEMP_VIDEO_THUMBNAIL_LIMIT ? +process.env.TEMP_VIDEO_THUMBNAIL_LIMIT : 0, + docker: process.env.DOCKER === "true", }; diff --git a/backend/services/chunk-service/actions/file-system-actions.ts b/backend/services/chunk-service/actions/file-system-actions.ts index f184c34..619d3fa 100644 --- a/backend/services/chunk-service/actions/file-system-actions.ts +++ b/backend/services/chunk-service/actions/file-system-actions.ts @@ -2,6 +2,7 @@ import fs from "fs"; import { UserInterface } from "../../../models/user-model"; import { GenericParams, IStorageActions } from "../store-types"; import env from "../../../enviroment/env"; +import { getFSStoragePath } from "../../../utils/getFSStoragePath"; class FilesystemActions implements IStorageActions { async getAuth() { @@ -60,7 +61,7 @@ class FilesystemActions implements IStorageActions { stream: NodeJS.ReadableStream, randomID: string ) => { - const path = `${env.fsDirectory}${randomID}`; + const path = `${getFSStoragePath()}${randomID}`; return { writeStream: fs.createWriteStream(path), emitter: null, diff --git a/backend/services/chunk-service/utils/createImageThumbnail.ts b/backend/services/chunk-service/utils/createImageThumbnail.ts index 40ca2c0..3050649 100644 --- a/backend/services/chunk-service/utils/createImageThumbnail.ts +++ b/backend/services/chunk-service/utils/createImageThumbnail.ts @@ -11,6 +11,7 @@ import { FilesystemActions } from "../actions/file-system-actions"; import { EventEmitter } from "stream"; import FileDB from "../../../db/mongoDB/fileDB"; import { getStorageActions } from "../actions/helper-actions"; +import { getFSStoragePath } from "../../../utils/getFSStoragePath"; const fileDB = new FileDB(); @@ -58,7 +59,7 @@ const processData = ( name: filename, owner: user._id, IV: thumbnailIV, - path: env.fsDirectory + thumbnailFilename, + path: getFSStoragePath() + thumbnailFilename, s3ID: thumbnailFilename, }); diff --git a/backend/services/chunk-service/utils/createVideoThumbnail.ts b/backend/services/chunk-service/utils/createVideoThumbnail.ts index dbeebc0..796655b 100644 --- a/backend/services/chunk-service/utils/createVideoThumbnail.ts +++ b/backend/services/chunk-service/utils/createVideoThumbnail.ts @@ -15,6 +15,7 @@ import { S3Actions } from "../actions/S3-actions"; import { FilesystemActions } from "../actions/file-system-actions"; import { createGenericParams } from "./storageHelper"; import { getStorageActions } from "../actions/helper-actions"; +import { getFSStoragePath } from "../../../utils/getFSStoragePath"; const storageActions = getStorageActions(); @@ -24,7 +25,7 @@ const attemptToRemoveChunks = async ( ) => { try { const readStreamParams = createGenericParams({ - filePath: env.fsDirectory + thumbnailFilename, + filePath: getFSStoragePath() + thumbnailFilename, Key: thumbnailFilename, }); await storageActions.removeChunks(readStreamParams); @@ -98,7 +99,7 @@ const createVideoThumbnail = ( name: filename, owner: user._id, IV: thumbnailIV, - path: env.fsDirectory + thumbnailFilename, + path: getFSStoragePath() + thumbnailFilename, s3ID: thumbnailFilename, }); diff --git a/backend/services/chunk-service/utils/getBusboyData.ts b/backend/services/chunk-service/utils/getBusboyData.ts index 743f4b9..44c9f4e 100644 --- a/backend/services/chunk-service/utils/getBusboyData.ts +++ b/backend/services/chunk-service/utils/getBusboyData.ts @@ -15,6 +15,7 @@ import videoChecker from "../../../utils/videoChecker"; import createVideoThumbnail from "./createVideoThumbnail"; import createThumbnail from "./createImageThumbnail"; import { RequestTypeFullUser } from "../../../controllers/file-controller"; +import { getFSStoragePath } from "../../../utils/getFSStoragePath"; // TODO: We should stop using moongoose directly here, // Also in our fileDB make sure we are actually using File instead @@ -115,7 +116,7 @@ const processData = ( } as FileMetadateInterface; if (env.dbType === "fs") { - metadata.filePath = env.fsDirectory + randomFilenameID; + metadata.filePath = getFSStoragePath() + randomFilenameID; } else { metadata.s3ID = randomFilenameID; } diff --git a/backend/services/chunk-service/utils/getFolderUploadBusboyData.ts b/backend/services/chunk-service/utils/getFolderUploadBusboyData.ts index 92a17df..82b4c66 100644 --- a/backend/services/chunk-service/utils/getFolderUploadBusboyData.ts +++ b/backend/services/chunk-service/utils/getFolderUploadBusboyData.ts @@ -18,6 +18,7 @@ import createThumbnail from "./createImageThumbnail"; import { EventEmitter } from "events"; import { getStorageActions } from "../actions/helper-actions"; import { RequestTypeFullUser } from "../../../controllers/file-controller"; +import { getFSStoragePath } from "../../../utils/getFSStoragePath"; type FileDataType = { name: string; @@ -133,7 +134,7 @@ const processData = ( } as FileMetadateInterface; if (env.dbType === "fs") { - metadata.filePath = env.fsDirectory + randomFilenameID; + metadata.filePath = getFSStoragePath() + randomFilenameID; } else { metadata.s3ID = randomFilenameID; } diff --git a/backend/services/chunk-service/utils/storageHelper.ts b/backend/services/chunk-service/utils/storageHelper.ts index 127d9a8..e29f912 100644 --- a/backend/services/chunk-service/utils/storageHelper.ts +++ b/backend/services/chunk-service/utils/storageHelper.ts @@ -1,4 +1,5 @@ import env from "../../../enviroment/env"; +import { getFSStoragePath } from "../../../utils/getFSStoragePath"; type GenericParmasType = { filePath?: string; @@ -13,11 +14,11 @@ export const createGenericParams = ({ filePath, Key }: GenericParmasType) => { const filePathSplit = filePath!.split("/"); const fileName = filePathSplit[filePathSplit.length - 1]; return { - filePath: env.fsDirectory + fileName, + filePath: getFSStoragePath() + fileName, }; } else { return { - filePath: env.fsDirectory + Key!, + filePath: getFSStoragePath() + Key!, }; } } else { diff --git a/backend/services/chunk-service/utils/tempCreateVideoThumbnail.ts b/backend/services/chunk-service/utils/tempCreateVideoThumbnail.ts index 330ea79..6459c49 100644 --- a/backend/services/chunk-service/utils/tempCreateVideoThumbnail.ts +++ b/backend/services/chunk-service/utils/tempCreateVideoThumbnail.ts @@ -14,6 +14,7 @@ import { S3Actions } from "../actions/S3-actions"; import { FilesystemActions } from "../actions/file-system-actions"; import { createGenericParams } from "./storageHelper"; import { getStorageActions } from "../actions/helper-actions"; +import { getFSStoragePath } from "../../../utils/getFSStoragePath"; const storageActions = getStorageActions(); @@ -73,7 +74,7 @@ const tempCreateVideoThumbnail = ( name: filename, owner: user._id, IV: thumbnailIV, - path: env.fsDirectory + thumbnailFilename, + path: getFSStoragePath() + thumbnailFilename, s3ID: thumbnailFilename, }); diff --git a/backend/utils/getFSStoragePath.ts b/backend/utils/getFSStoragePath.ts new file mode 100644 index 0000000..296d8eb --- /dev/null +++ b/backend/utils/getFSStoragePath.ts @@ -0,0 +1,9 @@ +import env from "../enviroment/env"; + +export const getFSStoragePath = () => { + if (env.docker) { + return "/data/"; + } else { + return env.fsDirectory; + } +}; diff --git a/docker-compose-no-mongo.yml b/docker-compose-no-mongo.yml deleted file mode 100644 index 2d89b36..0000000 --- a/docker-compose-no-mongo.yml +++ /dev/null @@ -1,13 +0,0 @@ -version: '3' - -services: - app: - container_name: mydrive-node-no-mongo - restart: always - build: . - ports: - - '3000:3000' - - '8080:8080' - env_file: - - docker-variables.env - \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index e57c087..77cb926 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,24 +1,18 @@ -version: '3' - +version: "3.8" services: app: - container_name: mydrive-node - restart: always - build: . - ports: - - '3000:3000' - - '8080:8080' + build: + context: . + dockerfile: Dockerfile env_file: - - docker-variables.env - links: - - mongo - mongo: - container_name: mongo - image: mongo - ports: - - '27017:27017' + - ./backend/config/.env.development volumes: - - 'mongodb_data_volume:/data/db' -volumes: - mongodb_data_volume: - external: true \ No newline at end of file + - .:/usr/app + - /usr/app/node_modules + - ${FS_DIRECTORY}:/data + ports: + - "3000:3000" + - "8080:8080" + - "5173:5173" + environment: + - DOCKER=true diff --git a/package.json b/package.json index 1ad6632..1453456 100755 --- a/package.json +++ b/package.json @@ -18,7 +18,9 @@ "create-video-thumbnails:dev": "NODE_ENV=development node serverUtils/createVideoThumbnails.js", "migrate-to-mydrive4": "NODE_ENV=production node serverUtils/migrateMyDrive4.js", "migrate-to-mydrive4:dev": "NODE_ENV=development node serverUtils/migrateMyDrive4.js", - "test": "NODE_ENV=test jest" + "test": "NODE_ENV=test jest", + "docker:dev": "docker-compose -f docker-compose.yml --env-file ./backend/config/.env.development up", + "docker:down": "docker-compose down" }, "dependencies": { "@babel/core": "^7.8.4", diff --git a/tests/utils/db-setup.js b/tests/utils/db-setup.js index 83d8d19..69c8b81 100644 --- a/tests/utils/db-setup.js +++ b/tests/utils/db-setup.js @@ -41,6 +41,7 @@ const envFileFix = (env) => { env.tempVideoThumbnailLimit = process.env.TEMP_VIDEO_THUMBNAIL_LIMIT ? +process.env.TEMP_VIDEO_THUMBNAIL_LIMIT : 0; + env.docker = process.env.DOCKER === "true"; }; module.exports = {