Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/refactor nest #60

Merged
merged 11 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
!package.json
!package-lock.json
!tsconfig.json
!tsconfig.build.json
!jest.config.ts
!common/
!websocket/
!packages/
!packages/
!src/
!nest-cli.json
40 changes: 19 additions & 21 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
env: {
browser: true,
es2021: true
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
overrides: [
{
env: {
node: true
},
files: ['.eslintrc.{js,cjs}'],
parserOptions: {
sourceType: 'script'
}
}
plugins: ['@typescript-eslint/eslint-plugin', 'prefer-arrow-functions'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module'
root: true,
env: {
node: true,
jest: true,
},
plugins: ['@typescript-eslint', 'prefer-arrow-functions', 'prettier'],
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',

'@typescript-eslint/consistent-type-imports': 'warn',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-redeclare': 'off',
Expand All @@ -40,5 +38,5 @@ module.exports = {
singleReturnOnly: false
}
]
}
}
},
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ utils-old/
coverage/
_depricated/
_deprecated/
_deprecated_*/

### Terraform ###
# Local .terraform directories
Expand Down
4 changes: 2 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"semi": false,
"trailingComma": "none",
"singleQuote": true,
"trailingComma": "all",
"semi": false,
"printWidth": 100
}
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM node:20-bookworm

WORKDIR /app

COPY ./package*.json ./

USER root

RUN npm install -g npm && \
npm install -g typescript && \
npm install

COPY ./tsconfig*.json ./
COPY ./nest-cli.json ./
COPY ./src ./src

RUN npm run build

# RUN adduser --no-create-home --system --disabled-password --disabled-login --group app-user && \
# mkdir -p /vol/web/media && \
# mkdir -p /vol/web/static && \
# mkdir -p /app/dist && \
# chown -R app-user:app-user /vol && \
# chmod -R 755 /vol/web && \
# chown -R app-user:app-user /app/dist && \
# chmod -R 755 /app/dist

# USER app-user
EXPOSE 8000
VOLUME ["/app/src"]

CMD ["npm", "run", "start:prod"]
54 changes: 15 additions & 39 deletions docker-compose.network.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ services:
restart: always
build:
context: .
# dockerfile: ./server.Dockerfile
dockerfile: ./server/Dockerfile
container_name: server-jbx
networks:
- cluster
environment:
- NODE_ENV=network
- PORT=9000
Expand All @@ -24,11 +24,9 @@ services:
- mongodb
- kafka
volumes:
- ./server:/app/server
- ./packages:/app/packages
networks:
- cluster
command: npm run dev:server
- ./src:/app/src
- ./package.json:/app/package.json
command: npm run start:network

proxy:
build:
Expand All @@ -41,10 +39,13 @@ services:
- server
volumes:
- client-dist:/vol/client
- club-static:/vol/static
environment:
- SERVER_URI=server-jbx:9000
- WEBSOCKET_URI=websocket-jbx:9001
attach: false
- WEBSOCKET_URI=server-jbx:9000
- CLUB_MANAGER_URI=club-app-network:9000

# attach: false

mongodb:
image: mongo:6.0.9
Expand All @@ -60,7 +61,7 @@ services:
command: mongod --quiet --logpath /dev/null --bind_ip_all
networks:
- cluster

####################################
# Kafka Config
####################################
Expand Down Expand Up @@ -96,7 +97,7 @@ services:
networks:
- cluster
attach: false

kafka-api:
image: 'docker-spring-boot-postgres:latest'
build:
Expand All @@ -108,39 +109,14 @@ services:
- SPRING_PROFILES_ACTIVE=dev
depends_on:
- kafka

####################################
# Web Socket Config
####################################
websocket:
build:
context: ./
dockerfile: ./websocket/Dockerfile
restart: always
ports:
- 9001:9001
container_name: websocket-jbx
volumes:
- ./websocket:/app/websocket
- ./packages:/app/packages
- ./package.json:/app/package.json
environment:
- HOST=0.0.0.0
- PORT=9001
- NODE_ENV=network
- LOG_LEVEL=debug
- KAFKA_BROKERS=kafka-jbx:9092
- KAFKA_GROUP_ID=websocket-jbx
- LOG_NS=websocket
# - BYPASS_AUTH=1
command: npm run dev:websocket
networks:
- cluster

volumes:
client-dist:
name: client-dist
mongo-data:
club-static:
name: club-static
# external: true

networks:
cluster:
Expand Down
60 changes: 0 additions & 60 deletions docker-compose.prod.yml

This file was deleted.

15 changes: 6 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ services:
server:
restart: always
build:
context: ./
dockerfile: ./server/Dockerfile
context: .
args:
- NODE_ENV=development
- NODE_ENV=dev
environment:
- NODE_ENV=development
- NODE_ENV=dev
- PORT=8000
- HOST=localhost
- JWT_SECRET_KEY=changeme
Expand All @@ -26,11 +25,9 @@ services:
depends_on:
- mongodb
volumes:
- ./server:/app/server
- ./jest.config.ts:/app/jest.config.ts
- ./packages:/app/packages
# - ./dist:/app/dist
command: npm run dev
- ./src:/app/src
- ./package.json:/app/package.json
command: npm run start:dev

mongodb:
image: mongo:6.0.9
Expand Down
52 changes: 52 additions & 0 deletions docs/Network-Mode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Working in Network Mode

## Helpful Commands

To run all of the services in docker-compose.network:

```sh
docker-compose -f docker-compose.network.yml up
```

When working with NGINX, you will often need to restart it after each edit, so this would ideally run separate. The suggested solution is to run the Jukebox server independent of the proxy container. In one terminal run:

```sh
docker-compose -f docker-compose.network.yml up server
```

and in another terminal run:

```sh
docker-compose -f docker-compose.network.yml up proxy
```

This allows you to restart the proxy after changes using:

```sh
docker-compose -f docker-compose.network.yml up proxy --build --force-recreate
```

### When Running with Club Manager Repo

Start the services in this order:

1. Start jukebox server

```sh
# dir: Jukebox-Server/
docker-compose -f docker-compose.network.yml up server
```

2. Start Club Manager

```sh
# dir: Club-Manager/
docker-compose -f docker-compose.network.yml up
```

3. Start Proxy

```sh
# dir: Jukebox-Server/
docker-compose -f docker-compose.network.yml up proxy --build --force-recreate
```
24 changes: 24 additions & 0 deletions docs/Project-Structure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Project Structure

```txt
jukebox-server/
|-- proxy/
|-- deploy/
|-- src
|-- [module]/
| |-- [module].module.ts <-- Module root
| |-- [module].controller.ts <-- Api routes defined, no business logic
| |-- [module].service.ts <-- Business logic
| |-- [module].gateway.ts <-- Websocket input/output router, no business logic
| |-- tests/
| | |-- [module].[type].spec.ts
| |-- dto/
| | |-- [model].dto.ts <-- Api input/output object structures
| |-- schemas/
| | |-- [model].schema.ts <-- Mongoose schemas
|-- spotify/
| |-- *
|-- track-queue/
| |-- *

```
Loading