Pericia.CleverCloudHelper 1.0.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 1.0.0-preview01                
NuGet\Install-Package Pericia.CleverCloudHelper -Version 1.0.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="1.0.0-preview01" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Pericia.CleverCloudHelper --version 1.0.0-preview01                
#r "nuget: Pericia.CleverCloudHelper, 1.0.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=1.0.0-preview01&prerelease

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

Pericia.CleverCloudHelper

Build status

NuGet

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.AddCcEnvironment() 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_HOST MongodbHost MongoDb:Host string
MONGODB_ADDON_DB MongodbDb MongoDb:Database string
MONGODB_ADDON_USER MongodbUser MongoDb:User string
MONGODB_ADDON_PASSWORD MongodbPassword MongoDb:Password string
MONGODB_ADDON_PORT MongodbPort MongoDb:Port string
MONGODB_ADDON_URI MongodbUri ConnectionStrings:MongoDb 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
ADDON_PULSAR_BINARY_PORT PulsarBinaryPort Pulsar:BinaryPort int
ADDON_PULSAR_BINARY_URL PulsarBinaryUrl Pulsar:BinaryUrl string
ADDON_PULSAR_HOSTNAME PulsarHostName Pulsar:HostName string
ADDON_PULSAR_HTTP_PORT PulsarHttpPort Pulsar:HttpPort int
ADDON_PULSAR_HTTP_URL PulsarHttpUrl Pulsar:HttpUrl string
ADDON_PULSAR_NAMESPACE PulsarNamespace Pulsar:Namespace string
ADDON_PULSAR_TENANT PulsarTenant Pulsar:Tenant string
ADDON_PULSAR_TOKEN PulsarToken Pulsar:Token string
BUCKET_HOST BucketHost Bucket:Host string
CELLAR_ADDON_HOST CellarHost Cellar:Host string
CELLAR_ADDON_KEY_ID CellarKeyId Cellar:KeyId string
CELLAR_ADDON_KEY_SECRET CellarKeySecret Cellar:KeySecret string
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
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 387 11/8/2022
1.0.0-preview01 145 11/1/2022
0.2.0-preview03 197 2/18/2022
0.2.0-preview02 210 2/10/2022
0.2.0-preview01 262 1/17/2022