Skip to content

Commit 86da6e7

Browse files
committed
reworked the docker setup to properly containerize frontend and backend
1 parent 29cc5d5 commit 86da6e7

File tree

7 files changed

+60
-43
lines changed

7 files changed

+60
-43
lines changed

.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<projectDescription>
3-
<name>project-meriadoc-gradmap</name>
3+
<name>project-meriadoc-gradmap-UBCGradMap</name>
44
<comment>Project project-meriadoc-gradmap created by Buildship.</comment>
55
<projects>
66
</projects>

Dockerfile

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,6 @@ RUN apt-get install -y wget unzip dos2unix
1212
# ENV GRADLE_HOME=/opt/gradle/gradle-8.11.1
1313
# ENV PATH=$PATH:$GRADLE_HOME/bin
1414

15-
RUN apt-get install -y nodejs npm
16-
17-
WORKDIR /gradmap/frontend
18-
19-
COPY frontend/package*.json ./
20-
21-
RUN npm install
22-
23-
# Install nginx
24-
RUN apt-get install -y nginx
25-
26-
2715
ENV PORT=5173
2816
EXPOSE 5173 8080 80
2917

@@ -37,29 +25,14 @@ WORKDIR /gradmap/app
3725
WORKDIR /gradmap/frontend
3826

3927
# Quickly change the code to make it point to the proper endpoint
40-
RUN sed -i "s/dev_yes/dev_no/g" src/Course.tsx
41-
42-
# Build the project
43-
RUN npm run build
44-
45-
# Move it to the right place
46-
RUN rm -rf /var/www/html
47-
RUN mkdir /var/www/html
48-
RUN mv dist/* /var/www/html
49-
50-
# Configure nginx
51-
RUN cp nginx.conf /etc/nginx/sites-available/server.conf
52-
RUN ln -s /etc/nginx/sites-available/server.conf /etc/nginx/sites-enabled/
53-
RUN unlink /etc/nginx/sites-enabled/default
28+
# RUN sed -i "s/dev_yes/dev_no/g" src/Course.tsx
5429

5530
RUN alias scrape="./gradlew runScraperNoCache"
5631

5732
WORKDIR /gradmap
58-
RUN ./gradlew clean
59-
60-
61-
RUN chmod +x ./runner.sh
62-
RUN sed -i "s/^M$//" ./runner.sh
63-
RUN dos2unix runner.sh
64-
CMD ["./runner.sh"]
65-
# CMD nginx
33+
# RUN ./gradlew clean
34+
#
35+
# RUN chmod +x ./runner.sh
36+
# RUN sed -i "s/^M$//" ./runner.sh
37+
# RUN dos2unix runner.sh
38+
CMD ["./gradlew", "clean", "run"]

docker-compose.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1-
version: '3.8'
21
services:
3-
gradmap:
2+
backend:
43
build: ./
4+
restart: always
5+
networks:
6+
- app-network
7+
8+
frontend:
9+
build: ./frontend
10+
restart: always
511
ports:
6-
- 5173:80
12+
- "80:80"
13+
networks:
14+
- app-network
15+
depends_on:
16+
- backend
717

18+
networks:
19+
app-network:
20+
driver: bridge

frontend/Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM node:20-slim as build
2+
3+
4+
WORKDIR /usr/app
5+
6+
COPY . /usr/app
7+
8+
RUN npm i
9+
10+
11+
RUN npm run build
12+
13+
FROM nginx:alpine3.18-slim
14+
15+
EXPOSE 80
16+
17+
COPY ./default.conf /etc/nginx/conf.d/default.conf
18+
19+
COPY --from=build /usr/app/dist /usr/share/nginx/html
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ server {
44

55
server_name _;
66

7-
location /api {
8-
proxy_pass http://localhost:8080/api;
7+
root /usr/share/nginx/html;
8+
index index.html;
9+
10+
location /api/ {
11+
proxy_pass http://backend:8080/api/;
912
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
1013
proxy_set_header X-Forwarded-Proto $scheme;
1114
proxy_set_header X-Forwarded-Port $server_port;
1215
}
1316

1417
location / {
15-
root /var/www/html;
16-
index index.html;
18+
try_files $uri $uri/ /index.html;
1719
}
1820
}

frontend/src/Course.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export interface Position {
3232
}
3333

3434
// The production build script changes this to dev_no
35-
export const DEVELOPMENT = "dev_yes";
35+
export const DEVELOPMENT = "dev_no";
3636
//export let API_ENDPOINT = import.meta.env.BASE_URL;
3737
export let API_ENDPOINT = "";
3838

frontend/vite.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,14 @@ import react from '@vitejs/plugin-react'
44
// https://vite.dev/config/
55
export default defineConfig({
66
plugins: [react()],
7+
server: {
8+
port: 5173,
9+
host: '0.0.0.0',
10+
proxy: {
11+
'/api': 'http://localhost:8080',
12+
},
13+
preview: {
14+
port: 5173,
15+
}
16+
}
717
})

0 commit comments

Comments
 (0)