Skip to content

Commit 9eed2b2

Browse files
committed
Revamp dev setup to run entirely inside Docker
1 parent 3facdf5 commit 9eed2b2

File tree

12 files changed

+99
-83
lines changed

12 files changed

+99
-83
lines changed

README.md

Lines changed: 4 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -141,86 +141,11 @@ docker-compose up --build -d
141141

142142
### Running the app (Locally/Debugging Purposes)
143143

144-
#### Mongo and Redis Setup
144+
1. Run `yarn install` in the `client` and `server` directories.
145+
1. Run `docker compose -f docker-compose.yml -f docker-compose.dev.yml up -V --build` to start the development containers. The client will be running on http://localhost:5050 and the server will be listening on port 5001. Editing files should work as expected.
145146

146-
1. Open the `docker-compose.yml` file and comment out all services except `caching` and `mongodb`
147-
148-
2. Running Redis and Mongo
149-
150-
```
151-
docker-compose up --build -d
152-
```
153-
154-
#### Client Setup
155-
156-
1. Setting up the client `.env` file (Placed in the root of your `client` folder)
157-
158-
```
159-
REACT_APP_BACKEND_URL="http://localhost:3001"
160-
```
161-
162-
2. Setting up `axios.ts`
163-
164-
> Note: Since we're running poll voting app locally, we'll need to provide some extra information that normally Shibboleth would provide to us.
165-
166-
> Your `axios.ts` file should look like the following:
167-
168-
```
169-
export const instance = axios.create({
170-
headers: { utorid: "utorid" },
171-
baseURL: `${process.env.REACT_APP_BACKEND_URL}`,
172-
});
173-
```
174-
175-
3. Setting up `socket.ts`
176-
177-
> Note: Since we're running poll voting app locally, we'll need to provide some extra information that normally Shibboleth would provide to us.
178-
179-
> Your `socket.ts` file should look like the following:
180-
181-
```
182-
export const socket = io(`${process.env.REACT_APP_BACKEND_URL}`, {
183-
withCredentials: true,
184-
extraHeaders: { utorid: "utorid" }
185-
});
186-
```
187-
188-
4. Running the client
189-
190-
```
191-
yarn run start
192-
```
193-
194-
#### Server Setup
195-
196-
1. Add instructor Utorid's to your whitelist file. It should be placed at the root of the `server` folder.
197-
198-
> Your whitelist file should be named "whitelist" and should look like the following...
199-
200-
```
201-
utorid1
202-
utorid2
203-
utorid3
204-
...
205-
```
206-
207-
2. Setting up the server `.env` file (Placed in the root of your `server` folder)
208-
209-
```
210-
PPORT=3001
211-
MONGODB_URL="mongodb://localhost:27018/quiz"
212-
FRONTEND_URL="http://localhost:3000"
213-
REDIS_URL="redis://default:password@localhost:6379"
214-
WHITELIST=../whitelist
215-
```
216-
217-
3. Running the server
218-
219-
```
220-
yarn run start
221-
```
222-
223-
The client and server will be listening and serving on port `3000` and `3001` respectively.
147+
When the app runs in dev, all of the same containers used in production are used,
148+
plus an extra Apache container that simulates the production proxy running Shibboleth.
224149

225150
### Updating the App
226151

client/Dockerfile.dev

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM node:16
2+
ARG REACT_APP_BACKEND_URL
3+
WORKDIR /frontend
4+
COPY ./package.json ./yarn.lock .
5+
RUN yarn install --ignore-scripts --frozen-lockfile
6+
CMD ["yarn", "run", "start"]

devproxy/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM rockylinux:9
2+
3+
RUN yum update -y && yum install -y httpd && yum clean all
4+
5+
COPY devproxy.conf /etc/httpd/conf.d/
6+
ENTRYPOINT ["/usr/sbin/httpd", "-DFOREGROUND"]

devproxy/devproxy.conf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# Simple Apache configuration to pretend to be Shibboleth.
3+
#
4+
5+
ServerName localhost:5050
6+
7+
<VirtualHost *:80>
8+
ProxyPass / http://nginx:80/
9+
ProxyPassReverse / http://nginx:80/
10+
Header add utorid "utorid"
11+
RequestHeader set utorid "utorid"
12+
13+
# for websockets (needed in prod too)
14+
RewriteEngine On
15+
RewriteCond %{HTTP:Upgrade} =websocket [NC]
16+
RewriteRule /(.*) ws://nginx:80/$1 [P,L]
17+
18+
</VirtualHost>

devproxy/env.client

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
REACT_APP_BACKEND_URL="http://localhost:5050"
2+
PORT=3001

devproxy/env.server

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
PORT=5001
2+
MONGODB_URL="mongodb://mongodb:27017/quiz"
3+
FRONTEND_URL="http://localhost:5050"
4+
REDIS_URL="redis://default:password@redis:6379"
5+
WHITELIST=../whitelist

devproxy/whitelist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
utorid

docker-compose.dev.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
services:
3+
frontend:
4+
volumes:
5+
- ./client:/frontend
6+
- /frontend/node_modules
7+
- ./devproxy/env.client:/frontend/.env
8+
build:
9+
dockerfile: Dockerfile.dev
10+
env_file:
11+
- ./devproxy/env.client
12+
voteapi:
13+
volumes:
14+
- ./server:/api
15+
- /api/node_modules
16+
- ./devproxy/env.server:/api/.env
17+
- ./devproxy/whitelist:/api/whitelist
18+
build:
19+
dockerfile: Dockerfile.dev
20+
env_file:
21+
- ./devproxy/env.server
22+
devproxy:
23+
container_name: devproxy
24+
build:
25+
context: ./devproxy
26+
dockerfile: Dockerfile
27+
restart: unless-stopped
28+
ports:
29+
- "5050:80"
30+
networks:
31+
backend:
32+
aliases:
33+
- devproxy
34+
depends_on:
35+
- frontend
36+
- voteapi

docker-compose.override.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
services:
2+
frontend:
3+
env_file:
4+
- ./client/.env
5+
voteapi:
6+
env_file:
7+
- ./server/.env

docker-compose.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ services:
4444
- caching
4545
ports:
4646
- "5001:5001"
47-
env_file:
48-
- ./server/.env
4947
environment:
5048
- TZ=America/New_York
5149

@@ -63,8 +61,6 @@ services:
6361
- frontend
6462
ports:
6563
- "3001:3001"
66-
env_file:
67-
- ./client/.env
6864

6965
nginx-proxy:
7066
container_name: nginx

nginx.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ http {
66
location / {
77
proxy_pass http://frontend:3001;
88
}
9+
location /sockjs-node {
10+
proxy_pass http://frontend:3001;
11+
proxy_redirect off;
12+
13+
proxy_http_version 1.1;
14+
proxy_set_header Upgrade $http_upgrade;
15+
proxy_set_header Connection "upgrade";
16+
}
917
location /api/ {
1018
proxy_pass http://voteapi:5001/;
1119
}

server/Dockerfile.dev

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM node:16
2+
WORKDIR /api
3+
COPY ./package.json ./yarn.lock .
4+
RUN yarn install --ignore-scripts --frozen-lockfile
5+
CMD ["yarn", "run", "start"]
6+

0 commit comments

Comments
 (0)