Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion software/tracksight/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
### tl;dr/dgaf
Run `docker-compose.sh <YourComposeFile.yml>`

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
Expand All @@ -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.
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.
38 changes: 38 additions & 0 deletions software/tracksight/docker/clean-up-containers.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions software/tracksight/docker/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down
3 changes: 3 additions & 0 deletions software/tracksight/docker/configs/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ services:
"npm",
"start"
]
volumes:
influx-data:
influx-config:
3 changes: 3 additions & 0 deletions software/tracksight/docker/configs/db_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ services:
extends:
file: ../common.yml
service: backend
volumes:
influx-data:
influx-config:
3 changes: 3 additions & 0 deletions software/tracksight/docker/configs/db_only.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ services:
extends:
file: ../common.yml
service: influx
volumes:
influx-data:
influx-config:
19 changes: 19 additions & 0 deletions software/tracksight/docker/influxdb-volumes.md
Original file line number Diff line number Diff line change
@@ -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 <volume name>
```
Loading