From 35688dd72c97800efb0600121b136c64fba1e51f Mon Sep 17 00:00:00 2001 From: Aleksi Lassila Date: Sat, 20 Apr 2024 02:38:30 +0300 Subject: [PATCH] fix: Docker compose build for production --- Dockerfile | 15 ++++++++++----- {config => backend/config}/.gitkeep | 0 backend/src/app.module.ts | 2 +- backend/src/database/database.providers.ts | 2 +- backend/src/main.ts | 4 ++-- docker-compose.yml | 2 +- src/App.svelte | 2 +- 7 files changed, 16 insertions(+), 11 deletions(-) rename {config => backend/config}/.gitkeep (100%) diff --git a/Dockerfile b/Dockerfile index 114a092..b38690f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,6 +12,10 @@ RUN npm i RUN npm run build +RUN npm i --prefix backend + +RUN npm run build --prefix backend + FROM --platform=linux/amd64 node:18-alpine as production RUN mkdir -p /usr/src/app @@ -19,10 +23,11 @@ WORKDIR /usr/src/app ENV NODE_ENV=production -COPY --from=pre-production /usr/src/app/build ./build +COPY --from=pre-production /usr/src/app/backend/dist ./dist +COPY --from=pre-production /usr/src/app/dist ./dist/dist -COPY package.json . -COPY package-lock.json . +COPY backend/package.json . +COPY backend/package-lock.json . RUN npm ci --omit dev @@ -30,7 +35,7 @@ RUN mkdir -p ./config RUN ln -s /usr/src/app/config /config -CMD [ "npm", "run", "deploy" ] +CMD [ "npm", "run", "start:prod" ] FROM node:18 as development @@ -48,4 +53,4 @@ RUN mkdir -p ./config RUN ln -s /usr/src/app/config /config -CMD [ "npm", "run", "dev" ] \ No newline at end of file +CMD [ "npm", "run", "dev" ] diff --git a/config/.gitkeep b/backend/config/.gitkeep similarity index 100% rename from config/.gitkeep rename to backend/config/.gitkeep diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index 7526283..e333a30 100644 --- a/backend/src/app.module.ts +++ b/backend/src/app.module.ts @@ -13,7 +13,7 @@ import { join } from 'path'; UserModule, AuthModule, ServeStaticModule.forRoot({ - rootPath: join(__dirname, '..', '..', 'dist'), + rootPath: join(__dirname, 'dist'), }), ], controllers: [AppController], diff --git a/backend/src/database/database.providers.ts b/backend/src/database/database.providers.ts index 75519ec..02e954b 100644 --- a/backend/src/database/database.providers.ts +++ b/backend/src/database/database.providers.ts @@ -8,7 +8,7 @@ export const databaseProviders = [ useFactory: async () => { const dataSource = new DataSource({ type: 'sqlite', - database: './reiverr.sqlite', + database: './config/reiverr.sqlite', entities: [__dirname + '/../**/*.entity{.ts,.js}'], synchronize: true, }); diff --git a/backend/src/main.ts b/backend/src/main.ts index c3768a8..83e3e91 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -3,7 +3,7 @@ import { AppModule } from './app.module'; import 'reflect-metadata'; import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; import * as fs from 'fs'; -import * as proxy from 'express-http-proxy'; +// import * as proxy from 'express-http-proxy'; async function bootstrap() { const app = await NestFactory.create(AppModule); @@ -20,6 +20,6 @@ async function bootstrap() { SwaggerModule.setup('openapi', app, document); fs.writeFileSync('./swagger-spec.json', JSON.stringify(document)); - await app.listen(3000); + await app.listen(9494); } bootstrap(); diff --git a/docker-compose.yml b/docker-compose.yml index e1bb6cf..542445e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,4 +8,4 @@ services: image: ghcr.io/aleksilassila/reiverr:latest restart: unless-stopped volumes: - - ./config:/config + - ./backend/config:/usr/src/app/config diff --git a/src/App.svelte b/src/App.svelte index a63eb7f..385274c 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -38,7 +38,7 @@ - + {#if $appState.user === undefined}