Skip to content

Commit

Permalink
fix(website): fix deps + builds
Browse files Browse the repository at this point in the history
  • Loading branch information
marcj committed Mar 19, 2024
1 parent 107399a commit 4183580
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 110 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
@@ -1,2 +1,5 @@
node_modules
dist
.angular
.dockerignore
Dockerfile
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -32,7 +32,7 @@
"devDependencies": {
"@commitlint/config-conventional": "^18.4.3",
"@commitlint/config-lerna-scopes": "^18.4.4",
"@deepkit/core": "^1.0.1-alpha.13",
"@deepkit/core": "^1.0.1-alpha.143",
"@jest/globals": "^29.2.1",
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/node": "20.6.0",
Expand Down
16 changes: 10 additions & 6 deletions website/Dockerfile
Expand Up @@ -5,9 +5,11 @@ RUN mkdir /app/
WORKDIR /app

ADD package.json /app/package.json
ADD package-lock.json /app/package-lock.json
RUN npm ci
ADD . /app
ADD .yarnrc.yml yarn.lock /app/
ADD .yarn /app/.yarn
ADD website/package.json /app/website/package.json
RUN yarn workspaces focus website
ADD website/ /app
RUN npm run build

FROM node:20.8.0-alpine3.18
Expand All @@ -20,12 +22,14 @@ RUN mkdir /app/
WORKDIR /app

ADD package.json /app/package.json
ADD package-lock.json /app/package-lock.json
RUN npm ci --production
ADD .yarnrc.yml yarn.lock /app/
ADD .yarn /app/.yarn
ADD website/package.json /app/website/package.json
RUN yarn workspaces focus website --production

COPY --from=0 /app/dist /app/dist
COPY --from=0 /app/src /app/src

ADD docker_start.sh /start.sh
ADD website/docker_start.sh /start.sh

CMD sh /start.sh
10 changes: 10 additions & 0 deletions website/README.md
Expand Up @@ -23,3 +23,13 @@ npm run app:build
npm run ssr:build
npm run server
``
## Build Docker image
```
cd website/
docker build -t website2 -f Dockerfile ../
docker run -p 8080:8080 -e app_databaseHost=host.docker.internal website2
```
27 changes: 19 additions & 8 deletions website/docker-compose.yml
@@ -1,11 +1,22 @@
# docker run -d --rm --name bench-postgres -d -e POSTGRES_PASSWORD=password -e POSTGRES_HOST_AUTH_METHOD=trust -p 127.0.0.1:5432:5432 postgres:13.4

services:
postgres:
image: postgres:13.4
ports:
- "5433:5432"
environment:
POSTGRES_PASSWORD: password
POSTGRES_DB: deepkit-website
POSTGRES_HOST_AUTH_METHOD: trust
website:
build:
context: ../
dockerfile: Dockerfile
ports:
- "8080:8008"
environment:
DATABASE_URL: postgres://postgres:password@localhost:5433/deepkit-website
depends_on:
- postgres

postgres:
image: postgres:13.4
ports:
- "5433:5432"
environment:
POSTGRES_PASSWORD: password
POSTGRES_DB: deepkit-website
POSTGRES_HOST_AUTH_METHOD: trust
36 changes: 22 additions & 14 deletions website/package.json
Expand Up @@ -22,20 +22,28 @@
"private": true,
"dependencies": {
"@angular/ssr": "^17.1.0",
"@deepkit/app": "^1.0.1-alpha.102",
"@deepkit/core": "^1.0.1-alpha.100",
"@deepkit/desktop-ui": "^1.0.1-alpha.102",
"@deepkit/event": "^1.0.1-alpha.102",
"@deepkit/framework": "^1.0.1-alpha.103",
"@deepkit/http": "^1.0.1-alpha.102",
"@deepkit/injector": "^1.0.1-alpha.102",
"@deepkit/logger": "^1.0.1-alpha.102",
"@deepkit/mongo": "^1.0.1-alpha.103",
"@deepkit/orm": "^1.0.1-alpha.102",
"@deepkit/postgres": "^1.0.1-alpha.103",
"@deepkit/rpc": "^1.0.1-alpha.102",
"@deepkit/sql": "^1.0.1-alpha.103",
"@deepkit/type": "^1.0.1-alpha.102",
"@deepkit/app": "^1.0.1-alpha.143",
"@deepkit/broker": "^1.0.1-alpha.143",
"@deepkit/bson": "^1.0.1-alpha.143",
"@deepkit/core": "^1.0.1-alpha.143",
"@deepkit/core-rxjs": "^1.0.1-alpha.143",
"@deepkit/desktop-ui": "^1.0.1-alpha.143",
"@deepkit/event": "^1.0.1-alpha.143",
"@deepkit/filesystem": "^1.0.1-alpha.143",
"@deepkit/framework": "^1.0.1-alpha.143",
"@deepkit/http": "^1.0.1-alpha.143",
"@deepkit/injector": "^1.0.1-alpha.143",
"@deepkit/logger": "^1.0.1-alpha.143",
"@deepkit/mongo": "^1.0.1-alpha.143",
"@deepkit/orm": "^1.0.1-alpha.143",
"@deepkit/postgres": "^1.0.1-alpha.143",
"@deepkit/rpc": "^1.0.1-alpha.143",
"@deepkit/rpc-tcp": "^1.0.1-alpha.143",
"@deepkit/sql": "^1.0.1-alpha.143",
"@deepkit/stopwatch": "^1.0.1-alpha.143",
"@deepkit/template": "^1.0.1-alpha.143",
"@deepkit/type": "^1.0.1-alpha.143",
"@deepkit/workflow": "^1.0.1-alpha.143",
"angular-plotly.js": "^5.2.2",
"discord.js": "^14.13.0",
"gray-matter": "^4.0.3",
Expand Down
104 changes: 58 additions & 46 deletions website/src/server/app.ts
Expand Up @@ -5,26 +5,32 @@ import { MainController } from '@app/server/controller/main.controller';
import { AngularListener } from '@app/server/angular';
import { serveStaticListener } from '@deepkit/http';
import { join } from 'path';
import { Search } from "@app/server/search";
import { OpenAI } from "openai";
import { fineTuneTest1, fineTuneTest1Check, fineTuneTest1Model, mlGenAnswerCommand, mlGenQuestionCommand } from "@app/server/commands/ml-fine-tuning";
import { WebController } from "@app/server/controller/web.controller";
import { PageProcessor } from "@app/server/page-processor";
import { Questions, testQuestions, testTestFunction } from "@app/server/questions";
import { registerBot } from "@app/server/commands/discord";
import { MainDatabase } from "@app/server/database";
import { Database } from "@deepkit/orm";
import { Client, GatewayIntentBits, Partials } from "discord.js";
import { Url } from "@app/server/url";
import { MarkdownParser } from "@app/common/markdown";
import { migrate } from "@app/server/commands/migrate";
import { importExamples, importQuestions } from "@app/server/commands/import";
import { BenchmarkController, BenchmarkHttpController } from "@app/server/controller/benchmark.controller";
import { Search } from '@app/server/search';
import { OpenAI } from 'openai';
import {
fineTuneTest1,
fineTuneTest1Check,
fineTuneTest1Model,
mlGenAnswerCommand,
mlGenQuestionCommand,
} from '@app/server/commands/ml-fine-tuning';
import { WebController } from '@app/server/controller/web.controller';
import { PageProcessor } from '@app/server/page-processor';
import { Questions, testQuestions, testTestFunction } from '@app/server/questions';
import { registerBot } from '@app/server/commands/discord';
import { MainDatabase } from '@app/server/database';
import { Database } from '@deepkit/orm';
import { Client, GatewayIntentBits, Partials } from 'discord.js';
import { Url } from '@app/server/url';
import { MarkdownParser } from '@app/common/markdown';
import { migrate } from '@app/server/commands/migrate';
import { importExamples, importQuestions } from '@app/server/commands/import';
import { BenchmarkController, BenchmarkHttpController } from '@app/server/controller/benchmark.controller';

(global as any).window = undefined;
(global as any).document = undefined;

new App({
const app = new App({
config: AppConfig,
controllers: [
MainController,
Expand All @@ -45,7 +51,7 @@ new App({
{
provide: OpenAI, useFactory(openaiApiKey: AppConfig['openaiApiKey']) {
return new OpenAI({ apiKey: openaiApiKey });
}
},
},
{
provide: Client, useFactory() {
Expand All @@ -59,36 +65,42 @@ new App({
GatewayIntentBits.GuildMessageReactions,
],
});
}
}
},
},
],
imports: [
new FrameworkModule({
migrateOnStartup: true, //yolo
})
]
})
.command('search:index', async (search: Search) => await search.index())
.command('search:find', async (query: string, search: Search) => {
console.log(await search.find(query));
})
.command('ml:gen-questions', mlGenQuestionCommand)
.command('ml:gen-answers', mlGenAnswerCommand)
.command('ml:test', testTestFunction)
.command('ml:q', testQuestions)
.command('ml:fine-tune', fineTuneTest1)
.command('ml:fine-tune:check', fineTuneTest1Check)
.command('ml:fine-tune:model', fineTuneTest1Model)
.command('import:questions', importQuestions)
.command('import:examples', importExamples)
.command('migrate', migrate)
.listen(onServerMainBootstrap, registerBot)
.listen(onAppExecute, (event, parser: MarkdownParser) => parser.load())
.loadConfigFromEnv({ namingStrategy: 'same', prefix: 'app_', envFilePath: ['local.env'] })
.setup((module) => {
const assets = findParentPath('dist/', __dirname);
if (assets) {
module.addListener(serveStaticListener(module, '/', join(assets, 'app/browser')));
}
})
.run();
}),
],
});


app.command('search:index', async (search: Search) => await search.index());
app.command('search:find', async (query: string, search: Search) => {
console.log(await search.find(query));
});
app.command('ml:gen-questions', mlGenQuestionCommand);
app.command('ml:gen-answers', mlGenAnswerCommand);
app.command('ml:test', testTestFunction);
app.command('ml:q', testQuestions);
app.command('ml:fine-tune', fineTuneTest1);
app.command('ml:fine-tune:check', fineTuneTest1Check);
app.command('ml:fine-tune:model', fineTuneTest1Model);
app.command('import:questions', importQuestions);
app.command('import:examples', importExamples);
app.command('migrate', migrate);

app.listen(onServerMainBootstrap, registerBot);
app.listen(onAppExecute, (event, parser: MarkdownParser) => parser.load());

app.loadConfigFromEnv({ namingStrategy: 'same', prefix: 'app_', envFilePath: ['local.env'] });

app.setup((module) => {
const assets = findParentPath('dist/', __dirname);
if (assets) {
module.addListener(serveStaticListener(module, '/', join(assets, 'app/browser')));
}
});

void app.run();
12 changes: 6 additions & 6 deletions website/src/server/search.ts
@@ -1,11 +1,11 @@
// import algoliasearch, { SearchClient } from 'algoliasearch';
// import { AppConfig } from "@app/server/config";
import { findParentPath } from "@deepkit/app";
import { findParentPath } from '@deepkit/app';
import glob from 'tiny-glob';
import { bodyToString, CommunityMessage, DocPageContent, Page, projectMap } from "@app/common/models";
import { PageProcessor } from "@app/server/page-processor";
import { Database } from "@deepkit/orm";
import { sql } from "@deepkit/sql";
import { bodyToString, CommunityMessage, DocPageContent, Page, projectMap } from '@app/common/models';
import { PageProcessor } from '@app/server/page-processor';
import { Database } from '@deepkit/orm';
import { sql } from '@deepkit/sql';

function createIndexEntriesForPage(page: Page, rootPath: string = ''): DocPageContent[] {
const entries: DocPageContent[] = [];
Expand Down Expand Up @@ -107,7 +107,7 @@ ORDER BY rank DESC;
await this.database.query(DocPageContent).deleteMany();

//go through all .md files in src/pages
const pagesDir = findParentPath('src/pages');
const pagesDir = findParentPath('src/pages', process.cwd());
if (!pagesDir) throw new Error('Could not find pages directory');

const files = await glob('**/*.md', { cwd: pagesDir });
Expand Down

0 comments on commit 4183580

Please sign in to comment.