Skip to content

Commit b91d87c

Browse files
luvwinniebkueng
authored andcommitted
Refeactor code for nginx docker container.
1 parent d9f85fb commit b91d87c

17 files changed

+346
-133
lines changed

.env

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# DOMAIN such as example.com or local development 192.168.1.2
2+
DOMAIN=review.px4.io
3+
PORT=5006
4+
EMAIL=
5+
CERT_PATH=./data/certbot
6+
USE_PROXY="True"
7+
# uncomment this for local development
8+
# BOKEH_ALLOW_WS_ORIGIN=192.168.1.2:5006
9+
10+
# Nginx config to use default.conf or default_ssl.conf
11+
# Please modify the file in nginx/default.conf or nginx/default_ssl.conf for your use cases
12+
NGINX_CONF=default.conf

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ __pycache__
1010
/config_user.ini
1111

1212
data/img/*
13+
14+
data/app_data
15+
data/certbot

README.md

+55-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ brew install fftw
5151
```bash
5252
# After git clone, enter the directory
5353
git clone https://github.com/PX4/flight_review.git
54-
cd flight_review
54+
cd flight_review/app
5555
pip install -r requirements.txt
5656
# Note: preferably use a virtualenv
5757
```
@@ -74,11 +74,13 @@ For local usage, the server can be started directly with a log file name,
7474
without having to upload it first:
7575

7676
```bash
77+
cd app
7778
./serve.py -f <file.ulg>
7879
```
7980

8081
To start the whole web application:
8182
```bash
83+
cd app
8284
./serve.py --show
8385
```
8486

@@ -138,6 +140,58 @@ the root directory (Eg `tornado_handlers.py`). Then to make sure the same module
138140
is only loaded once, we use `import xy` instead of `import plot_app.xy`.
139141
It's useful to look at `print('\n'.join(sys.modules.keys()))` to check this.
140142

143+
# Description
144+
145+
This section explain about how to work with docker.
146+
147+
# Arguments
148+
149+
- PORT - The number of port, what listen service in docker, default 5006
150+
- USE_PROXY - The set his, if you use reverse proxy (Nginx, ...)
151+
- DOMAIN - The address domain name for origin, default = *
152+
- CERT_PATH - The SSL certificate volume path
153+
- EMAIL - Email for challenging Let's Encrypt DNS
154+
155+
# Paths
156+
157+
- /opt/service/config_user.ini - Path for config
158+
- /opt/service/data - Folder where stored database
159+
- .env - Environment variables for nginx and app docker container
160+
161+
# Build Docker Image
162+
163+
```bash
164+
cd app
165+
docker build -t px4flightreview -f Dockerfile .
166+
```
167+
168+
# Work with docker-compose
169+
Run with following command to start docker container.
170+
Please modify the .env and app/config_default.ini or add app/config_user.ini with respective stages.
171+
172+
***
173+
174+
Uncomment the BOKEH_ALLOW_WS_ORIGIN with your local IP Address when developing, this is for the bokeh application's websocket to work.
175+
### Development
176+
```bash
177+
docker-compose -f docker-compose.dev.yml up
178+
```
179+
***
180+
Test locally with nginx.
181+
182+
### Test Locally
183+
```bash
184+
docker-compose up
185+
```
186+
187+
Remember to Change NGINX_CONF to use default_ssl.conf and add the EMAIL for production.
188+
189+
### Production
190+
```bash
191+
chmod u+x init-letsencrypt.sh
192+
./init-letsencrypt.sh
193+
```
194+
141195

142196
## Contributing
143197
Contributions are welcome! Just open a pull request with detailed description

app/Dockerfile.dev

-23
This file was deleted.

app/plot_app/templates/browse.html

+56-57
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,37 @@
1-
21
{% include 'header.html' %}
32

43
<h3>Browse public Log Files</h3>
54

65
<p>
7-
Use <a href="https://github.com/PX4/flight_review/blob/master/download_logs.py">
8-
this script</a> for automated download of public log files.
6+
Use <a href="https://github.com/PX4/flight_review/blob/master/download_logs.py">
7+
this script</a> for automated download of public log files.
98
</p>
109

1110
<p>
1211

1312
</p>
1413

1514
<table id="logs_table" style="border-collapse: collapse !important"
16-
class="table table-sm table-striped table-bordered table-condensed">
17-
<thead>
18-
<tr>
19-
<th>#</th>
20-
<th>Upload Date</th>
21-
<th>Overview</th>
22-
<th>Description</th>
23-
<th>Type</th>
24-
<th>Airframe</th>
25-
<th>Hardware</th>
26-
<th>Software</th>
27-
<th>Duration</th>
28-
<th>Start Time</th>
29-
<th>Rating</th>
30-
<th>Errors</th>
31-
<th>Flight Modes</th>
32-
</tr>
33-
</thead>
34-
<tbody>
35-
</tbody>
15+
class="table table-sm table-striped table-bordered table-condensed">
16+
<thead>
17+
<tr>
18+
<th>#</th>
19+
<th>Upload Date</th>
20+
<th>Overview</th>
21+
<th>Description</th>
22+
<th>Type</th>
23+
<th>Airframe</th>
24+
<th>Hardware</th>
25+
<th>Software</th>
26+
<th>Duration</th>
27+
<th>Start Time</th>
28+
<th>Rating</th>
29+
<th>Errors</th>
30+
<th>Flight Modes</th>
31+
</tr>
32+
</thead>
33+
<tbody>
34+
</tbody>
3635
</table>
3736

3837

@@ -44,51 +43,50 @@ <h3>Browse public Log Files</h3>
4443

4544
<script type="text/javascript" charset="utf-8" src="//cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
4645

47-
<script type="text/javascript" charset="utf-8" src="https://cdn.datatables.net/1.10.16/js/dataTables.bootstrap4.min.js"></script>
46+
<script type="text/javascript" charset="utf-8"
47+
src="https://cdn.datatables.net/1.10.16/js/dataTables.bootstrap4.min.js"></script>
4848

4949

5050
<script type="text/javascript">
5151

52-
$(document).ready(function() {
53-
$('#logs_table').DataTable({
52+
$(document).ready(function () {
53+
$('#logs_table').DataTable({
5454
{% if initial_search %}
5555
"search": {
56-
"search": {{ initial_search }}
56+
"search": {{ initial_search }}
5757
},
58-
{% endif %}
59-
"order": [[1, 'desc']],
60-
"ordering": true,
61-
"lengthMenu": [10, 25, 50, 75, 100],
62-
63-
"columns": [
64-
{"orderable": false }, /* row number */
65-
null,
66-
{ "orderable": false }, /* overview */
67-
{ "width": "13%" }, /* description */
68-
null,
69-
{ "orderable": false },/* airframe - not from DB */
70-
null,
71-
null,
72-
null,
73-
{ "width": "10%" }, /* start time */
74-
{ "orderable": false, "width": "13%" }, /* rating */
75-
null,
76-
{ "orderable": false, "width": "11%" } /* flight modes */
77-
],
78-
79-
"language": {
80-
"infoFiltered": "<br>(filtered from _MAX_ total entries)",
81-
},
82-
83-
"serverSide": true,
84-
"ajax": "browse_data_retrieval",
58+
{% endif %}
59+
"order": [[1, 'desc']],
60+
"ordering": true,
61+
"lengthMenu": [10, 25, 50, 75, 100],
62+
63+
"columns": [
64+
{ "orderable": false }, /* row number */
65+
null,
66+
{ "orderable": false }, /* overview */
67+
{ "width": "13%" }, /* description */
68+
null,
69+
{ "orderable": false },/* airframe - not from DB */
70+
null,
71+
null,
72+
null,
73+
{ "width": "10%" }, /* start time */
74+
{ "orderable": false, "width": "13%" }, /* rating */
75+
null,
76+
{ "orderable": false, "width": "11%" } /* flight modes */
77+
],
78+
79+
"language": {
80+
"infoFiltered": "<br>(filtered from _MAX_ total entries)",
81+
},
82+
83+
"serverSide": true,
84+
"ajax": "browse_data_retrieval",
8585
});
8686
var table = $('#logs_table').DataTable();
8787
table.on('xhr', function () {
88-
8988
try {
9089
var table = $('#logs_table').DataTable();
91-
console.log(table);
9290
var search_term = table.search();
9391
var url = new URL(window.location.href);
9492
if (search_term === '') {
@@ -106,4 +104,5 @@ <h3>Browse public Log Files</h3>
106104
</script>
107105

108106
</body>
109-
</html>
107+
108+
</html>
File renamed without changes.

doc.md

-24
This file was deleted.

docker-compose.dev.yml

+6-16
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
11
version: "3.3"
22
services:
3-
# nginx:
4-
# image: nginx
5-
srv:
3+
flight_review_app:
64
build:
75
context: ./app
8-
dockerfile: Dockerfile.dev
9-
restart: always
10-
network_mode: bridge
6+
dockerfile: Dockerfile
7+
env_file: .env
118
ports:
12-
- 5006:5006
13-
environment:
14-
USE_PROXY: "True"
15-
PORT: "5006"
16-
DOMAIN: "192.168.1.30"
17-
BOKEH_ALLOW_WS_ORIGIN: "localhost:5006" # for local development
18-
BOKEH_LOG_LEVEL: "debug"
19-
# BOKEH_ALLOW_WS_ORIGIN: "192.168.1.30:5006" # for local development
20-
command: /opt/service/run.sh
9+
- 5006:5006
2110
volumes:
2211
- ./app:/opt/service/
2312
- ./data:/opt/service/data
24-
# - ./app/config_default.ini:/opt/service/config_default.ini:ro
13+
- ${PWD}/config_default.ini:/opt/service/config_default.ini:ro # Absolute for volume a file.
14+
restart: always

docker-compose.prod.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
version: "3.3"
2+
services:
3+
flight_review_app:
4+
# image: px4flightreview
5+
build:
6+
context: ./app
7+
dockerfile: Dockerfile
8+
env_file: .env_prod
9+
volumes:
10+
- ./data:/opt/service/data
11+
# Absolute for volume a file.
12+
- ${PWD}/config_default.ini:/opt/service/config_default.ini:ro
13+
- ${PWD}/config_user.ini:/opt/service/config_user.ini:ro
14+
restart: always
15+
certbot:
16+
image: certbot/certbot
17+
volumes:
18+
- ./data/certbot/conf:/etc/letsencrypt
19+
- ./data/certbot/www:/var/www/certbot
20+
- ./logs/letsencrypt:/var/log/letsencrypt
21+
- /etc/localtime:/etc/localtime:ro # for synchronize with host timezone
22+
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
23+
restart: always
24+
nginx:
25+
build:
26+
context: ./nginx
27+
dockerfile: Dockerfile
28+
args:
29+
- NGINX_CONF=${NGINX_CONF}
30+
env_file: .env_prod
31+
ports:
32+
- 80:80
33+
- 443:443
34+
volumes:
35+
- ./data/certbot/conf:/etc/letsencrypt
36+
- ./data/certbot/www:/var/www/certbot
37+
- ./logs/nginx:/var/log/nginx/
38+
- /etc/localtime:/etc/localtime:ro # for synchronize with host timezone
39+
command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
40+
links:
41+
- flight_review_app
42+
depends_on:
43+
- flight_review_app
44+
restart: always
45+
46+

0 commit comments

Comments
 (0)