Skip to content

Commit c0e6723

Browse files
authored
Merge pull request #140 from weaponsforge/dev
v3.1.0
2 parents bf47c21 + 55a657c commit c0e6723

File tree

14 files changed

+295
-13
lines changed

14 files changed

+295
-13
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,19 @@ https://sites.google.com/view/gsites-embed-app/full-page
101101
- Navigate to the /server directory from the commandline and run:<br>
102102
`npm run user:create [email protected] --password=anypasasword --displayname="Game Tester" --emailverified=true`
103103

104+
## Run with Docker
105+
106+
```
107+
# Run on development mode
108+
docker compose -f docker-compose.dev.yml build
109+
docker compose -f docker-compose.dev.yml up
110+
docker compose -f docker-compose.dev.yml down
111+
112+
# Build and run for production mode
113+
docker compose -f docker-compose.prod.yml build
114+
docker compose -f docker-compose.prod.yml up
115+
docker compose -f docker-compose.prod.yml down
116+
```
117+
104118
@weaponsforge<br>
105119
20230326

client/.dockerignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.git
2+
.gitignore
3+
node_modules
4+
npm-debug.log
5+
Dockerfile
6+
.dockerignore
7+
*.zip
8+
*.firebase
9+
firebase-debug.log

client/.env.example

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ NEXT_PUBLIC_BASE_PATH=''
22
NEXT_PUBLIC_FIREBASE_WEB_API_KEY=AIzaSyD65tGpVAl23Iu_IfLatCO3ikoNQzR347o
33
NEXT_PUBLIC_FIREBASE_WEB_AUTHDOMAIN=climate-profile-app.firebaseapp.com
44
NEXT_PUBLIC_FIREBASE_WEB_PROJECT_ID=climate-profile-app
5-
NEXT_PUBLIC_FIREBASE_WEB_STORAGE_BUCKET=climate-profile-app.appspot.com
5+
NEXT_PUBLIC_FIREBASE_WEB_STORAGE_BUCKET=climate-profile-app.appspot.com
6+
# Uncomment this line if using Docker Desktop and WSL2 on Windows OS
7+
# WATCHPACK_POLLING=true

client/Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM node:20.15.0-alpine as base
2+
RUN mkdir -p /opt/client
3+
WORKDIR /opt/client
4+
RUN adduser -S client
5+
RUN chown -R client /opt/client
6+
COPY package*.json ./
7+
8+
# BUILD TARGET
9+
FROM base as build
10+
RUN npm install && npm cache clean --force
11+
COPY . ./
12+
RUN npm run export
13+
USER client
14+
15+
# DEVELOPMENT CLIENT PROFILE
16+
FROM base as development
17+
ENV NODE_ENV=development
18+
RUN npm install && npm cache clean --force
19+
COPY . ./
20+
EXPOSE 3000
21+
CMD ["npm", "run", "dev"]
22+
23+
# PRODUCTION CLIENT PROFILE
24+
FROM nginx:1.22.0-alpine as production
25+
COPY --from=build /opt/client/out /usr/share/nginx/html
26+
RUN rm /etc/nginx/conf.d/default.conf
27+
COPY config/nginx/nginx.conf /etc/nginx/conf.d
28+
EXPOSE 3000
29+
CMD ["nginx", "-g", "daemon off;"]

client/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ password: useruser
3333

3434
2. Set up the environment variables. Create a `.env`, `.env.local` and a `.env.development` files inside the root project directory with reference to the `.env.example` file.<br>
3535

36-
| Variable Name | Description |
37-
| --------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
36+
| Variable Name | Description |
37+
| --- | --- |
3838
| NEXT_PUBLIC_BASE_PATH | Root directory path name that NextJS uses for assets, media and client-side routing for the app.<br><br>Set its value to blank `''` when working on development mode in localhost.<br><br>Set its value to the sub-directory name where the exported NextJS app is to be deployed, i.e. `/<YOUR_REPOSITORY_NAME>` when<br> deploying on a repository (sub-directory) of a root GitHub Pages site, i.e, on `https://<YOUR_GITHUB_USERNAME>.github.io/<YOUR_REPOSITORY_NAME>` |
39-
| NEXT_PUBLIC_FIREBASE_WEB_API_KEY | Firebase web API key from the Firebase Project Settings configuration file. |
40-
| NEXT_PUBLIC_FIREBASE_WEB_AUTHDOMAIN | Firebase web auth domain key from the Firebase Project Settings configuration file. |
41-
| NEXT_PUBLIC_FIREBASE_WEB_PROJECT_ID | Firebase web project ID from the Firebase Project Settings configuration file. |
42-
| NEXT_PUBLIC_FIREBASE_WEB_STORAGE_BUCKET | Firebase web storage bucket key from the Firebase Project Settings configuration file. |
39+
| NEXT_PUBLIC_FIREBASE_WEB_API_KEY | Firebase web API key from the Firebase Project Settings configuration file. |
40+
| NEXT_PUBLIC_FIREBASE_WEB_AUTHDOMAIN | Firebase web auth domain key from the Firebase Project Settings configuration |
41+
| NEXT_PUBLIC_FIREBASE_WEB_PROJECT_ID | Firebase web project ID from the Firebase Project Settings configuration file. |
42+
| NEXT_PUBLIC_FIREBASE_WEB_STORAGE_BUCKET | Firebase web storage bucket key from the Firebase Project Settings configuration file. |
43+
| WATCHPACK_POLLING | Enables hot reload on NextJS apps (tested on NextJS v13.2.1) running inside Docker containers on a Windows host. Set it to `true` if running Docker Desktop with WSL2 on a Windows OS. |
4344

4445
3. Deploy the **Firestore Security Rules** defined in the `"firestore.rules"` file using the Firebase CLI.<br>
4546
`firebase deploy --only firestore:rules`

client/config/nginx/nginx.conf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Minimal nginx configuration for running locally in containers
2+
server {
3+
listen 3000;
4+
5+
root /usr/share/nginx/html;
6+
include /etc/nginx/mime.types;
7+
index index.html index.html;
8+
9+
server_name localhost;
10+
server_tokens off;
11+
12+
# Rewrite all React URLs/routes to index.html
13+
# location / {
14+
# try_files $uri $uri/ /index.html =404;
15+
# }
16+
17+
# Reverse proxy to the backend API server
18+
# Requires the backend service running on a container named 'webserver-kmz-prod'
19+
# location /api {
20+
# proxy_pass http://climate-server-prod:3001;
21+
# proxy_set_header Host $host;
22+
# }
23+
24+
# Other error pages
25+
error_page 500 502 503 504 /50x.html;
26+
location = /50x.html {
27+
root /usr/share/nginx/html;
28+
}
29+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Full nginx configuration with SSL certificate for nginx running on host machine
2+
# Requires a registered domain name, letsencrypt SSL certificates
3+
# and local client/server apps (running in containers or manually installed on host)
4+
5+
server {
6+
listen 80;
7+
listen [::]:80;
8+
server_name www.<YOUR.DOMAIN.COM.HERE>;
9+
return 301 https://<YOUR.DOMAIN.COM.HERE>$request_uri;
10+
}
11+
12+
server {
13+
listen 80;
14+
listen [::]:80;
15+
server_name <YOUR.DOMAIN.COM.HERE>;
16+
return 301 https://<YOUR.DOMAIN.COM.HERE>$request_uri;
17+
}
18+
19+
server {
20+
listen 443 ssl;
21+
server_name www.<YOUR.DOMAIN.COM.HERE>;
22+
ssl_certificate /etc/letsencrypt/live/<YOUR.DOMAIN.COM.HERE>/fullchain.pem;
23+
ssl_certificate_key /etc/letsencrypt/live/<YOUR.DOMAIN.COM.HERE>/privkey.pem;
24+
return 301 https://<YOUR.DOMAIN.COM.HERE>$request_uri;
25+
}
26+
27+
server {
28+
listen 443 ssl http2;
29+
listen [::]:443 ssl http2;
30+
31+
server_name <YOUR.DOMAIN.COM.HERE>;
32+
server_tokens off;
33+
34+
# Available methods
35+
add_header Allow 'GET, POST, PATCH, DELETE, HEAD' always;
36+
add_header X-XSS-Protection '1; mode=block';
37+
38+
if ( $request_method !~ ^(GET|POST|PATCH|DELETE|HEAD)$ ) {
39+
return 405;
40+
}
41+
42+
ssl_certificate /etc/letsencrypt/live/<YOUR.DOMAIN.COM.HERE>/fullchain.pem;
43+
ssl_certificate_key /etc/letsencrypt/live/<YOUR.DOMAIN.COM.HERE>/privkey.pem;
44+
45+
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
46+
ssl_prefer_server_ciphers on;
47+
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
48+
ssl_dhparam '/etc/pki/nginx/dhparams.pem';
49+
50+
add_header Strict-Transport-Security 'max-age=63072000; includeSubDomains' always;
51+
52+
# gzip comppression settings
53+
gzip on;
54+
gzip_disable 'msie6';
55+
56+
gzip_vary on;
57+
gzip_proxied any;
58+
gzip_comp_level 6;
59+
gzip_buffers 16 8k;
60+
gzip_http_version 1.1;
61+
gzip_min_length 0;
62+
gzip_types text/plain application/javascript text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype;
63+
64+
# Reverse proxy to the client website
65+
# Requires the client service running on http://<MACHINE_PRIVATE_IP>:3000 (from a container or manually installed on host)
66+
location / {
67+
proxy_pass http://<MACHINE_PRIVATE_IP>:3000;
68+
proxy_set_header Host $host;
69+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
70+
proxy_set_header X-Forwarded-Proto $scheme;
71+
proxy_set_header X-Real-IP $remote_addr;
72+
proxy_cache_bypass $http_upgrade;
73+
74+
# For websockets
75+
proxy_http_version 1.1;
76+
proxy_set_header Connection 'upgrade';
77+
proxy_set_header Upgrade $http_upgrade;
78+
proxy_read_timeout 600s;
79+
}
80+
81+
# Reverse proxy to the backend API server
82+
# Requires the backend service running on http://<MACHINE_PRIVATE_IP>:3001 (from a container or manually installed on host)
83+
location /api {
84+
proxy_pass http://<MACHINE_PRIVATE_IP>:3001;
85+
proxy_set_header Host $host;
86+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
87+
proxy_set_header X-Forwarded-Proto $scheme;
88+
proxy_set_header X-Real-IP $remote_addr;
89+
proxy_cache_bypass $http_upgrade;
90+
91+
# For websockets
92+
proxy_http_version 1.1;
93+
proxy_set_header Connection 'upgrade';
94+
proxy_set_header Upgrade $http_upgrade;
95+
proxy_read_timeout 600s;
96+
}
97+
98+
# Other error pages
99+
error_page 500 502 503 504 /50x.html;
100+
location = /50x.html {
101+
root /usr/share/nginx/html;
102+
}
103+
}

docker-compose.dev.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
services:
2+
# NextJS v13 app running on development mode
3+
climate-client-dev:
4+
container_name: climate-client-dev
5+
image: weaponsforge/climate-client:dev
6+
env_file:
7+
- ./client/.env
8+
build:
9+
context: ./client
10+
dockerfile: Dockerfile
11+
target: development
12+
networks:
13+
- climate-dev
14+
volumes:
15+
- ./client:/opt/client
16+
- /opt/client/node_modules
17+
- /opt/client/.next
18+
ports:
19+
- "3000:3000"
20+
21+
# Express server for hosting KMZ files running in development mode
22+
climate-server-dev:
23+
container_name: climate-server-dev
24+
image: weaponsforge/climate-server:dev
25+
env_file:
26+
- ./server/.env
27+
build:
28+
context: ./server
29+
dockerfile: Dockerfile
30+
target: development
31+
networks:
32+
- climate-dev
33+
volumes:
34+
- ./server:/opt/server
35+
- /opt/server/node_modules
36+
stdin_open: true
37+
tty: true
38+
39+
networks:
40+
climate-dev:
41+
name: climate-dev
42+
external: false

docker-compose.prod.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
services:
2+
# NextJS exported app running on an nginx webserver
3+
climate-client-prod:
4+
container_name: climate-client-prod
5+
image: weaponsforge/climate-client:latest
6+
restart: always
7+
build:
8+
context: ./client
9+
dockerfile: Dockerfile
10+
target: production
11+
networks:
12+
- climate-prod
13+
ports:
14+
- "3000:3000"
15+
16+
networks:
17+
climate-prod:
18+
name: climate-prod
19+
external: false

scripts/docker-cleanup.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
# Stops and deletes ALL Docker resources
4+
docker image prune
5+
docker rmi $(docker images -a -q)
6+
docker stop $(docker ps -a -q)
7+
docker rm $(docker ps -a -q)
8+
docker system prune -f
9+
docker system prune -a
10+
docker volume prune -f

0 commit comments

Comments
 (0)