Edit configuration - use docker compose to run frontend and backend

This commit is contained in:
nthouliss 2023-06-15 15:55:47 +10:00
parent e4682a042d
commit 3507d14a29
12 changed files with 97 additions and 73 deletions

5
.dockerignore Normal file
View File

@ -0,0 +1,5 @@
node_modules
npm-debug.log
Dockerfile
.git
.gitignore

27
Dockerfile Normal file
View File

@ -0,0 +1,27 @@
# DEVELOPMENT DOCKERFILE ONLY
# THIS DOCKERFILE IS NOT INTENDED FOR PRODUCTION. IT LEVERAGES DEVELOPMENT DEPENDENCIES TO RUN.
FROM node:16.20.0-alpine3.18 AS builder
RUN mkdir /home/node/app/ && chown -R node:node /home/node/app
WORKDIR /home/node/app
COPY --chown=node:node package.json ./
COPY --chown=node:node yarn.lock ./
USER node
RUN yarn install --non-interactive --dev && yarn cache clean
FROM node:16.20.0-alpine3.18
USER node
ENV NODE_ENV production
WORKDIR /home/node/app
COPY --chown=node:node package.json ./
COPY --chown=node:node yarn.lock ./
COPY --chown=node:node tsconfig.json ./
COPY --chown=node:node ./src/ ./src
COPY --chown=node:node ./public/ ./public
COPY --chown=node:node --from=builder /home/node/app/node_modules ./node_modules
CMD ["yarn", "start"]

View File

@ -1,4 +1,4 @@
FROM node:14.18.1-alpine3.13 AS builder
FROM node:16.20.0-alpine3.18 AS builder
RUN mkdir /home/node/app/ && chown -R node:node /home/node/app
@ -18,12 +18,13 @@ ENV NODE_ENV production
WORKDIR /home/node/app
RUN rm -rf ./node_modules && yarn install --non-interactive --prod --frozen-lockfile && yarn cache clean
FROM node:14.18.1-alpine3.13
FROM node:16.20.0-alpine3.18
USER node
ENV NODE_ENV production
WORKDIR /home/node/app
COPY --chown=node:node package.json ./
COPY --chown=node:node yarn.lock ./
COPY --chown=node:node ice.json ./
COPY --chown=node:node --from=builder /home/node/app/build ./build
COPY --chown=node:node --from=install /home/node/app/node_modules ./node_modules

View File

@ -1,26 +0,0 @@
.SILENT:
## RECOMMENDED
obr:
docker compose run --rm --service-ports --name "obr-service" owlbearrodeo
## DEVELOPER HELPERS
new:
docker compose run --service-ports --name "obr-service" owlbearrodeo
build:
docker compose build --no-cache owlbearrodeo
start:
docker start obr-service
stop:
docker stop obr-service
dev:
docker compose rm -s -f owlbearrodeo && make start
remove:
docker rm obr-service

View File

@ -1,10 +0,0 @@
services:
owlbearrodeo:
build: ./
stop_grace_period: 30s
init: true
ports:
- 9000:9000
environment:
PORT: 9000
ALLOW_ORIGIN: ".*"

3
backend/ice.json Normal file
View File

@ -0,0 +1,3 @@
{
"iceServers": [{ "urls": "stun:stun.l.google.com:19302" }]
}

View File

@ -11,16 +11,6 @@
"start": "node --es-module-specifier-resolution=node ./build/index.js",
"lint": "eslint src/**/*.ts"
},
"repository": {
"type": "git",
"url": "git+https://github.com/mitchemmc/owlbear-rodeo.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/mitchemmc/owlbear-rodeo/issues"
},
"homepage": "https://github.com/mitchemmc/owlbear-rodeo#readme",
"dependencies": {
"bcrypt": "^5.0.0",
"cors": "^2.8.5",

View File

@ -30,6 +30,7 @@ export default class IceServerController extends Controller {
const servers = await this.iceServer.getIceServers();
res.send(JSON.stringify(servers));
} catch (error) {
console.error(JSON.stringify(error));
res.status(500).send({ error });
}
}

View File

@ -1,12 +1,21 @@
import fs from "fs/promises";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export default class Global {
static ORIGIN_WHITELIST: string = process.env.ALLOW_ORIGIN!!;
static CONNECTION_PORT: string | number = process.env.PORT || 9000;
static ICE_SERVERS: string = `
{
"iceServers": [
]
}
`;
static ICE_SERVERS = fs
.readFile(path.resolve(__dirname, "../../", "ice.json"), "utf8")
.then((data) => {
return JSON.parse(data);
})
.catch((error) => {
throw new Error(error);
});
}

View File

@ -2,8 +2,7 @@ import Global from "./Global";
export default class IceServer {
async getIceServers(): Promise<any> {
const servers = Global.ICE_SERVERS;
const data = JSON.parse(servers);
return data;
const servers = await Global.ICE_SERVERS;
return servers;
}
}

View File

@ -10,8 +10,10 @@
"moduleResolution": "node",
"strict": true,
"sourceMap": true,
"skipLibCheck": true
"skipLibCheck": true,
"module": "es2022",
"resolveJsonModule": true
},
"include": ["./src/**/*"],
"include": ["./src/**/*", "ice.json"],
"exclude": ["node_modules/**/*", "./build/**/*"]
}
}

23
docker-compose.yml Normal file
View File

@ -0,0 +1,23 @@
services:
backend:
build: ./backend/
stop_grace_period: 30s
init: true
ports:
- 9000:9000
environment:
PORT: 9000
ALLOW_ORIGIN: ".*"
frontend:
build:
context: ./
depends_on:
- backend
ports:
- 3000:3000
environment:
REACT_APP_BROKER_URL: "http://localhost:9000"
REACT_APP_ICE_SERVERS_URL: "http://localhost:9000/iceservers"
REACT_APP_VERSION: "1.10.2"
REACT_APP_MAINTENANCE: "false"