diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..7d64449 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +node_modules +npm-debug.log +Dockerfile +.git +.gitignore \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d83a274 --- /dev/null +++ b/Dockerfile @@ -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"] \ No newline at end of file diff --git a/backend/Dockerfile b/backend/Dockerfile index 8ad7e06..159ce21 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -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 diff --git a/backend/Makefile b/backend/Makefile deleted file mode 100644 index 9c91fd8..0000000 --- a/backend/Makefile +++ /dev/null @@ -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 \ No newline at end of file diff --git a/backend/docker-compose.yml b/backend/docker-compose.yml deleted file mode 100644 index 4db2c7b..0000000 --- a/backend/docker-compose.yml +++ /dev/null @@ -1,10 +0,0 @@ -services: - owlbearrodeo: - build: ./ - stop_grace_period: 30s - init: true - ports: - - 9000:9000 - environment: - PORT: 9000 - ALLOW_ORIGIN: ".*" \ No newline at end of file diff --git a/backend/ice.json b/backend/ice.json new file mode 100644 index 0000000..9d47db8 --- /dev/null +++ b/backend/ice.json @@ -0,0 +1,3 @@ +{ + "iceServers": [{ "urls": "stun:stun.l.google.com:19302" }] +} diff --git a/backend/package.json b/backend/package.json index 0793782..e8933f0 100644 --- a/backend/package.json +++ b/backend/package.json @@ -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", diff --git a/backend/src/controllers/IceServerController.ts b/backend/src/controllers/IceServerController.ts index 8957bbc..9622b21 100644 --- a/backend/src/controllers/IceServerController.ts +++ b/backend/src/controllers/IceServerController.ts @@ -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 }); } } diff --git a/backend/src/entities/Global.ts b/backend/src/entities/Global.ts index 0cf0e78..f356698 100644 --- a/backend/src/entities/Global.ts +++ b/backend/src/entities/Global.ts @@ -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); + }); } diff --git a/backend/src/entities/IceServer.ts b/backend/src/entities/IceServer.ts index 859d187..dbd5c1b 100644 --- a/backend/src/entities/IceServer.ts +++ b/backend/src/entities/IceServer.ts @@ -2,8 +2,7 @@ import Global from "./Global"; export default class IceServer { async getIceServers(): Promise { - const servers = Global.ICE_SERVERS; - const data = JSON.parse(servers); - return data; + const servers = await Global.ICE_SERVERS; + return servers; } } diff --git a/backend/tsconfig.json b/backend/tsconfig.json index 4f18be5..d940084 100644 --- a/backend/tsconfig.json +++ b/backend/tsconfig.json @@ -1,17 +1,19 @@ { - "compilerOptions": { - "outDir": "./build", - "allowJs": true, - "allowSyntheticDefaultImports": true, - "target": "es6", - "noFallthroughCasesInSwitch": true, - "noEmitOnError": true, - "pretty": true, - "moduleResolution": "node", - "strict": true, - "sourceMap": true, - "skipLibCheck": true - }, - "include": ["./src/**/*"], - "exclude": ["node_modules/**/*", "./build/**/*"] - } \ No newline at end of file + "compilerOptions": { + "outDir": "./build", + "allowJs": true, + "allowSyntheticDefaultImports": true, + "target": "es6", + "noFallthroughCasesInSwitch": true, + "noEmitOnError": true, + "pretty": true, + "moduleResolution": "node", + "strict": true, + "sourceMap": true, + "skipLibCheck": true, + "module": "es2022", + "resolveJsonModule": true + }, + "include": ["./src/**/*", "ice.json"], + "exclude": ["node_modules/**/*", "./build/**/*"] +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..19fb374 --- /dev/null +++ b/docker-compose.yml @@ -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" +