Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to push the correct configuration data with C# worker service to swarm/kubernetes?

I have 3 configs in service:

1 - appsettings.development.json
2 - appsettings.testing.json
3 - appsettings.production.json

And i have 3 launch settings for them as well in launchsettings.json:

{
    "profiles": {
        "DevelopmentDockerProfile" {
            "commandName": "Docker",
            "environmentVariables": {
                "DOTNET_ENVIRONMENT": "development"
            }
        },
        "ProductionDockerProfile" {
            "commandName": "Docker",
            "environmentVariables": {
                "DOTNET_ENVIRONMENT": "production"
            }
        },
        "TestingDockerProfile" {
            "commandName": "Docker",
            "environmentVariables": {
                "DOTNET_ENVIRONMENT": "testing"
            }
        }
    }
}

And i can normally run service, using correct configuration only on local machine.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I can not push DOTNET_ENVIRONMENT variable with service when publishing.

Is there any way to bind environment variable to publishProfile.pubxml or whatever else, that environment variable DOTNET_ENVIRONMENT will magically appear in docker service on host machine?

>Solution :

Short answer

No, there is no such option.

Longer one

First of all, you can easily set environment variables using Environment.SetEnvironmentVariable("name", "value"). But that’s probably not what you want.

What you might want is to configure environment variables in configs for container/orchestration tool you use, either set in docker command line (docker run -e VARIABLE_NAME=value) or in docker-compose.yml for Docker Compose or in service YAML config for k8s.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading