Pericia.CleverCloudHelper 0.2.0-preview01

This is a prerelease version of Pericia.CleverCloudHelper.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Pericia.CleverCloudHelper --version 0.2.0-preview01                
NuGet\Install-Package Pericia.CleverCloudHelper -Version 0.2.0-preview01                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Pericia.CleverCloudHelper" Version="0.2.0-preview01" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Pericia.CleverCloudHelper --version 0.2.0-preview01                
#r "nuget: Pericia.CleverCloudHelper, 0.2.0-preview01"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Pericia.CleverCloudHelper as a Cake Addin
#addin nuget:?package=Pericia.CleverCloudHelper&version=0.2.0-preview01&prerelease

// Install Pericia.CleverCloudHelper as a Cake Tool
#tool nuget:?package=Pericia.CleverCloudHelper&version=0.2.0-preview01&prerelease                

Pericia.CleverCloudHelper

Un peu d'aide pour configurer et d�ployer son application ASP.NET Core dans Clever Cloud

Chargement des ConnectionStrings

Lorsqu'on d�ploie une application li�e � une base de donn�es, les informations de connexion sont accessibles sous forme de variables d'environnement.

Pour les utiliser plus facilement, cette librairie les renvoie sous forme de ConnectionString :

CcEnvironment.MySqlConnectionString
CcEnvironment.PgsqlConnectionString

Afin d'acc�der � ces connection strings depuis la configuration, vous pouvez appeler builder.AddCcConnectionStrings() dans ConfigureAppConfiguration :

public static IWebHost BuildWebHost(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .ConfigureAppConfiguration((ctx, builder) =>
        {
            builder.SetBasePath(Directory.GetCurrentDirectory())
                        .AddJsonFile("appsettings.json")
                        .AddJsonFile($"appsettings.{ctx.HostingEnvironment.EnvironmentName}.json", optional: true)
                        .AddCcEnvironment()
                        .AddEnvironmentVariables();
            
            if (ctx.HostingEnvironment.IsDevelopment())
            {
                builder.AddUserSecrets<Startup>();
            }
        })
        .UseStartup<Startup>()
        .Build();

Afin de pouvoir utiliser des valeurs diff�rentes sur son poste de d�veloppement, ajoutez les chaines de connexion dans votre fichier appsettings.Development.json ou vos user secrets

{
    "ConnectionStrings": {
        "PostgreSql": "Host=localhost;Port=5432;Database=dbName;Username=usr;Password=pwd",
        "MySql": "Server=localhost;Port=3306;Database=dbName;Uid=usr;Pwd=pwd"
    }
}

Ainsi, vos chaines de connexion sont accessibles depuis IConfiguration :

configuration.GetConnectionString("PostgreSql");
configuration.GetConnectionString("MySql");

Autorisation du reverse-proxy Clever Cloud

Une fois d�ploy�e dans Clever Cloud, votre application sera derri�re un load-balancer, et il vous faudra donc la configurer en cons�quence.

Ajoutez l'appel � la m�thode services.ConfigureCcProxy(); dans ConfigureServices, et app.UseForwardedHeaders(); au d�but de Configure :

public void ConfigureServices(IServiceCollection services)
{
    services.ConfigureCcProxy();
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app.UseForwardedHeaders();

    app.Run(async (context) =>
    {
        context.Response.ContentType = "text/plain";
        await context.Response.WriteAsync("Request Url: " + context.Request.GetDisplayUrl());
    });
}

Variables d'environnement

Les principales variables d'environnement sont accessibles depuis la classe statique CcEnvironment, ou depuis IConfiguration (si vous avez appel� la m�thode builder.AddCcEnvironment()).

Common

Variable d'environnement Propri�t� Cl� configuration Type
INSTANCE_NUMBER InstanceNumber CleverCloud:InstanceNumber int?
INSTANCE_TYPE InstanceType CleverCloud:InstanceType string
INSTANCE_ID InstanceId CleverCloud:InstanceId string
CC_PRETTY_INSTANCE_NAME PrettyInstanceName CleverCloud:PrettyInstanceName string
APP_ID AppId CleverCloud:AppId string
APP_HOME AppHomePath CleverCloud:AppHomePath string
CC_DEPLOYMENT_ID DeploymentId CleverCloud:DeploymentId string
COMMIT_ID CommitId CleverCloud:CommitId string
CC_REVERSE_PROXY_IPS ReverseProxyIps string[]

.NET

Variable d'environnement Propri�t� Type
CC_DOTNET_VERSION DotnetVersion string
CC_DOTNET_PROJ DotnetProj string
CC_DOTNET_TFM DotnetTfm string
CC_DOTNET_PROFILE DotnetProfile string
CC_RUN_COMMAND RunCommand string

Addons

Variable d'environnement Propri�t� Cl� configuration Type
POSTGRESQL_ADDON_HOST PgsqlHost PostgreSql:Host string
POSTGRESQL_ADDON_PORT PgsqlPort PostgreSql:Port string
POSTGRESQL_ADDON_DB PgsqlDatabase PostgreSql:Database string
POSTGRESQL_ADDON_USER PgsqlUser PostgreSql:User string
POSTGRESQL_ADDON_PASSWORD PgsqlPassword PostgreSql:Password string
PgsqlConnectionString ConnectionStrings:PostgreSql string
MYSQL_ADDON_HOST MysqlHost MySql:Host string
MYSQL_ADDON_PORT MysqlPort MySql:Port string
MYSQL_ADDON_DB MysqlDatabase MySql:Database string
MYSQL_ADDON_USER MysqlUser MySql:User string
MYSQL_ADDON_PASSWORD MysqlPassword MySql:Password string
MySqlConnectionString ConnectionStrings:MySql string
MONGODB_ADDON_DB MongodbDb MongoDb:Database string
MONGODB_ADDON_USER MongodbUser MongoDb:User string
MONGODB_ADDON_PASSWORD MongodbPassword MongoDb:Password string
REDIS_HOST RedisHost Redis:Host string
REDIS_PORT RedisPort Redis:Port string
REDIS_PASSWORD RedisPassword Redis:Password string
ES_ADDON_URI ElasticsearchUri Elastic:Uri string
ES_ADDON_HOST ElasticsearchHost Elastic:Host string
ES_ADDON_USER ElasticsearchUser Elastic:User string
ES_ADDON_PASSWORD ElasticsearchPassword Elastic:Password string
ES_ADDON_KIBANA_HOST KibanaHost Kibana:Host string
ES_ADDON_KIBANA_USER KibanaUser Kibana:User string
ES_ADDON_KIBANA_PASSWORD KibanaPassword Kibana:Password string
ES_ADDON_APM_HOST ApmHost ElasticApm:ServerUrl string
ES_ADDON_APM_AUTH_TOKEN ApmAuthToken ElasticApm:SecretToken string
ES_ADDON_APM_USER ApmUser ElasticApm:User string
ES_ADDON_APM_PASSWORD ApmPassword ElasticApm:Password string
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 385 11/8/2022
1.0.0-preview01 143 11/1/2022
0.2.0-preview03 195 2/18/2022
0.2.0-preview02 208 2/10/2022
0.2.0-preview01 260 1/17/2022