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

feat(Config): Using environment variables for configuration paths and debug mode #41

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
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
10 changes: 7 additions & 3 deletions Copy/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@ internal class Config
/// <summary>
/// Path to the configuration file.
/// </summary>
public static string ConfigPath = Path.Combine(Directory.GetCurrentDirectory(), "config.json");
public static string ConfigPath = Environment.GetEnvironmentVariable("CONFIG_PATH") ??
Path.Combine(Directory.GetCurrentDirectory(), "config.json");

/// <summary>
/// Path to the scheme file.
/// </summary>
public static string SchemePath = Path.Combine(Directory.GetCurrentDirectory(), "scheme.json");
public static string SchemePath = Environment.GetEnvironmentVariable("SCHEME_PATH") ??
Path.Combine(Directory.GetCurrentDirectory(), "scheme.json");

/// <summary>
/// Indicates if the program is in debug mode.
/// </summary>
[JsonProperty("Debug", Required = Required.DisallowNull)]
public bool Debug { get; set; } = false;
public bool Debug { get; set; } = Environment.GetEnvironmentVariable("DEBUG")?.ToLower() == "true";

/// <summary>
/// List of clients.
/// </summary>
Expand Down
19 changes: 14 additions & 5 deletions Copy/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base
USER app
# See https://aka.ms/customizecontainer to learn how to customize your debug container
FROM mcr.microsoft.com/dotnet/runtime:8.0-alpine AS base
WORKDIR /app
# Configuration des variables d'environnement
ENV CONFIG_PATH=/app/config/config.json \
SCHEME_PATH=/app/config/scheme.json \
DEBUG=false

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["Copy/Copy.csproj", "Copy/"]
Expand All @@ -20,4 +22,11 @@ RUN dotnet publish "./Copy.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:Us
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .

# Création du répertoire pour la configuration
RUN mkdir -p /app/config

# Volume pour les fichiers de configuration
VOLUME /app/config

ENTRYPOINT ["dotnet", "Copy.dll"]