Skip to content

Commit

Permalink
feat: add docker implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Impeqq committed Jan 6, 2025
1 parent 18cfdcb commit c943a66
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 628 deletions.
15 changes: 15 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:14.13.0-alpine

WORKDIR /usr/src/app

COPY package.json yarn.lock ./

RUN yarn install --frozen-lockfile

COPY . .

RUN npm run build

EXPOSE 5432

CMD ["yarn", "start"]
12 changes: 0 additions & 12 deletions backend/docker-compose.yml

This file was deleted.

6 changes: 4 additions & 2 deletions backend/ormconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"type": "postgres",
"host": "localhost",
"host": "db",
"port": 5432,
"username": "postgres",
"password": "postgres",
"database": "space_db",
"synchronize": true,
"logging": false,
"entities": ["dist/**/*.entity.js"]
"entities": [
"dist/**/*.entity.js"
]
}
5 changes: 2 additions & 3 deletions backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import { graphqlUploadExpress } from 'graphql-upload';
import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors();
const app = await NestFactory.create(AppModule, { cors: true });
app.use(
graphqlUploadExpress({
maxFileSize: 100000000,
maxFiles: 2,
}),
);
await app.listen(5000);
await app.listen(3000);
}
bootstrap();
2 changes: 1 addition & 1 deletion backend/src/user/user.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Socket, Server } from 'socket.io';
import { UserService } from './user.service';
import { pubsub } from 'src/lib/pubsub';

@WebSocketGateway(5001, { cors: true })
@WebSocketGateway(3001, { cors: true })
export class UserGateway
implements OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect {
@WebSocketServer() server: Server;
Expand Down
31 changes: 31 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
services:
db:
container_name: messenger_database
image: postgres:13.4
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: space_db
api:
container_name: messenger_backend
image: api:1.0.0
build: './backend'
volumes:
- ./backend:/usr/src/app
ports:
- 3000:3000
- 3001:3001
depends_on:
- db
web:
container_name: messenger_frontend
image: web:1.0.0
build: './frontend'
volumes:
- ./frontend:/usr/src/app
ports:
- 8080:8080
- 9001:9001
depends_on:
- api

15 changes: 15 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:14.16.0-alpine

WORKDIR /usr/src/app

COPY package.json yarn.lock ./

RUN yarn install --frozen-lockfile

COPY . .

RUN npm run build

EXPOSE 8080

CMD ["yarn", "start"]
6 changes: 3 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"start": "webpack serve --config=./webpack.config.js",
"start": "webpack serve --host 0.0.0.0 --config=./webpack.config.js",
"build": "yarn eslint && webpack --config=./webpack.config.js",
"deploy": "yarn build && gh-pages -d dist"
},
Expand Down Expand Up @@ -68,10 +68,10 @@
"css-loader": "6.2.0",
"html-webpack-plugin": "5.5.0",
"mini-css-extract-plugin": "2.2.0",
"node-sass": "6.0.1",
"sass": "1.49.9",
"sass-loader": "12.1.0",
"webpack": "5.49.0",
"webpack-cli": "4.9.0",
"webpack-dev-server": "3.11.2"
}
}
}
4 changes: 2 additions & 2 deletions frontend/src/features/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const AUTH_TOKEN = "auth-token";
export const API = "localhost:5000";
export const SOCKET_API = "localhost:5001";
export const API = "localhost:3000";
export const SOCKET_API = "localhost:3001";
export const ALERT_SECONDS = 5;
2 changes: 1 addition & 1 deletion frontend/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
devServer: {
contentBase: path.join(__dirname, "dist"),
compress: true,
port: 9000,
port: 8080,
},
module: {
rules: [
Expand Down
Loading

0 comments on commit c943a66

Please sign in to comment.