-
Notifications
You must be signed in to change notification settings - Fork 1
Deployment of server & website
This describes a local, lightweight deployment for developing the RailTrail
- NodeJS version 18.16.0
- python3
- docker-compose
cd Railtrail/Server
docker-compose -f docker-compose-dev.yml build
docker-compose -f docker-compose-dev.yml up
Rename .env.example
to .env
cd Railtrail/Server
npm i
npm run prisma
npm run build
npm run start
cd Railtrail/Server
npm i
npm run prisma # ensure that the database is reachable
npm run dev
Rename .env.development
to .env
cd Railtrail/Website
npm i
npm run build
npm run start
Keep .env.development
file as is, DO NOT rename it. Then run:
cd Railtrail/Website
npm i
npm run dev
Page loads may be slow as pages are rendered on demand.
export BACKEND_URI=http://localhost:8080/api/tracker/oyster/lorawan
cd Railtrail/vehicle-simulator
python src/main.py
All these assume that the backend and the frontend are running using their default ports.
The Server/prisma/seed.ts
-script will add the first part of the database initialization. It will create an initial user if the associated environment variables are set and will add some vehicle-types and POI-types if there are none set yet.
Navigate to http://localhost:3000/management/add_track
, enter the name of both start and end of the track, then select the file containing the GeoJSON FeatureCollection<Point>
, serialized as JSON. Click on "Absenden" to add the track.
Add the tracker that is simulated by the vehicle simulator. Navigate to http://localhost:3000/management/trackers
, and enter the tracker name vehicle-simulator
. As there is no vehicle yet, leave that field empty. Click on "Hinzufügen" to add the tracker.
Navigate to http://localhost:3000/management/vehicles
. Leave the selection on "[Neues Fahrzeug hinzufügen]", and enter a name for the vehicle. Select the track, vehicle type, and tracker you have previously added.
To add some points of interest, navigate to http://localhost:3000/management/poi
. Another option is to use the restore script. This can be found in poi-backup-and-restore
and the poi-backup-and-restore/README.md
gives further explanation. This script requires a backup from an instance of RailTrail.
The vehicle simulator should now show up as an icon on the map at http://localhost:3000/map
, or as a list entry in http://localhost:3000/list
.
Points of Interest should also show up on the map at http://localhost:3000/map
.
This section explains how to inspect the database bypassing the backend. Doing this might be useful to triage problems.
Assuming that the database is running in a docker container named server-postgres-1
, execute
docker exec -ti server-postgres-1 bash
to obtain a shell inside of the database docker container. In there run
psql -d railtrail
for an interactive SQL shell.
Some useful commands might be:
SELECT COUNT(1) from "Log"; --- get the number of tracker logs in the database
SELECT * from "User"; --- Look up names of registered users
SELECT "uid", "name", "isTurningPoint", "typeId", "trackId" from "POI"; --- Get a compact list of known POIs
- docker
- docker-compose
For the most basic deployment, simply run docker compose up -d
in the /Server
directory or copy the docker-compose.yml and .env file to your server and run it from there. You don't have to clone the whole repo and build the images, since we publish images to the GitHub container registry.
When the pull-request to main is finally merged, there will be a docker image with tag main
, so you can change the tag development
to main
in the docker-compose.yml for railtrail-backend and railtrail-website.
In the .env file you can change the database name, user and password and the initial application user and password.
The other environment variables that configure our applications can be changed in the docker-compose.yml if needed.
A list of the configurable environment variables can be found in this wiki under Configuration
.
Beware that this deployment will have some flaws like missing TLS support, that are best solved with a reverse proxy that does TLS termination and routing.
The configuration of the reverse proxy depends on the choice of reverse proxy (e.g. Nginx, Apache, Traefik, Caddy, HAProxy, etc.).
For the reverse proxy configuration you need to match the domain/subdomain and route all requests that begin with /api/
to the railtrail-backend service. All other requests should be routed to the railtrail-website
service.
The website makes requests to the backend locally from the docker container but the app makes requests through the internet. That's why both services must be exposed through the reverse proxy.
In the docker-compose.yml you can change the ports
section to an expose
section with just the docker internal port to not open ports on the host machine (only the reverse proxy needs to). Then configure your reverse proxy to target the docker containers DNS name with the correct port.
Note that the website is configured with the BACKEND_URI
environment variable which must contain the full domain name and protocol where the backend is reachable without the path. The domain must be reachable from the railtrail-website docker container, so you could use the docker-DNS to route the traffic or you could feed it through the reverse proxy.
So either https://your-railtrail-domain.de
to go through the reverse proxy again or http://railtrail-backend:8080
to forward just via docker and HTTP (the latter should be a little more performant).
Always remember to change the password of the automatically created initial user in the .env file.
Make sure to change the backend URL in the app and recompile and distribute it. Only then it will communicate with the correct deployment of the backend.