Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[698] feat: Allow providing config directory via environment variables #700

Merged
merged 2 commits into from
Jan 2, 2025
Merged
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
3 changes: 2 additions & 1 deletion docker/headless/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ services:
image: philosowaffle/peloton-to-garmin:console-stable
environment:
- TZ=America/Chicago
- P2G_CONFIG_DIRECTORY=/app/config
volumes:
- ./configuration.local.json:/app/configuration.local.json
- ./config:/app/config
- ./output:/app/output
6 changes: 4 additions & 2 deletions docker/webui/docker-compose-ui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ services:
image: philosowaffle/peloton-to-garmin:api-stable
environment:
- TZ=America/Chicago
- P2G_CONFIG_DIRECTORY=/app/config
# ports:
# - 8001:8080 # optional, only if you plan to interact with the API directly
volumes:
- ./api.local.json:/app/configuration.local.json
- ./config/api/:/app/config
- ./data:/app/data # recommended for saving settings across restarts
- ./output:/app/output # optional, if you want access to the generated workout and log files

Expand All @@ -20,7 +21,8 @@ services:
- 8002:8080
environment:
- TZ=America/Chicago
- P2G_CONFIG_DIRECTORY=/app/config
volumes:
- ./webui.local.json:/app/configuration.local.json
- ./config/webui:/app/config
depends_on:
- p2g-api
10 changes: 10 additions & 0 deletions mkdocs/docs/configuration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ P2G supports configuration via

By default, P2G looks for a file named `configuration.local.json` in the same directory where it is run.

!!! tip
You can override where the config Directory is mounted in the docker container by setting the environment vairable `P2G_CONFIG_DIRECTORY`. P2G will expect to find a `configuration.local.json` file in the specified directory.

### Config Precedence

The following defines the precedence in which config definitions are honored. With the first items having higher precendence than the next items.
Expand Down Expand Up @@ -121,3 +124,10 @@ For nested config sections, continue to use the same naming convention of defini
```bash
P2G_OBSERVABILITY__SERILOG__WRITETO__0__NAME="File"
```
#### Additional Environment Variables

In addition to overriding config values, the following extra environment variables are also supported.

| ENV Variable | Required | Default | Description |
|:-------------|:---------|:--------|:--------------------------|
| `P2G_CONFIG_DIRECTORY` | false | P2G Directory | Tells P2G where to look for the `configuration.local.json` file |
3 changes: 2 additions & 1 deletion mkdocs/docs/install/docker-headless.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ This flavor of P2G runs without any user interface and relies on configuration f

1. Create a directory `p2g-headless`
1. Inside this folder create a [docker-compose.yaml](https://github.com/philosowaffle/peloton-to-garmin/blob/master/docker/headless/docker-compose.yaml) file in the directory
1. Also create a [configuration.local.json](https://github.com/philosowaffle/peloton-to-garmin/blob/master/configuration.example.json) file in the directory.
1. Within this same directory, also create a folder called `config`
1. Inside the `config` folder create the [configuration.local.json](https://github.com/philosowaffle/peloton-to-garmin/blob/master/configuration.example.json).
1. Edit the configuration file to use your Peloton and Garmin credentials
1. Open a terminal in this folder
1. Run: `docker-compose pull && docker-compose up -d`
Expand Down
39 changes: 6 additions & 33 deletions mkdocs/docs/install/docker-webui.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ P2G provides a website user interface. Some key features include:

1. Create a folder named `p2g-webui`
1. Inside this folder create [docker-compose.yaml](https://github.com/philosowaffle/peloton-to-garmin/blob/master/docker/webui/docker-compose-ui.yaml)
1. Also create [api.local.json](https://github.com/philosowaffle/peloton-to-garmin/blob/master/docker/webui/api.local.json)
1. Also create [webui.local.json](https://github.com/philosowaffle/peloton-to-garmin/blob/master/docker/webui/webui.local.json)
1. Open a terminal in this folder
1. Within this same directory, also create a folder called `config`
1. Create two more folders within the `config` directory: `api` and `webui`
1. Within the `api` folder, create [api.local.json](https://github.com/philosowaffle/peloton-to-garmin/blob/master/docker/webui/api.local.json)
1. Within the `webui` folder, create [webui.local.json](https://github.com/philosowaffle/peloton-to-garmin/blob/master/docker/webui/webui.local.json)
1. Open a terminal in the `p2g-webui` folder
1. Run: `docker-compose pull && docker-compose up -d`
1. This will pull the containers and start them up running in the background
1. You can close the terminal at this time
Expand All @@ -43,33 +45,4 @@ If you are migrating to the Web UI for the first time you will need to reconfigu

## Open Api

To access the Open API spec for P2G you will need to expose the below port on the Api docker container. The open API spec will be available at `http://localhost:8001/swagger`.

```yaml
version: "3.9"

services:
p2g-api:
container_name: p2g-api
image: philosowaffle/peloton-to-garmin:api-stable
environment:
- TZ=America/Chicago
ports:
- 8001:8080 # to access the api or swagger docs
volumes:
- ./api.local.json:/app/configuration.local.json
- ./data:/app/data
- ./output:/app/output

p2g-webui:
container_name: p2g-webui
image: philosowaffle/peloton-to-garmin:webui-stable
ports:
- 8002:8080
environment:
- TZ=America/Chicago
volumes:
- ./webui.local.json:/app/configuration.local.json
depends_on:
- p2g-api
```
To access the Open API spec for P2G you will need to expose port `8080` on the Api docker container. The open API spec will be available at `http://localhost:8001/swagger`.
4 changes: 2 additions & 2 deletions src/Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
Statics.AppType = Constants.ApiName;
Statics.MetricPrefix = Constants.ApiName;
Statics.TracingService = Constants.ApiName;
Statics.ConfigPath = Path.Join(Environment.CurrentDirectory, "configuration.local.json");
Statics.ConfigPath = Path.Join(Statics.DefaultConfigDirectory, "configuration.local.json");

///////////////////////////////////////////////////////////
/// HOST
///////////////////////////////////////////////////////////
var builder = WebApplication.CreateBuilder(args);

var configProvider = builder.Configuration.AddJsonFile(Statics.ConfigPath, optional: true, reloadOnChange: true)
.AddEnvironmentVariables(prefix: "P2G_")
.AddEnvironmentVariables(prefix: $"{Constants.EnvironmentVariablePrefix}_")
.AddCommandLine(args);

var config = new AppConfiguration();
Expand Down
4 changes: 2 additions & 2 deletions src/ClientUI/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static MauiApp CreateMauiApp()
Statics.AppType = Constants.ClientUIName;
Statics.MetricPrefix = Constants.ClientUIName;
Statics.TracingService = Constants.ClientUIName;
Statics.ConfigPath = Path.Join(Environment.CurrentDirectory, "configuration.local.json");
Statics.ConfigPath = Path.Join(Statics.DefaultConfigDirectory, "configuration.local.json");

Directory.CreateDirectory(Statics.DefaultOutputDirectory);

Expand All @@ -38,7 +38,7 @@ public static MauiApp CreateMauiApp()
InitObservabilityConfigFile("configuration.local.json", observabilityConfigFilePath);

var configProvider = builder.Configuration.AddJsonFile(observabilityConfigFilePath, optional: true, reloadOnChange: true)
.AddEnvironmentVariables(prefix: "P2G_");
.AddEnvironmentVariables(prefix: $"{Constants.EnvironmentVariablePrefix}_");

var config = new AppConfiguration();
ConfigurationSetup.LoadConfigValues(builder.Configuration, config);
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public static class Constants
public const string WebUIName = "p2g_webui";
public const string ClientUIName = "p2g_clientui";

public const string AppVersion = "4.3.1";
public const string AppVersion = "4.4.0-rc";
}
}
2 changes: 1 addition & 1 deletion src/Common/Dto/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public App()
public int PollingIntervalSeconds { get; set; }
public bool CheckForUpdates { get; set; }

public static string DataDirectory => Path.GetFullPath(Path.Join(Statics.DefaultDataDirectory, "data"));
public static string DataDirectory => Statics.DefaultDataDirectory;

public string WorkingDirectory => Statics.DefaultTempDirectory;
public string OutputDirectory => Statics.DefaultOutputDirectory;
Expand Down
6 changes: 4 additions & 2 deletions src/Common/Stateful/Statics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ public static class Statics
{
public static string AppType = "unknown";
public static string MetricPrefix = "p2g";
public static string TracingService = "p2g";
public static string TracingService = "p2g";

public static string DefaultConfigDirectory = Environment.GetEnvironmentVariable($"{Constants.EnvironmentVariablePrefix}_CONFIG_DIRECTORY") ?? Environment.CurrentDirectory;

public static string DefaultDataDirectory = Environment.CurrentDirectory;
public static string DefaultDataDirectory = Path.GetFullPath(Path.Join(Environment.CurrentDirectory, "data"));
public static string DefaultTempDirectory = Path.Join(Environment.CurrentDirectory, "working");
public static string DefaultOutputDirectory = Path.Join(Environment.CurrentDirectory, "output");

Expand Down
6 changes: 3 additions & 3 deletions src/ConsoleClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ static IHostBuilder CreateHostBuilder(string[] args)
{
configBuilder.Sources.Clear();

var configPath = Environment.CurrentDirectory;
if (args.Length > 0) configPath = args[0];
var configDirectory = Statics.DefaultConfigDirectory;
if (args.Length > 0) configDirectory = args[0];

Statics.ConfigPath = Path.Join(configPath, "configuration.local.json");
Statics.ConfigPath = Path.Join(configDirectory, "configuration.local.json");

configBuilder
.AddJsonFile(Statics.ConfigPath, optional: true, reloadOnChange: true)
Expand Down
4 changes: 2 additions & 2 deletions src/WebUI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
Statics.AppType = Constants.WebUIName;
Statics.MetricPrefix = Constants.WebUIName;
Statics.TracingService = Constants.WebUIName;
Statics.ConfigPath = Path.Join(Environment.CurrentDirectory, "configuration.local.json");
Statics.ConfigPath = Path.Join(Statics.DefaultConfigDirectory, "configuration.local.json");

///////////////////////////////////////////////////////////
/// HOST
///////////////////////////////////////////////////////////
var builder = WebApplication.CreateBuilder(args);

var configProvider = builder.Configuration.AddJsonFile(Statics.ConfigPath, optional: true, reloadOnChange: true)
.AddEnvironmentVariables(prefix: "P2G_")
.AddEnvironmentVariables(prefix: $"{Constants.EnvironmentVariablePrefix}_")
.AddCommandLine(args);

var config = new AppConfiguration();
Expand Down
14 changes: 5 additions & 9 deletions vNextReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
[![](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/philosowaffle) <span class="badge-buymeacoffee"><a href="https://www.buymeacoffee.com/philosowaffle" title="Donate to this project using Buy Me A Coffee"><img src="https://img.shields.io/badge/buy%20me%20a%20coffee-donate-yellow.svg" alt="Buy Me A Coffee donate button" /></a></span>
---

## Fixes
## Features

- [#683] Initial fix for Garmin Upload error. Additionally introduces new settings for configuring Garmin Api.

> [!CAUTION]
> **Windows App Users**
> When editing settings, you may encounter an issue where your mouse stops working within the P2G app. Keyboard navigation continues to work. If this happens, quit P2G and restart. I will be investigating how to get a proper fix for this on a future release.
- [#698] If using docker, you can now mount the config directory instead of the config file itself. Additionally, the location of the config directory can be overriddien via environment variable: `P2G_CONFIG_DIRECTORY`.

## Docker Tags

- Console
- `console-stable`
- `console-latest`
- `console-v4.3.1`
- `console-v4.4.0`
- `console-v4`
- Api
- `api-stable`
- `api-latest`
- `api-v4.3.1`
- `api-v4.4.0`
- `api-v4`
- WebUI
- `webui-stable`
- `webui-latest`
- `webui-v4.3.1`
- `webui-v4.4.0`
- `webui-v4`
Loading