Skip to content

Commit 03a192b

Browse files
authored
chore: add nginx reverse proxy to dev environment (ietf-tools#5745)
* chore: add nginx reverse proxy to dev environment * chore: replace settings_local in docker and backup old
1 parent 4051ac8 commit 03a192b

10 files changed

Lines changed: 118 additions & 29 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
},
6767

6868
// Use 'forwardPorts' to make a list of ports inside the container available locally.
69-
"forwardPorts": [3000, 5432, 5433, 8000, 8001],
69+
"forwardPorts": [3000, 5432, 5433, 8000],
7070

7171
"portsAttributes": {
7272
"3000": {
@@ -82,12 +82,12 @@
8282
"onAutoForward": "silent"
8383
},
8484
"8000": {
85-
"label": "Datatracker",
85+
"label": "NGINX",
8686
"onAutoForward": "notify"
8787
},
8888
"8001": {
89-
"label": "Static",
90-
"onAutoForward": "silent"
89+
"label": "Datatracker",
90+
"onAutoForward": "ignore"
9191
}
9292
},
9393

.devcontainer/docker-compose.extend.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@ services:
1818
pgadmin:
1919
network_mode: service:db
2020

21+
static:
22+
network_mode: service:db
23+
2124
volumes:
2225
datatracker-vscode-ext:

.vscode/launch.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"program": "${workspaceFolder}/ietf/manage.py",
1313
"args": [
1414
"runserver",
15-
"0.0.0.0:8000",
15+
"0.0.0.0:8001",
1616
"--settings=settings_local"
1717
],
1818
"django": true,
@@ -30,7 +30,7 @@
3030
"program": "${workspaceFolder}/ietf/manage.py",
3131
"args": [
3232
"runserver",
33-
"0.0.0.0:8000",
33+
"0.0.0.0:8001",
3434
"--settings=settings_local_vite"
3535
],
3636
"django": true,
@@ -48,7 +48,7 @@
4848
"program": "${workspaceFolder}/ietf/manage.py",
4949
"args": [
5050
"runserver",
51-
"0.0.0.0:8000",
51+
"0.0.0.0:8001",
5252
"--settings=settings_local_debug"
5353
],
5454
"django": true,

docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ services:
6262
static:
6363
image: ghcr.io/ietf-tools/static:latest
6464
restart: unless-stopped
65-
ports:
66-
- 8001:80
6765

6866
mq:
6967
image: rabbitmq:3-alpine

docker/app.Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ COPY docker/scripts/app-setup-python.sh /tmp/library-scripts/docker-setup-python
3030
RUN sed -i 's/\r$//' /tmp/library-scripts/docker-setup-python.sh && chmod +x /tmp/library-scripts/docker-setup-python.sh
3131
RUN bash /tmp/library-scripts/docker-setup-python.sh "none" "/usr/local" "${PIPX_HOME}" "${USERNAME}"
3232

33+
# Setup nginx
34+
COPY docker/scripts/app-setup-nginx.sh /tmp/library-scripts/docker-setup-nginx.sh
35+
RUN sed -i 's/\r$//' /tmp/library-scripts/docker-setup-nginx.sh && chmod +x /tmp/library-scripts/docker-setup-nginx.sh
36+
RUN bash /tmp/library-scripts/docker-setup-nginx.sh
37+
COPY docker/configs/nginx-proxy.conf /etc/nginx/sites-available/default
38+
COPY docker/configs/nginx-502.html /var/www/html/502.html
39+
3340
# Remove library scripts for final image
3441
RUN rm -rf /tmp/library-scripts
3542

docker/configs/nginx-502.html

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Datatracker DEV</title>
7+
<style>
8+
body {
9+
background-color: #111;
10+
color: #FFF;
11+
font-family: Arial, Helvetica, sans-serif;
12+
text-align: center;
13+
padding: 50px;
14+
font-size: 16px;
15+
}
16+
img {
17+
height: 80px;
18+
}
19+
h1 {
20+
color: #CCC;
21+
}
22+
div {
23+
background-color: #222;
24+
border-radius: 10px;
25+
padding: 10px 50px;
26+
display: inline-block;
27+
}
28+
i {
29+
font-size: 64px;
30+
line-height: 16px;
31+
vertical-align: text-bottom;
32+
margin-right: 5px;
33+
}
34+
code {
35+
background-color: #444;
36+
padding: 3px 6px;
37+
border-radius: 5px;
38+
margin: 0 5px;
39+
}
40+
.mt {
41+
margin-top: 15px;
42+
}
43+
a {
44+
color: #31CCEC;
45+
}
46+
</style>
47+
</head>
48+
<body>
49+
<img src="/_static/logos/ietf-inverted.svg" alt="IETF" />
50+
<h1>Datatracker</h1>
51+
<h2>Could not connect to dev server.</h2>
52+
<div>
53+
<p>Is the datatracker server running?</p>
54+
<p class="mt">Using <strong>VS Code</strong>, open the <strong>Run and Debug</strong> tab on the left and click the <i>&#x2023;</i> symbol (Run Server) to start the server.</p>
55+
<p>Otherwise, run the command <code>ietf/manage.py runserver 0.0.0.0:8001</code> from the terminal.</p>
56+
</div>
57+
<p class="mt">For more information, check out the <a href="https://github.com/ietf-tools/datatracker/blob/main/docker/README.md" target="_blank">Datatracker Development in Docker</a> guide.</p>
58+
</body>
59+
</html>

docker/configs/nginx-proxy.conf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
server {
2+
listen 8000 default_server;
3+
listen [::]:8000 default_server;
4+
5+
root /var/www/html;
6+
index index.html index.htm index.nginx-debian.html;
7+
8+
server_name _;
9+
10+
location /_static/ {
11+
proxy_pass http://localhost:80/;
12+
}
13+
14+
location / {
15+
error_page 502 /502.html;
16+
proxy_pass http://localhost:8001/;
17+
}
18+
19+
location /502.html {
20+
root /var/www/html;
21+
internal;
22+
}
23+
}

docker/configs/settings_local.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@
5656

5757
DE_GFM_BINARY = '/usr/local/bin/de-gfm'
5858

59-
STATIC_IETF_ORG = "http://localhost:8001"
59+
STATIC_IETF_ORG = "/_static"

docker/scripts/app-init.sh

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ sudo chown dev:dev "/assets"
2121
echo "Fix chromedriver /dev/shm permissions..."
2222
sudo chmod 1777 /dev/shm
2323

24+
# Run nginx
25+
26+
echo "Starting nginx..."
27+
sudo nginx
28+
2429
# Build node packages that requrie native compilation
2530
echo "Compiling native node packages..."
2631
yarn rebuild
@@ -35,37 +40,27 @@ cp $WORKSPACEDIR/docker/configs/settings_postgresqldb.py $WORKSPACEDIR/ietf/sett
3540

3641
if [ ! -f "$WORKSPACEDIR/ietf/settings_local.py" ]; then
3742
echo "Setting up a default settings_local.py ..."
38-
cp $WORKSPACEDIR/docker/configs/settings_local.py $WORKSPACEDIR/ietf/settings_local.py
39-
4043
else
41-
echo "Using existing ietf/settings_local.py file"
42-
if ! cmp -s $WORKSPACEDIR/docker/configs/settings_local.py $WORKSPACEDIR/ietf/settings_local.py; then
43-
echo "NOTE: Differences detected compared to docker/configs/settings_local.py!"
44-
echo "We'll assume you made these deliberately."
45-
fi
44+
echo "Renaming existing ietf/settings_local.py to ietf/settings_local.py.bak"
45+
mv -f $WORKSPACEDIR/ietf/settings_local.py $WORKSPACEDIR/ietf/settings_local.py.bak
4646
fi
47+
cp $WORKSPACEDIR/docker/configs/settings_local.py $WORKSPACEDIR/ietf/settings_local.py
4748

4849
if [ ! -f "$WORKSPACEDIR/ietf/settings_local_debug.py" ]; then
4950
echo "Setting up a default settings_local_debug.py ..."
50-
cp $WORKSPACEDIR/docker/configs/settings_local_debug.py $WORKSPACEDIR/ietf/settings_local_debug.py
5151
else
52-
echo "Using existing ietf/settings_local_debug.py file"
53-
if ! cmp -s $WORKSPACEDIR/docker/configs/settings_local_debug.py $WORKSPACEDIR/ietf/settings_local_debug.py; then
54-
echo "NOTE: Differences detected compared to docker/configs/settings_local_debug.py!"
55-
echo "We'll assume you made these deliberately."
56-
fi
52+
echo "Renaming existing ietf/settings_local_debug.py to ietf/settings_local_debug.py.bak"
53+
mv -f $WORKSPACEDIR/ietf/settings_local.py $WORKSPACEDIR/ietf/settings_local.py.bak
5754
fi
55+
cp $WORKSPACEDIR/docker/configs/settings_local_debug.py $WORKSPACEDIR/ietf/settings_local_debug.py
5856

5957
if [ ! -f "$WORKSPACEDIR/ietf/settings_local_vite.py" ]; then
6058
echo "Setting up a default settings_local_vite.py ..."
61-
cp $WORKSPACEDIR/docker/configs/settings_local_vite.py $WORKSPACEDIR/ietf/settings_local_vite.py
6259
else
63-
echo "Using existing ietf/settings_local_vite.py file"
64-
if ! cmp -s $WORKSPACEDIR/docker/configs/settings_local_vite.py $WORKSPACEDIR/ietf/settings_local_vite.py; then
65-
echo "NOTE: Differences detected compared to docker/configs/settings_local_vite.py!"
66-
echo "We'll assume you made these deliberately."
67-
fi
60+
echo "Renaming existing ietf/settings_local_vite.py to ietf/settings_local_vite.py.bak"
61+
mv -f $WORKSPACEDIR/ietf/settings_local_vite.py $WORKSPACEDIR/ietf/settings_local_vite.py.bak
6862
fi
63+
cp $WORKSPACEDIR/docker/configs/settings_local_vite.py $WORKSPACEDIR/ietf/settings_local_vite.py
6964

7065
# Create data directories
7166

docker/scripts/app-setup-nginx.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
3+
apt-get update -y
4+
apt-get install -y nginx

0 commit comments

Comments
 (0)