Skip to content

Conversation

@mpietruschka
Copy link

Hey,

every time I recreated my docker container I had to wait 24 hours until enough data has been collected to return some zimmermann calculation.

Persisting the observations in the containers working directory has been a good start, but didn't help in my case.

I added another environment Variable which is making the user able to define a different directory storing observations.json and geocoderCache.json.

  • process.env.PERSISTENCE_LOCATION

Furthermore I extended the Dockerfile. It is preset to use an anonymous volume storing those files. Its mounted into /data.

Regards

@mpietruschka mpietruschka changed the title add peristence to docker add persistence to docker Sep 19, 2023
@salbahra salbahra requested a review from Copilot June 6, 2025 23:45
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds support for persisting observation and geocoder cache files to a configurable directory in Docker.

  • Introduces the PERSISTENCE_LOCATION environment variable to override default storage paths.
  • Updates LocalWeatherProvider and Geocoder classes to use PERSISTENCE_LOCATION for their JSON files.
  • Adjusts the Dockerfile to create, own, and mount /data, and set PERSISTENCE_LOCATION by default.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
routes/weatherProviders/local.ts Added observationsFile property and switched file operations to use the env var.
routes/geocoders/Geocoder.ts Updated cacheFile path to respect PERSISTENCE_LOCATION or fall back to default.
Dockerfile Defines PERSISTENCE_LOCATION, prepares /data directory with correct ownership, and declares it as a volume.
Comments suppressed due to low confidence (2)

routes/geocoders/Geocoder.ts:7

  • Use path.join or path.resolve for building the cacheFile path to avoid hardcoded separators and improve cross-platform compatibility.
private static cacheFile: string = (process.env.PERSISTENCE_LOCATION || __dirname + "/../../..") + "/geocoderCache.json";

Dockerfile:2

  • Update the project’s README or other documentation to explain the new PERSISTENCE_LOCATION environment variable and its effect on file storage.
ENV PERSISTENCE_LOCATION=/data


export default class LocalWeatherProvider extends WeatherProvider {

public static observationsFile: string = ( process.env.PERSISTENCE_LOCATION ? process.env.PERSISTENCE_LOCATION + "/observations.json" : "observations.json");
Copy link

Copilot AI Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Construct file paths using Node’s path.join or path.resolve instead of manual string concatenation to ensure correct cross-platform behavior.

Copilot uses AI. Check for mistakes.

export default class LocalWeatherProvider extends WeatherProvider {

public static observationsFile: string = ( process.env.PERSISTENCE_LOCATION ? process.env.PERSISTENCE_LOCATION + "/observations.json" : "observations.json");
Copy link

Copilot AI Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback path "observations.json" is relative to the current working directory and may not resolve as expected; consider using __dirname or a configured base path for consistency.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant