Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/clever/master' into feat/b…
Browse files Browse the repository at this point in the history
…ack-deploy
  • Loading branch information
AleksanderNekr committed Jun 23, 2024
2 parents 78ef534 + d3b308f commit e5253d6
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 90 deletions.
29 changes: 29 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.next
**/.cache
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
**/build
**/dist
LICENSE
README.md
node_modules/
10 changes: 9 additions & 1 deletion backend/src/config/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@ import * as fs from "fs";

export class Config {
dbHost: string;
dbPort: number;
dbUsername: string;
dbPass: string;
dbName: string;
privateKeyPath: string;
publicKeyPath: string;
frontendURL: string;

constructor() {
this.dbHost = process.env.DB_HOST || "";
this.dbPort = process.env.DB_PORT || "";
this.dbUsername = process.env.DB_USERNAME || "";
this.dbPass = process.env.DB_PASS || "";
this.dbName = process.env.DB_NAME || "";
this.privateKeyPath = process.env.PRIVATE_KEY_PATH || "";
this.publicKeyPath = process.env.PUBLIC_KEY_PATH || "";
this.frontendURL = process.env.FRONTEND_URL || "";
this.frontendURL = "https://train-platform.vercel.app";
}

readPrivateKey(): string {
Expand Down
8 changes: 4 additions & 4 deletions backend/src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { config } from "./config/Config";
export const AppDataSource = new DataSource({
type: "postgres",
host: config.dbHost,
port: 5432,
username: "postgres",
password: "postgres",
database: "courses",
port: config.dbPort,
username: config.dbUsername,
password: config.dbPass,
database: config.dbName,
synchronize: true, // TODO(db): disable at production code
logging: false,
entities: ["**/entity/*.ts"],
Expand Down
1 change: 0 additions & 1 deletion backend/src/entity/Course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
ManyToOne,
} from "typeorm";
import { CoursesModule } from "./CoursesModules";
import { CoursesStep } from "./CoursesStep";
import { CoursesViewer } from "./CoursesViewers";

@Entity("courses")
Expand Down
6 changes: 0 additions & 6 deletions backend/src/entity/CoursesModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ export class CoursesModule extends BaseEntity {
@Column("text")
description: string | undefined;

@Column({ default: false, type: "boolean" })
isVisible: boolean | undefined;

@Column({ type: "integer" })
moduleNumber: number | undefined;

@ManyToOne(() => Course, (course) => course.modules)
course: Course;

Expand Down
10 changes: 0 additions & 10 deletions backend/src/entity/CoursesStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
PrimaryGeneratedColumn,
} from "typeorm";
import { CoursesModule } from "./CoursesModules";
import { UsersActivity } from "./UsersActivity";

@Entity("courses_steps")
export class CoursesStep extends BaseEntity {
Expand All @@ -26,21 +25,12 @@ export class CoursesStep extends BaseEntity {
@Column({ nullable: true, type: "text" })
youtubeVideoLink: string | undefined;

@Column({ default: false, type: "boolean" })
isVisible: boolean | undefined;

@Column({ type: "integer" })
stepNumber: number | undefined;

@Column({ default: -1, type: "integer" })
deadline: number | undefined;

@Column({ default: 1, type: "integer" })
ratingAward: number | undefined;

@OneToMany(() => UsersActivity, (activity) => activity.step)
activities: UsersActivity[];

@ManyToOne(() => CoursesModule, (module) => module.steps)
module: CoursesModule;
}
7 changes: 0 additions & 7 deletions backend/src/entity/CoursesViewers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
OneToMany,
PrimaryGeneratedColumn,
} from "typeorm";
import { UsersRole } from "./UsersRoles";
import { Course } from "./Course";
import { User } from "./User";

Expand All @@ -20,12 +19,6 @@ export class CoursesViewer extends BaseEntity {
@Column({ type: "uuid" })
courseId: "uuid" | undefined;

@Column({ type: "uuid" })
roleId: "uuid" | undefined;

@OneToMany(() => UsersRole, (role) => role.viewer)
roles: UsersRole[];

@OneToMany(() => User, (user) => user.viewers)
user: User[];

Expand Down
8 changes: 0 additions & 8 deletions backend/src/entity/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ import {
Column,
Entity,
ManyToOne,
OneToMany,
PrimaryGeneratedColumn,
} from "typeorm";
import { UUID } from "crypto";
import { UsersActivity } from "./UsersActivity";
import { UsersRole } from "./UsersRoles";
import { Course } from "./Course";
import { CoursesViewer } from "./CoursesViewers";

@Entity("users")
Expand Down Expand Up @@ -49,9 +44,6 @@ export class User {
@Column({ type: "text", nullable: true })
healthIssues: string;

@OneToMany(() => UsersActivity, (activity) => activity.user)
activities: UsersActivity[];

@ManyToOne(() => CoursesViewer, (viewer) => viewer.user)
viewers: CoursesViewer;
}
30 changes: 0 additions & 30 deletions backend/src/entity/UsersActivity.ts

This file was deleted.

21 changes: 0 additions & 21 deletions backend/src/entity/UsersRoles.ts

This file was deleted.

5 changes: 3 additions & 2 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "./config/Config";
import { AppDataSource } from "./db";
import {app} from "./server";
import { config } from "typescript-eslint";

AppDataSource.initialize()
.then(async () => {
Expand All @@ -10,6 +11,6 @@ AppDataSource.initialize()
})
.catch((error) => console.log(error));

app.listen(3000, () => {
console.log(`Backend node app listening on port ${3000}`);
app.listen(8080, () => {
console.log(`Backend node app listening on port ${8080}`);
});
37 changes: 37 additions & 0 deletions cc-back.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
ARG NODE_VERSION=20.14.0

FROM node:${NODE_VERSION}-alpine

## Use production node environment by default.
#ENV NODE_ENV production

# Install pnpm and openssl.
RUN apk add --no-cache openssl \
&& npm install -g npm@latest

WORKDIR /usr/src/app

# Copy package.json and pnpm-lock.yaml
COPY backend/package.json ./package.json
COPY backend/pnpm-lock.yaml ./pnpm-lock.yaml

# Install dependencies
RUN npm i --frozen-lockfile --force

# Generate RSA keys in src/config
RUN mkdir -p src/config \
&& openssl genpkey -algorithm RSA -out src/config/private.pem -pkeyopt rsa_keygen_bits:2048 \
&& openssl rsa -pubout -in src/config/private.pem -out src/config/public.pem \
&& chmod 644 src/config/private.pem src/config/public.pem

# Run the application as a non-root user.
USER node

# Copy the rest of the source files into the image.
COPY backend /usr/src/app

# Expose the port that the application listens on.
EXPOSE 8080

# Run the application.
CMD npm start
4 changes: 4 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ services:
- 3000:3000
environment:
DB_HOST: postgres
DB_PORT: 5432
DB_USERNAME: postgres
DB_PASS: postgres
DB_NAME: courses
PRIVATE_KEY_PATH: src/config/private.pem
PUBLIC_KEY_PATH: src/config/public.pem
FRONTEND_URL: "http://localhost:3001"
Expand Down

0 comments on commit e5253d6

Please sign in to comment.