From da76610fcee342c56cca5666b4ad9155a82c1a43 Mon Sep 17 00:00:00 2001 From: rubikscraft Date: Fri, 25 Feb 2022 13:56:16 +0100 Subject: [PATCH] add documentation and docker --- .dockerignore | 8 ++++++++ Dockerfile | 18 ++++++++++++++++++ README.md | 37 +++++++++++++++++++++++++++++++++++++ backend/src/env.ts | 29 +++++++++++++++++------------ backend/src/main.ts | 5 +++-- docker-compose.yml | 38 ++++++++++++++++++++++++++++++++++++++ frontend/public/image/logo | 2 +- workspace.code-workspace | 21 +++++++++++++++++++++ 8 files changed, 143 insertions(+), 15 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 workspace.code-workspace diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..173e8ce --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +node_modules +**/node_modules +dist +**/dist + +Dockerfile +docker-compose.yml +support diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2864b9c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM node:16-alpine + +ADD . /imagur +WORKDIR /imagur + +RUN yarn install --frozen-lockfile + +WORKDIR /imagur/shared +RUN yarn build + +WORKDIR /imagur/frontend +RUN yarn build + +WORKDIR /imagur/backend +RUN yarn build + +CMD ["yarn", "start:prod"] + diff --git a/README.md b/README.md index 77e4bb6..8cf7c77 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,40 @@ # Imagur > Totally not an imgur clone + +I couldn't really find any open source project that allowed you to easily host images. So I decided to create one. + +It works like a hybrid between imgur and pastebin. + +## Beta + +Right now this software is still in beta, and many things are still missing, or will be changed in the future. +But it does function, so feel free to give it a try. + +## Running + +To start Imagur easily, you can clone the repository and then run `docker-compose up -d`. It will then be running on port `8080`. + +## Configuration + +You can configure a couple different things using environment variables. Here is the current list with their default values: + +```txt +IMAGUR_HOST: '0.0.0.0' +IMAGUR_PORT: 8080 + +IMAGUR_DB_HOST: imagur_postgres +IMAGUR_DB_PORT: 5432 +IMAGUR_DB_USER: imagur +IMAGUR_DB_PASSWORD: imagur +IMAGUR_DB_NAME: imagur + +IMAGUR_ADMIN_USERNAME: imagur +IMAGUR_ADMIN_PASSWORD: imagur + +IMAGUR_JWT_SECRET: CHANGE_ME +IMAGUR_JWT_EXPIRY: 1d + +IMAGUR_MAX_FILE_SIZE: 128000000 +IMAGUR_STATIC_FRONTEND_ROOT: "/imagur/frontend/dist" +``` diff --git a/backend/src/env.ts b/backend/src/env.ts index d196773..448b24d 100644 --- a/backend/src/env.ts +++ b/backend/src/env.ts @@ -3,34 +3,39 @@ import { fileURLToPath } from 'url'; const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../'); const Config = { + host: process.env.IMAGUR_HOST || '0.0.0.0', + port: process.env.IMAGUR_PORT || 8080, database: { - host: process.env.DB_HOST ?? 'localhost', - port: process.env.DB_PORT ? parseInt(process.env.DB_PORT) : 5432, - username: process.env.DB_USERNAME ?? 'imagur', - password: process.env.DB_PASSWORD ?? 'imagur', - database: process.env.DB_DATABASE ?? 'imagur', + host: process.env.IMAGUR_DB_HOST ?? 'localhost', + port: process.env.IMAGUR_DB_PORT + ? parseInt(process.env.IMAGUR_DB_PORT) + : 5432, + username: process.env.IMAGUR_DB_USERNAME ?? 'imagur', + password: process.env.IMAGUR_DB_PASSWORD ?? 'imagur', + database: process.env.IMAGUR_DB_DATABASE ?? 'imagur', }, defaultAdmin: { - username: process.env.DEFAULT_ADMIN_USERNAME ?? 'admin', - password: process.env.DEFAULT_ADMIN_PASSWORD ?? 'admin', + username: process.env.IMAGUR_ADMIN_USERNAME ?? 'admin', + password: process.env.IMAGUR_ADMIN_PASSWORD ?? 'admin', }, jwt: { - secret: process.env.JWT_SECRET ?? 'CHANGE_ME', - expiresIn: process.env.JWT_EXPIRES_IN ?? '1d', + secret: process.env.IMAGUR_JWT_SECRET ?? 'CHANGE_ME', + expiresIn: process.env.IMAGUR_JWT_EXPIRES_IN ?? '1d', }, uploadLimits: { fieldNameSize: 128, fieldSize: 1024, fields: 16, files: 16, - fileSize: process.env.MAX_FILE_SIZE - ? parseInt(process.env.MAX_FILE_SIZE) + fileSize: process.env.IMAGUR_MAX_FILE_SIZE + ? parseInt(process.env.IMAGUR_MAX_FILE_SIZE) : 128000000, }, static: { packageRoot: packageRoot, frontendRoot: - process.env.STATIC_FRONTEND_ROOT ?? join(packageRoot, '../frontend/dist'), + process.env.IMAGUR_STATIC_FRONTEND_ROOT ?? + join(packageRoot, '../frontend/dist'), backendRoutes: ['i', 'api'], }, }; diff --git a/backend/src/main.ts b/backend/src/main.ts index a4f9764..0caf1a9 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -9,6 +9,7 @@ import { AppModule } from './app.module'; import * as multipart from 'fastify-multipart'; import { MainExceptionFilter } from './layers/http-exception/http-exception.filter'; import { SuccessInterceptor } from './layers/success/success.interceptor'; +import Config from './env'; async function bootstrap() { const fastifyAdapter = new FastifyAdapter(); @@ -18,12 +19,12 @@ async function bootstrap() { const app = await NestFactory.create( AppModule, - fastifyAdapter + fastifyAdapter, ); app.useGlobalFilters(new MainExceptionFilter()); app.useGlobalInterceptors(new SuccessInterceptor()); app.useGlobalPipes(new ValidationPipe({ disableErrorMessages: true })); - await app.listen(3000); + await app.listen(Config.port, Config.host); } bootstrap().catch(console.error); diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..549380e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,38 @@ +version: "3" +services: + imagur: + build: . + container_name: imagur + ports: + - "8080:8080" + environment: + # IMAGUR_HOST: '0.0.0.0' + # IMAGUR_PORT: 8080 + + IMAGUR_DB_HOST: imagur_postgres + # IMAGUR_DB_PORT: 5432 + # IMAGUR_DB_USER: imagur + # IMAGUR_DB_PASSWORD: imagur + # IMAGUR_DB_NAME: imagur + + # IMAGUR_ADMIN_USERNAME: imagur + # IMAGUR_ADMIN_PASSWORD: imagur + + # IMAGUR_JWT_SECRET: CHANGE_ME + # IMAGUR_JWT_EXPIRY: 1d + + # IMAGUR_MAX_FILE_SIZE: 128000000 + # IMAGUR_STATIC_FRONTEND_ROOT: "/imagur/frontend/dist" + restart: unless-stopped + imagur_postgres: + image: postgres:11-alpine + container_name: imagur_postgres + environment: + POSTGRES_DB: imagur + POSTGRES_PASSWORD: imagur + POSTGRES_USER: imagur + restart: unless-stopped + volumes: + - db-data:/var/lib/postgresql/data +volumes: + db-data: diff --git a/frontend/public/image/logo b/frontend/public/image/logo index 1dfef9c..ea5a0e3 120000 --- a/frontend/public/image/logo +++ b/frontend/public/image/logo @@ -1 +1 @@ -/home/rubikscraft/Documents/Projects/Imagur/Imagur-Monorepo/branding/logo \ No newline at end of file +../../../branding/logo/ \ No newline at end of file diff --git a/workspace.code-workspace b/workspace.code-workspace new file mode 100644 index 0000000..7ed508f --- /dev/null +++ b/workspace.code-workspace @@ -0,0 +1,21 @@ +{ + "folders": [ + { + "name": "shared", + "path": "shared" + }, + { + "name": "backend", + "path": "backend" + }, + { + "name": "frontend", + "path": "frontend" + }, + { + "name": "Imagur-Monorepo", + "path": "." + } + ], + "settings": {} +}