Compare commits

..

No commits in common. "34339b8021b14ee91cc744a59130e40210f46688" and "5ff2918d07c4338e58ab52ff43b95bad4bb86fdf" have entirely different histories.

9 changed files with 101 additions and 66 deletions

3
.gitignore vendored
View file

@ -4,6 +4,3 @@ lastStatisticsUpdate.txt
log.* log.*
state.txt state.txt
migrations migrations
# created when running development environment
mariadb/**

View file

@ -34,21 +34,12 @@ To run Surveillance using docker, decide between development/testing or producti
1. Clone this repository 1. Clone this repository
2. Run `docker compose -f docker-compose.yml -f docker-compose.dev.yml up` and wait for services to start up 2. Run `docker compose up` and wait for services to start up
3. Visit `http://localhost:8080/` in a browser; you should see an interactive OpenStreetMap 3. Visit `http://localhost:8080/` in a browser; you should see an interactive OpenStreetMap
4. You can see most cameras on the map immediately; the `data_handler` background process continuously applies updates from OpenStreetMap which become visible after refrshing the page _tbd.: Populate camera data_
5. Appending `-f docker-compose.dev.yml` applies these changes:
- PHP won't supress any errors; to disable this, remove `return;` in `./web/www/sunders/config.php`
- Making changes in the `web` will immediately apply them to the running containers; try modifying `web/www/sunders/index.php`
- Making changes in the `data_handler` will immediately apply them to the running containers (try modifying `data_handler/utils/update_camera.sh`)
- The host has access to database files at `./mariadb`
### Production ### Production
1. Close this repository 1. Close this repository
@ -57,9 +48,9 @@ To run Surveillance using docker, decide between development/testing or producti
3. Run `docker compose up` and wait for services to start up 3. Run `docker compose up` and wait for services to start up
3. Visit `http://localhost:8080/` in a browser; you should see an interactive OpenStreetMap 3. Visit `http://localhost:8080/` in a browser to open the web interface
4. You can see most cameras on the map immediately; the `data_handler` background process continuously applies updates from OpenStreetMap which become visible after refrshing the page _tbd.: Populate camera data_
## Surveillance nodes ## Surveillance nodes

72
docker-compose-dev.yml Normal file
View file

@ -0,0 +1,72 @@
services:
db:
image: mariadb:12.0.2
restart: unless-stopped
command: --max_allowed_packet=3250585600
environment:
MYSQL_ROOT_PASSWORD: rootpassword # ${{secrets.MYSQL_ROOT_PASSWORD}}
MYSQL_DATABASE: camera # ${{secrets.MYSQL_DATABASE}}
MYSQL_USER: camera # ${{secrets.MYSQL_USER}}
MYSQL_PASSWORD: camerapassword # ${{secrets.MYSQL_PASSWORD}}
volumes:
- ./mariadb:/var/lib/mysql:Z
healthcheck:
test: ["CMD", "mariadb-admin", "ping", "-h", "localhost", "-uroot", "-prootpassword"]
interval: 10s
timeout: 5s
start_period: 30s
retries: 5
web:
image: git.hamburg.ccc.de/ccchh/sunders/web:latest
restart: unless-stopped
environment:
MYSQL_HOST: db
MYSQL_DB: camera # ${{secrets.MYSQL_DATABASE}}
CAMERA_SELECT_USER: camera_select # ${{secrets.CAMERA_SELECT_USER}}
CAMERA_SELECT_USER_PASSWORD: camera_selectpassword # ${{secrets.CAMERA_SELECT_USER_PASSWORD}}
DEFAULT_ZOOM: 12
DEFAULT_LAT: 0
DEFAULT_LON: 0
DEFAULT_LANGUAGE: en
IMPRESSUM_URL: https://hamburg.ccc.de/imprint/
ports:
- "8081:80"
volumes:
- ./web/www/sunders:/var/www/html:Z
depends_on:
db:
condition: service_started
# all the way zoomed out, with hamburg at the center, at least one camera should be returned
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost/sync-state.php"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
data_handler:
image: git.hamburg.ccc.de/ccchh/sunders/data_handler:latest
restart: unless-stopped
environment:
MYSQL_HOST: db
MYSQL_DB: camera # ${{secrets.MYSQL_DATABASE}}
MYSQL_USER: root # ${{secrets.MYSQL_USER}}
MYSQL_PASSWORD: rootpassword # ${{secrets.MYSQL_ROOT_PASSWORD}}
CAMERA_USER: camera # ${{secrets.CAMERA_USER}}
CAMERA_USER_PASSWORD: camerapassword # ${{secrets.CAMERA_USER_PASSWORD}}
CAMERA_SELECT_USER: camera_select # ${{secrets.CAMERA_SELECT_USER}}
CAMERA_SELECT_USER_PASSWORD: camera_selectpassword # ${{secrets.CAMERA_SELECT_USER_PASSWORD}}
depends_on:
db:
condition: service_healthy
restart: true
# if the latest `update_camera_*.log` contains "error", fail the healthcheck
healthcheck:
test: ["CMD", "sh", "-c", "ls /var/log | grep '^update_camera_' | xargs -I {} sh -c 'grep -q error /var/log/{} || exit 0; exit 1'"]
interval: 10s
timeout: 5s
retries: 5
volumes:
mariadb:

View file

@ -1,15 +0,0 @@
services:
db:
volumes:
- ./mariadb:/var/lib/mysql:Z
web:
volumes:
- ./web/www/sunders:/var/www/html:Z
environment:
APP_ENV: development
data_handler:
volumes:
- ./data_handler/utils:/opt:Z
- ./data_handler/data_init:/opt/init/init.sql:Z

View file

@ -33,10 +33,12 @@ services:
ports: ports:
- "8081:80" - "8081:80"
depends_on: depends_on:
db: data_handler:
condition: service_started condition: service_started
# all the way zoomed out, with hamburg at the center, at least one camera should be returned
healthcheck: healthcheck:
test: ["CMD", "curl", "-f", "http://localhost/sync-state.php"] test: >
["CMD", "curl -s 'http://localhost/camera.php?bbox=-92.52991540527346,30.683278176916133,131.7689595947266,72.87186315234298&zoom=4&width=2552&height=867' | grep '^\[.+\]$'"]
interval: 10s interval: 10s
timeout: 5s timeout: 5s
start_period: 30s start_period: 30s

View file

@ -1,4 +1,5 @@
<?php <?php
error_reporting(0);
// Convert the content of the symbology JSON file to HTML. // Convert the content of the symbology JSON file to HTML.
function addListSymbology($jsonPath, $i18n, $i18nDefault) { function addListSymbology($jsonPath, $i18n, $i18nDefault) {
global $pathToWebFolder; global $pathToWebFolder;

View file

@ -1,4 +1,5 @@
<?php <?php
error_reporting(0);
include $pathToWebFolder.'config.php'; include $pathToWebFolder.'config.php';
define('MAX_POINTS_FOR_QUICKHULL', 3000); define('MAX_POINTS_FOR_QUICKHULL', 3000);

View file

@ -13,15 +13,4 @@
define('MYSQL_PASSWORD', getenv('CAMERA_SELECT_USER_PASSWORD') ?: ''); define('MYSQL_PASSWORD', getenv('CAMERA_SELECT_USER_PASSWORD') ?: '');
define('USE_STATISTICS', false); define('USE_STATISTICS', false);
$environment = getenv('APP_ENV') ?: 'production';
if ($environment === 'development') {
ini_set('display_errors', 1);
error_reporting(E_ALL);
return;
}
ini_set('display_errors', 0);
error_reporting(0);
?> ?>

View file

@ -2,10 +2,14 @@
error_reporting(0); error_reporting(0);
include $pathToWebFolder.'config.php'; include $pathToWebFolder.'config.php';
try {
/* Connect to database */
$mysqli = new mysqli(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DB); $mysqli = new mysqli(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DB);
if($mysqli->connect_errno) { if($mysqli->connect_errno) {
throw new Exception("Could not connect to database"); header('Content-type: application/json');
$result = '{"error":"error while connecting to db : ' . $mysqli->error . '"}';
echo $result;
exit;
} }
$syncstate_querry = $mysqli->query("SELECT * FROM sync_state WHERE k = 'sequenceNumber'"); $syncstate_querry = $mysqli->query("SELECT * FROM sync_state WHERE k = 'sequenceNumber'");
@ -20,11 +24,4 @@
header('Content-type: application/json; Charset : utf-8'); header('Content-type: application/json; Charset : utf-8');
echo $result; echo $result;
mysqli_report(MYSQLI_REPORT_OFF);
} catch (Exception $e) {
http_response_code(503);
header('Content-type: application/json');
$result = '{"error":"Database unavailable"}';
echo $result;
}
?> ?>