Simplify docker setup

This commit is contained in:
ADAMJR 2021-12-21 17:38:39 +00:00
parent ab3744581e
commit cf223ceac5
9 changed files with 59 additions and 88 deletions

19
Dockerfile.dev Normal file
View File

@ -0,0 +1,19 @@
FROM node:16-alpine3.14
RUN addgroup app && adduser -SG app app
RUN mkdir /app && chown app:app /app
USER app
WORKDIR /app/backend
COPY --chown=app:app backend/package*.json ./
RUN npm i
WORKDIR /app/frontend
COPY --chown=app:app frontend/package*.json ./
RUN npm i
WORKDIR /app
COPY --chown=app:app . .
EXPOSE 3000
EXPOSE 4200
CMD ./bin/start-dev.sh

View File

@ -1,14 +0,0 @@
FROM node:16-alpine3.14
RUN addgroup app && adduser -SG app app
RUN mkdir /app && chown app:app /app
USER app
WORKDIR /app
COPY --chown=app:app package*.json ./
RUN npm i
COPY --chown=app:app . .
RUN unlink /app/types
COPY --chown=app:app --from=accord_types:latest /app /app/types
EXPOSE 3000
CMD npm run start:dev

View File

@ -6,15 +6,15 @@ export class VoiceService {
}
public getForUser(channelId: string, userId: string) {
// check if user is already connected
const connections = this.getOrCreate(channelId);
const isConnected = connections.some(u => u.userId === userId);
const cons = this.getOrCreate(channelId);
const isConnected = cons.some(u => u.userId === userId);
if (!isConnected)
throw new TypeError('You are not connected to the voice service');
// we don't want to give user their own audio back
// TODO: store and filter muted connections here?
// - 'isMuted' as part of ChannelTypes.VoiceConnection?
return connections.filter(c => c.userId !== userId);
return cons.filter(c => c.userId !== userId);
}
private getOrCreate(channelId: string) {
return this.connections.get(channelId)
@ -24,26 +24,26 @@ export class VoiceService {
}
public add(channelId: string, data: ChannelTypes.VoiceConnection) {
const channelConnections = this.getOrCreate(channelId);
channelConnections.push(data);
this.connections.set(channelId, channelConnections);
const cons = this.getOrCreate(channelId);
cons.push(data);
this.connections.set(channelId, cons);
}
public setForUser(channelId: string, data: ChannelTypes.VoiceConnection) {
const channelConnections = this.getOrCreate(channelId);
const index = channelConnections.findIndex(c => c.userId === data.userId);
const cons = this.getOrCreate(channelId);
const index = cons.findIndex(c => c.userId === data.userId);
channelConnections[index] = data;
this.connections.set(channelId, channelConnections);
cons[index] = data;
this.connections.set(channelId, cons);
return this.getForUser(channelId, data.userId);
}
public remove(channelId: string, userId: string) {
const channelConnections = this.getOrCreate(channelId);
const index = channelConnections.findIndex(c => c.userId === userId);
const cons = this.getOrCreate(channelId);
const index = cons.findIndex(c => c.userId === userId);
channelConnections.splice(index, 1);
this.connections.set(channelId, channelConnections);
cons.splice(index, 1);
this.connections.set(channelId, cons);
}
}

5
bin/start-dev.sh Normal file
View File

@ -0,0 +1,5 @@
#!/bin/sh
cd /app/backend && npm run start:dev &
cd /app/frontend && npm run start:dev
fg %1

View File

@ -5,28 +5,18 @@ services:
image: mongo:5-focal
ports: [27018:27017]
volumes: [accord:/data/db]
types:
build: ./types
backend:
container_name: accord_backend
depends_on: [types, database]
build: ./backend
ports: [3000:3000]
env_file: [./backend/.env]
app:
container_name: accord_app
depends_on: [database]
build:
context: ./
dockerfile: Dockerfile.dev
ports: [3000:3000, 4200:4200]
env_file: [./backend/.env, ./frontend/env/.env.dev]
volumes:
- ./backend/src:/app/src
- ./backend/assets:/app/assets
- ./backend/logs:/app/logs
frontend:
container_name: accord_frontend
depends_on: [types, database]
build:
context: ./frontend
args:
REACT_APP_API_URL: ${backend}/v2
ports: [4200:4200]
env_file: [./frontend/env/.env.dev]
volumes:
- ./frontend/src:/app/src
volumes:
accord:

View File

@ -1,22 +0,0 @@
FROM node:16-alpine3.14
RUN addgroup app && adduser -SG app app
RUN mkdir /app && chown app:app /app
USER app
WORKDIR /app
COPY --chown=app:app package*.json ./
RUN npm i
COPY --chown=app:app . .
RUN unlink /app/types
COPY --chown=app:app --from=accord_types:latest /app /app/types
ENV PORT $PORT
ENV REACT_APP_API_URL $REACT_APP_API_URL
ENV REACT_APP_CDN_URL $REACT_APP_CDN_URL
ENV REACT_APP_REPO $REACT_APP_REPO
ENV REACT_APP_ROOT_API_URL $REACT_APP_ROOT_API_URL
ARG REACT_APP_API_URL $REACT_APP_API_URL
EXPOSE 4200
CMD npm run start:dev

View File

@ -1,5 +1,5 @@
PORT=4200
REACT_APP_API_URL="${backend}/v2"
REACT_APP_CDN_URL="${backend}/assets"
REACT_APP_API_URL="http://localhost:3000/v2"
REACT_APP_CDN_URL="http://localhost:3000/assets"
REACT_APP_REPO="https://github.com/accord-dot-app/app"
REACT_APP_ROOT_API_URL=${backend}
REACT_APP_ROOT_API_URL="http://localhost:4200"

View File

@ -1,17 +1,14 @@
{
"scripts": {
"dc:run": "sudo docker-compose -f docker-compose.dev.yml run database --service-ports",
"dc:up": "sudo docker-compose -f docker-compose.dev.yml up -d --build",
"dc:down": "sudo docker-compose -f docker-compose.dev.yml down",
"dc:logs": "sudo docker-compose -f docker-compose.dev.yml logs -t",
"dc:logs:db": "sudo npm run dc:logs | grep database",
"dc:logs:b": "sudo npm run dc:logs | grep backend",
"dc:logs:f": "sudo npm run dc:logs | grep frontend",
"dc:ps": "sudo docker-compose -f docker-compose.dev.yml ps",
"dc:build:prod": "sudo docker-compose -f docker-compose.prod.yml build",
"dc:up:prod": "sudo docker-compose -f docker-compose.prod.yml up -d --build",
"dc:down:prod": "sudo docker-compose -f docker-compose.prod.yml down",
"dc:logs:prod": "sudo docker-compose -f docker-compose.prod.yml logs",
"dc:ps:prod": "sudo docker-compose -f docker-compose.dev.yml ps"
"dc:run": "docker-compose -f docker-compose.dev.yml run database --service-ports",
"dc:up": "docker-compose -f docker-compose.dev.yml up -d --build",
"dc:down": "docker-compose -f docker-compose.dev.yml down",
"dc:logs": "docker-compose -f docker-compose.dev.yml logs -t",
"dc:ps": "docker-compose -f docker-compose.dev.yml ps",
"dc:build:prod": "docker-compose -f docker-compose.prod.yml build",
"dc:up:prod": "docker-compose -f docker-compose.prod.yml up -d --build",
"dc:down:prod": "docker-compose -f docker-compose.prod.yml down",
"dc:logs:prod": "docker-compose -f docker-compose.prod.yml logs",
"dc:ps:prod": "docker-compose -f docker-compose.dev.yml ps"
}
}

View File

@ -1,4 +0,0 @@
FROM node:16-alpine3.14
WORKDIR /app
COPY . .