Skip to content

add persistence to docker - #144

Closed
mpietruschka wants to merge 1 commit into
OpenSprinkler:masterfrom
pietmacom:add_perstistence_to_docker
Closed

mpietruschka wants to merge 1 commit into
OpenSprinkler:masterfrom
pietmacom:add_perstistence_to_docker

Conversation

@mpietruschka

Copy link
Copy Markdown

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

Copilot AI left a comment

Copy link
Copy Markdown

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");

Copilot AI Jun 6, 2025

Copy link

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");

Copilot AI Jun 6, 2025

Copy link

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.
rayshobby added a commit that referenced this pull request Aug 10, 2026
Enable local observation persistence independently of the selected weather provider, parse the setting explicitly, and write state atomically to a configurable directory. Provide a persistent Docker data volume for observations and geocoder state.

Reimplements the behavior proposed in #144 and #150 against the current provider architecture.
@rayshobby

Copy link
Copy Markdown
Member

Thank you @mpietruschka. Persistent local PWS storage has now been implemented in an updated form through #180 and released in Weather Service 3.1.0, including documented persistent /data volume support. Closing this superseded PR.

@rayshobby rayshobby closed this Aug 12, 2026
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.

3 participants