Skip to content

Commit

Permalink
Merge pull request #185 from AlecM33/local-docker-compose
Browse files Browse the repository at this point in the history
Local docker compose
  • Loading branch information
AlecM33 committed Mar 5, 2024
2 parents e0789f8 + 48888fe commit 613a16e
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 75 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git
*Dockerfile*
*docker-compose*
node_modules
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CONTAINER_PORT_1=5000
CONTAINER_PORT_2=5001
WEB_PORT=5000
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Use the official lightweight Node.js 12 image.
# Use the official lightweight Node.js 14 image.
# https://hub.docker.com/_/node
FROM node:14-slim

Expand Down
15 changes: 15 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:14-slim

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . ./

ENV NODE_ENV development
ENV REDIS_URL_DEV "redis://redis:6379"
ENV WEB_PORT 5000

CMD [ "npm", "run", "start:dev:docker" ]
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ Instances of this app are part of a stateless architecture that scales up and do

### Running Locally

#### Using Docker

If you have Docker Desktop installed, running `docker compose up` will spin up, by default, two
web servers and one redis server for them to connect to. The app can then be accessed at `localhost:5000`
or `localhost:5001`. Otherwise, read below for setup that does not use Docker.

![image](https://github.com/AlecM33/Werewolf/assets/24642328/36161f89-20a4-4236-ad24-e395985d48c3)

#### Without Docker

The entrypoint for the application is `index.js` at the root.

Before starting the Node.js server, you'll need a Redis server running locally on the default port. This is what's used
Expand Down
15 changes: 15 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
services:
redis:
image: "redis:alpine"
ports:
- "6379:6379"
web:
build:
dockerfile: Dockerfile.dev
ports:
- "${CONTAINER_PORT_1}:${WEB_PORT}"
web-2:
build:
dockerfile: Dockerfile.dev
ports:
- "${CONTAINER_PORT_2}:${WEB_PORT}"
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
});
})().then(() => console.log('Server startup complete.'))
.catch((e) => {
console.error('SERVER FAILED TO START: ' + e);
console.error('SERVER FAILED TO START: ' + e.stack);
process.exit(-1);
});
125 changes: 59 additions & 66 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
"bundle": "webpack --config client/webpack/webpack-prod.config.js",
"gcp-build": "webpack --config client/webpack/webpack-prod.config.js",
"build:dev": "webpack --watch --config client/webpack/webpack-dev.config.js --mode=development",
"start:dev": "NODE_ENV=development && webpack --config client/webpack/webpack-dev.config.js --mode=development && nodemon index.js",
"start:dev:no-hot-reload": "NODE_ENV=development && webpack --config client/webpack/webpack-dev.config.js --mode=development && node index.js",
"start:dev:windows": "SET NODE_ENV=development && webpack --config client/webpack/webpack-dev.config.js --mode=development && nodemon index.js -- loglevel=debug",
"start:dev:windows:no-hot-reload:debug": "SET NODE_ENV=development && webpack --config client/webpack/webpack-dev.config.js --mode=development && node --inspect index.js",
"start:dev:windows:no-hot-reload": "SET NODE_ENV=development && webpack --config client/webpack/webpack-dev.config.js --mode=development && node index.js",
"start:dev:docker": "webpack --config client/webpack/webpack-dev.config.js --mode=development && node index.js -- loglevel=debug",
"start:dev": "NODE_ENV=development REDIS_URL_DEV=redis://127.0.0.1:6379 && webpack --config client/webpack/webpack-dev.config.js --mode=development && nodemon index.js",
"start:dev:no-hot-reload": "NODE_ENV=development REDIS_URL_DEV=redis://127.0.0.1:6379 && webpack --config client/webpack/webpack-dev.config.js --mode=development && node index.js",
"start:dev:windows": "SET NODE_ENV=development & SET REDIS_URL_DEV=redis://127.0.0.1:6379 && webpack --config client/webpack/webpack-dev.config.js --mode=development && nodemon index.js -- loglevel=debug",
"start:dev:windows:no-hot-reload:debug": "SET NODE_ENV=development & SET REDIS_URL_DEV=redis://127.0.0.1:6379 && webpack --config client/webpack/webpack-dev.config.js --mode=development && node --inspect index.js",
"start:dev:windows:no-hot-reload": "SET NODE_ENV=development & SET REDIS_URL_DEV=redis://127.0.0.1:6379 && webpack --config client/webpack/webpack-dev.config.js --mode=development && node index.js",
"start": "NODE_ENV=production node index.js -- loglevel=debug",
"start:windows": "SET NODE_ENV=production && node index.js -- loglevel=debug port=8080",
"test": "jasmine && karma start --single-run --browsers ChromeHeadless karma.conf.js",
Expand Down
2 changes: 1 addition & 1 deletion server/modules/ServerBootstrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const ServerBootstrapper = {
try {
const args = Array.from(process.argv.map((arg) => arg.trim().toLowerCase()));
const useHttps = args.includes('protocol=https');
const port = process.env.PORT || args
const port = process.env.WEB_PORT || args
.filter((arg) => {
return /port=\d+/.test(arg);
})
Expand Down
4 changes: 3 additions & 1 deletion server/modules/singletons/EventManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ class EventManager {

createRedisPublisher = async () => {
this.publisher = process.env.NODE_ENV.trim() === 'development'
? redis.createClient()
? redis.createClient({
url: process.env.REDIS_URL_DEV
})
: redis.createClient({
url: process.env.REDIS_URL
});
Expand Down

0 comments on commit 613a16e

Please sign in to comment.