diff --git a/Tsi1.Api/.dockerignore b/Tsi1.Api/.dockerignore new file mode 100644 index 0000000000000000000000000000000000000000..2e9693ed1a9619a49dcd4c7f3e9ea26541ff27d7 --- /dev/null +++ b/Tsi1.Api/.dockerignore @@ -0,0 +1,2 @@ +obj +bin \ No newline at end of file diff --git a/Tsi1.Api/Dockerfile b/Tsi1.Api/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..63e9ca89caa1cb56c4311a8ea3b1381f1faf050a --- /dev/null +++ b/Tsi1.Api/Dockerfile @@ -0,0 +1,23 @@ +# https://hub.docker.com/_/microsoft-dotnet-core +FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build +WORKDIR /app +EXPOSE 5000 + +# copy csproj and restore as distinct layers +WORKDIR /src +COPY Tsi1.Api/*.csproj ./Tsi1.Api/ +COPY Tsi1.BusinessLayer/*.csproj ./Tsi1.BusinessLayer/ +COPY Tsi1.DataLayer/*.csproj ./Tsi1.DataLayer/ +RUN dotnet dev-certs https -ep %USERPROFILE%\.aspnet\https\aspnetapp.pfx -p 111111 +RUN dotnet restore ./Tsi1.Api/Tsi1.Api.csproj + +# copy everything else and build app +COPY . ./ +WORKDIR /src/Tsi1.Api +RUN dotnet publish -c release -o /app/publish + +# final stage/image +FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 +WORKDIR /app +COPY --from=build /app/publish . +ENTRYPOINT ["dotnet", "Tsi1.Api.dll"] \ No newline at end of file diff --git a/Tsi1.Api/Tsi1.Api/Program.cs b/Tsi1.Api/Tsi1.Api/Program.cs index 50e6716c5925665dc0b091548bd2fc4b82d4b82c..e864adfcab4e11e1b7d69580b29ea8661d208789 100644 --- a/Tsi1.Api/Tsi1.Api/Program.cs +++ b/Tsi1.Api/Tsi1.Api/Program.cs @@ -21,6 +21,7 @@ namespace Tsi1.Api .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); + webBuilder.UseUrls("http://*:5000/"); }); } } diff --git a/Tsi1.Api/Tsi1.Api/Properties/launchSettings.json b/Tsi1.Api/Tsi1.Api/Properties/launchSettings.json index c733fd6ce95de3866e074b5acfe589be558c7f72..b1df540928120320c3f2a8333977bf6adef98e8d 100644 --- a/Tsi1.Api/Tsi1.Api/Properties/launchSettings.json +++ b/Tsi1.Api/Tsi1.Api/Properties/launchSettings.json @@ -21,7 +21,7 @@ "commandName": "Project", "launchBrowser": true, "launchUrl": "swagger/index.html", - "applicationUrl": "https://localhost:5001;http://localhost:5000", + "applicationUrl": "http://localhost:5000", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/Tsi1.Api/Tsi1.Api/Startup.cs b/Tsi1.Api/Tsi1.Api/Startup.cs index c2039f807c016c5a5cc472fab047c366d4234e7d..6d81c782a6874fe01d7d13bd1692e974f6e06fcc 100644 --- a/Tsi1.Api/Tsi1.Api/Startup.cs +++ b/Tsi1.Api/Tsi1.Api/Startup.cs @@ -40,10 +40,15 @@ namespace Tsi1.Api { services.AddControllers(); - services.AddDbContext<Tsi1Context>(x => x.UseNpgsql(Configuration.GetConnectionString("PostgreSql"))); + var isElasticCloud = bool.Parse(Configuration.GetSection("IsElasticCloud").Value); + + var postgreSqlSection = isElasticCloud ? "PostgreSqlCloud" : "PostgreSql"; + var mongoDbSection = isElasticCloud ? "Tsi1DatabaseSettingsCloud" : "Tsi1DatabaseSettings"; + + services.AddDbContext<Tsi1Context>(x => x.UseNpgsql(Configuration.GetConnectionString(postgreSqlSection))); services.Configure<Tsi1DatabaseSettings>( - Configuration.GetSection(nameof(Tsi1DatabaseSettings))); + Configuration.GetSection(mongoDbSection)); services.AddSingleton<ITsi1DatabaseSettings>(sp => sp.GetRequiredService<IOptions<Tsi1DatabaseSettings>>().Value); @@ -131,7 +136,7 @@ namespace Tsi1.Api app.UseDeveloperExceptionPage(); } - app.UseHttpsRedirection(); + // app.UseHttpsRedirection(); app.UseSwagger(); app.UseSwaggerUI(c => diff --git a/Tsi1.Api/Tsi1.Api/appsettings.json b/Tsi1.Api/Tsi1.Api/appsettings.json index e637ca6e8eb7e6a16d907ad18a2eb348b0fe590c..a12bc5f6e104663e378e9f4150cf6c1483aa187e 100644 --- a/Tsi1.Api/Tsi1.Api/appsettings.json +++ b/Tsi1.Api/Tsi1.Api/appsettings.json @@ -1,16 +1,23 @@ { + "IsElasticCloud": true, "ConnectionStrings": { - "PostgreSql": "Host=localhost;Database=tsi1;Username=postgres;Password=111111" + "PostgreSql": "Host=localhost;Database=tsi1;Username=postgres;Password=111111", + "PostgreSqlCloud": "Host=postgres;Database=tsi1;Username=postgres;Password=postgres" }, "Tsi1DatabaseSettings": { "Tsi1CollectionName": "Messages", "ConnectionString": "mongodb://localhost:27017", "DatabaseName": "Tsi1Db" }, + "Tsi1DatabaseSettingsCloud": { + "Tsi1CollectionName": "Messages", + "ConnectionString": "mongodb://mongo:27017", + "DatabaseName": "Tsi1Db" + }, "jwtTokenConfig": { "secret": "1234567890123456789", - "issuer": "https://localhost:44363", - "audience": "https://localhost:44363", + "issuer": "https://localhost:5000", + "audience": "https://localhost:5000", "accessTokenExpiration": 20, "refreshTokenExpiration": 60 },