Browse Source

add more stuff

master
david 3 years ago
parent
commit
9348d80d9d
  1. 2
      .dockerignore
  2. 20
      Dockerfile
  3. 15
      README.md
  4. 8
      docker-compose.yml
  5. 9
      index.js
  6. 95
      package-lock.json
  7. 5
      package.json
  8. 36
      serviceWrapper.bash
  9. 27
      supervisord.conf

2
.dockerignore

@ -3,3 +3,5 @@ rubbish/
db.sqlite3
data.csv
public/styles/style.css
README.md
Dockerfile

20
Dockerfile

@ -1,10 +1,16 @@
FROM nikolaik/python-nodejs:python3.9-nodejs16-alpine AS builder
WORKDIR /app
COPY . ./
RUN NODE_ENV=development npm install \
&& NODE_ENV=production npm run build:css \
&& rm -rf node_modules \
&& NODE_ENV=production npm install
FROM nikolaik/python-nodejs:python3.9-nodejs16-alpine
ENV PYTHONUNBUFFERED=1 NODE_ENV=production
ENV PYTHONUNBUFFERED=1 NODE_ENV=production TZ=Australia/Sydney
WORKDIR /app
COPY ./netmon.py ./
CMD [ "python", "./netmon.py" , "monitor" ]
RUN pip install supervisor
COPY --from=builder /app ./
ENTRYPOINT ["supervisord", "-c", "/app/supervisord.conf"]
# copy index/views/public/pkg.json/postcss/tailwind configs
#npm i
#build css
#run supervisord or wrapper
EXPOSE 3000

15
README.md

@ -1,6 +1,19 @@
# netmon
bunch of misc cmds
super basic way to run
```
touch db.sqlite3
docker run --rm -d \
--name netmon \
-p 4000:3000 \
-e dstHost=1.1.1.1 \
-e dstPort=53 \
--mount type=bind,source=$(pwd)/db.sqlite3,target=/app/db.sqlite3 \
daveplsno/netmon:latest
```
bunch of misc cmds used along the way
```
docker run --rm -it --name pls -w /app -p 3000:3000 -p 5000:5000 -e dstHost=localhost -e dstPort=8000 -e TZ=Australia/Sydney -v /home/blender/projects/netmon:/app nikolaik/python-nodejs:python3.9-nodejs16-alpine sh

8
docker-compose.yml

@ -0,0 +1,8 @@
---
version: '3.7'
services:
netmon-build:
build:
context: .
image: daveplsno/netmon:latest

9
index.js

@ -1,4 +1,6 @@
const express = require('express');
const helmet = require('helmet');
const compression = require('compression');
const app = express();
const port = 3000;
const path = require('path');
@ -9,6 +11,13 @@ app.set('views', __dirname + '/views');
app.set('view engine', 'jsx');
app.engine('jsx', require('express-react-views').createEngine());
app.use(express.static(path.join(__dirname, '/public')));
app.use(
helmet({
referrerPolicy: false,
contentSecurityPolicy: false,
})
);
app.use(compression());
const db = require('./database.js');

95
package-lock.json generated

@ -1,14 +1,16 @@
{
"name": "netmon",
"name": "app",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"dependencies": {
"compression": "^1.7.4",
"dayjs": "^1.10.6",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"express-react-views": "^0.11.0",
"helmet": "^4.6.0",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"sqlite3": "^5.0.2"
@ -2569,6 +2571,42 @@
"resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz",
"integrity": "sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs="
},
"node_modules/compressible": {
"version": "2.0.18",
"resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz",
"integrity": "sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg==",
"dependencies": {
"mime-db": ">= 1.43.0 < 2"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/compression": {
"version": "1.7.4",
"resolved": "https://registry.npmjs.org/compression/-/compression-1.7.4.tgz",
"integrity": "sha512-jaSIDzP9pZVS4ZfQ+TzvtiWhdpFhE2RDHz8QJkpX9SIpLq88VueF5jJw6t+6CUQcAoA6t+x89MLrWAqpfDE8iQ==",
"dependencies": {
"accepts": "~1.3.5",
"bytes": "3.0.0",
"compressible": "~2.0.16",
"debug": "2.6.9",
"on-headers": "~1.0.2",
"safe-buffer": "5.1.2",
"vary": "~1.1.2"
},
"engines": {
"node": ">= 0.8.0"
}
},
"node_modules/compression/node_modules/bytes": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz",
"integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@ -3562,6 +3600,14 @@
"node": ">=8"
}
},
"node_modules/helmet": {
"version": "4.6.0",
"resolved": "https://registry.npmjs.org/helmet/-/helmet-4.6.0.tgz",
"integrity": "sha512-HVqALKZlR95ROkrnesdhbbZJFi/rIVSoNq6f3jA/9u6MIbTsPh3xZwihjeI5+DO/2sOV6HMHooXcEOuwskHpTg==",
"engines": {
"node": ">=10.0.0"
}
},
"node_modules/html-tags": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/html-tags/-/html-tags-3.1.0.tgz",
@ -4715,6 +4761,14 @@
"node": ">= 0.8"
}
},
"node_modules/on-headers": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz",
"integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
@ -8617,6 +8671,35 @@
"resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz",
"integrity": "sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs="
},
"compressible": {
"version": "2.0.18",
"resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz",
"integrity": "sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg==",
"requires": {
"mime-db": ">= 1.43.0 < 2"
}
},
"compression": {
"version": "1.7.4",
"resolved": "https://registry.npmjs.org/compression/-/compression-1.7.4.tgz",
"integrity": "sha512-jaSIDzP9pZVS4ZfQ+TzvtiWhdpFhE2RDHz8QJkpX9SIpLq88VueF5jJw6t+6CUQcAoA6t+x89MLrWAqpfDE8iQ==",
"requires": {
"accepts": "~1.3.5",
"bytes": "3.0.0",
"compressible": "~2.0.16",
"debug": "2.6.9",
"on-headers": "~1.0.2",
"safe-buffer": "5.1.2",
"vary": "~1.1.2"
},
"dependencies": {
"bytes": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz",
"integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg="
}
}
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@ -9391,6 +9474,11 @@
"integrity": "sha512-UqBRqi4ju7T+TqGNdqAO0PaSVGsDGJUBQvk9eUWNGRY1CFGDzYhLWoM7JQEemnlvVcv/YEmc2wNW8BC24EnUsw==",
"dev": true
},
"helmet": {
"version": "4.6.0",
"resolved": "https://registry.npmjs.org/helmet/-/helmet-4.6.0.tgz",
"integrity": "sha512-HVqALKZlR95ROkrnesdhbbZJFi/rIVSoNq6f3jA/9u6MIbTsPh3xZwihjeI5+DO/2sOV6HMHooXcEOuwskHpTg=="
},
"html-tags": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/html-tags/-/html-tags-3.1.0.tgz",
@ -10292,6 +10380,11 @@
"ee-first": "1.1.1"
}
},
"on-headers": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz",
"integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA=="
},
"once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",

5
package.json

@ -1,9 +1,11 @@
{
"dependencies": {
"compression": "^1.7.4",
"dayjs": "^1.10.6",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"express-react-views": "^0.11.0",
"helmet": "^4.6.0",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"sqlite3": "^5.0.2"
@ -21,6 +23,7 @@
"dev": "npm run build:css && nodemon index.js",
"testHost": "python -m http.server 8000",
"netmon": "python netmon.py monitor",
"prod": "NODE_ENV=production node index.js "
"prod": "NODE_ENV=production node index.js ",
"prodTest": "NODE_ENV=production npm run build:css && NODE_ENV=production node index.js "
}
}

36
serviceWrapper.bash

@ -1,36 +0,0 @@
#!/bin/bash
# Start the first process
./my_first_process -D
status=$?
if [ $status -ne 0 ]; then
echo "Failed to start my_first_process: $status"
exit $status
fi
# Start the second process
./my_second_process -D
status=$?
if [ $status -ne 0 ]; then
echo "Failed to start my_second_process: $status"
exit $status
fi
# Naive check runs checks once a minute to see if either of the processes exited.
# This illustrates part of the heavy lifting you need to do if you want to run
# more than one service in a container. The container exits with an error
# if it detects that either of the processes has exited.
# Otherwise it loops forever, waking up every 60 seconds
while sleep 60; do
ps aux |grep my_first_process |grep -q -v grep
PROCESS_1_STATUS=$?
ps aux |grep my_second_process |grep -q -v grep
PROCESS_2_STATUS=$?
# If the greps above find anything, they exit with 0 status
# If they are not both 0, then something is wrong
if [ $PROCESS_1_STATUS -ne 0 -o $PROCESS_2_STATUS -ne 0 ]; then
echo "One of the processes has already exited."
exit 1
fi
done

27
supervisord.conf

@ -0,0 +1,27 @@
[supervisord]
user=root
nodaemon=true
logfile=/app/supervisord.log
logfile_maxbytes=0
pidfile=/var/run/supervisord.pid
loglevel = INFO
[program:netmon]
command = python netmon.py monitor
autostart=true
autorestart=true
priority=5
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[program:express]
command = npm run prod
autostart=true
autorestart=true
priority=5
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
Loading…
Cancel
Save