diff --git a/software/tracksight/docker/README.md b/software/tracksight/docker/README.md index d0e9643988..68c0c76723 100644 --- a/software/tracksight/docker/README.md +++ b/software/tracksight/docker/README.md @@ -3,6 +3,8 @@ ### tl;dr/dgaf Run `docker-compose.sh ` +If containers are acting weird, likely due to leftover containers, run `clean-up-container.sh` + ### Philosphy Docker containers here are used as a runtime environment for the code. This means that it carries the @@ -24,4 +26,4 @@ There are a few important design decisions made because of this philosophy: 1. **No code in the container**: The code is mounted as a volume in the container. This means that the code is not part of the container image. This is important because the code is the most frequently changing part of the system. This also means that the container can be used for multiple codebases. 2. **No environment variables in the code**: The environment variables are passed to the container at runtime. This means that the code is not dependent on the environment variables. This is important because the environment variables are the most frequently changing part of the system. This also means that the container can be used for multiple environments. -3. **No dependencies in the code**: The dependencies are installed in the container. This means that the code is not dependent on the dependencies. This is important because the dependencies are the most frequently changing part of the system. This also means that the container can be used for multiple dependencies. \ No newline at end of file +3. **No dependencies in the code**: The dependencies are installed in the container. This means that the code is not dependent on the dependencies. This is important because the dependencies are the most frequently changing part of the system. This also means that the container can be used for multiple dependencies. diff --git a/software/tracksight/docker/clean-up-containers.sh b/software/tracksight/docker/clean-up-containers.sh new file mode 100755 index 0000000000..c49838b06e --- /dev/null +++ b/software/tracksight/docker/clean-up-containers.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# Cleans up stale Docker containers and networks left behind by previous +# Tracksight compose runs (e.g. all.yml, db_only.yml, db_backend.yml). +# +# Symptoms this fixes: +# - backend panics with "dns error ... failed to lookup address information" +# - a service is "healthy" but not actually attached to its network +# - influx port not published / unreachable on localhost:8086 +# +# Usage: ./docker-clean.sh + +cd "$(dirname "$0")" || exit 1 + +if ! [ -f "envs/common.env" ]; then + echo "common.env does not exist! Create one with the template in ./envs." + exit 1 +fi + +# Bring down every compose project defined under ./configs. Each config sets its +# own project `name:`, so `down` targets the correct project and removes its +# containers and default network. --remove-orphans clears renamed/removed services. +for config in configs/*.yml; do + [ -f "$config" ] || continue + echo "Tearing down $config ..." + docker compose --env-file envs/common.env -f "$config" down --remove-orphans +done + +# Catch any stray Tracksight containers that aren't tracked by the configs above +# (e.g. from an old project name or a half-removed run). +stray=$(docker ps -aq --filter "name=tracksight-") +if [ -n "$stray" ]; then + echo "Removing stray tracksight containers ..." + docker rm -f $stray +fi + +# Remove dangling networks (including broken ones that leave services unattached). +echo "Pruning unused networks ..." +docker network prune -f diff --git a/software/tracksight/docker/common.yml b/software/tracksight/docker/common.yml index de7eb02be5..93b08303a8 100644 --- a/software/tracksight/docker/common.yml +++ b/software/tracksight/docker/common.yml @@ -5,6 +5,12 @@ services: # InfluxDB port is always 8086 internally - "${INFLUXDB_PORT}:8086" env_file: envs/influx.env + volumes: + # Persist InfluxDB data and config across container recreations. + # These named volumes survive `docker compose down` and image rebuilds; + # they are only deleted by `docker compose down -v` or `docker volume rm`. + - influx-data:/var/lib/influxdb2 + - influx-config:/etc/influxdb2 healthcheck: # Ping server every 30s in case something breaks. test: [ "CMD", "curl", "-f", "http://localhost:8086/health" ] diff --git a/software/tracksight/docker/configs/all.yml b/software/tracksight/docker/configs/all.yml index c0d5ce16b6..249c27b46e 100644 --- a/software/tracksight/docker/configs/all.yml +++ b/software/tracksight/docker/configs/all.yml @@ -17,3 +17,6 @@ services: "npm", "start" ] +volumes: + influx-data: + influx-config: diff --git a/software/tracksight/docker/configs/db_backend.yml b/software/tracksight/docker/configs/db_backend.yml index 60d7e1f333..ba2a282efd 100644 --- a/software/tracksight/docker/configs/db_backend.yml +++ b/software/tracksight/docker/configs/db_backend.yml @@ -8,3 +8,6 @@ services: extends: file: ../common.yml service: backend +volumes: + influx-data: + influx-config: diff --git a/software/tracksight/docker/configs/db_only.yml b/software/tracksight/docker/configs/db_only.yml index c8e62bff11..187334b310 100644 --- a/software/tracksight/docker/configs/db_only.yml +++ b/software/tracksight/docker/configs/db_only.yml @@ -4,3 +4,6 @@ services: extends: file: ../common.yml service: influx +volumes: + influx-data: + influx-config: diff --git a/software/tracksight/docker/influxdb-volumes.md b/software/tracksight/docker/influxdb-volumes.md new file mode 100644 index 0000000000..ca51a16da5 --- /dev/null +++ b/software/tracksight/docker/influxdb-volumes.md @@ -0,0 +1,19 @@ +### InfluxDB data persistence + +InfluxDB data is stored in named Docker volumes (`influx-data`, `influx-config`) declared in each config under `docker/configs/`. These volumes live independently of the container. + +- Safe (data preserved): `docker compose ... down`, `docker compose ... up --build`, removing/recreating containers, upgrading the image. +- Destructive (wipes data): `docker compose ... down -v`, `docker volume rm tracksight-docker_influx-data`, or pruning all volumes. + +To inspect/back up the data volume: +``` +docker volume ls | grep influx +docker run --rm -v tracksight-docker_influx-data:/data -v $PWD:/backup alpine \ + tar czf /backup/influx-data.tgz -C /data . +``` +(The volume name prefix matches the `name:` field in your chosen config — `tracksight-docker`, `tracksight-wireless`, or `tracksight-db`.) + +To clean volumes: +``` +docker volume rm +```