Skip to content
This repository was archived by the owner on Aug 1, 2021. It is now read-only.

Commit a8a5032

Browse files
committed
docker beta
1 parent ee8d1cc commit a8a5032

36 files changed

Lines changed: 2877 additions & 393 deletions

src/.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
.vscode
77
*/bin
88
*/obj
9-
**/.toolstarget
9+
**/.toolstarget
10+
node_modules/

src/Backend/Jp.Infra.CrossCutting.Identity/Context/ApplicationDbContext.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,6 @@ public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
1616
{
1717
}
1818

19-
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
20-
{
21-
// get the configuration from the app settings
22-
var config = new ConfigurationBuilder()
23-
.SetBasePath(Directory.GetCurrentDirectory())
24-
.AddJsonFile("appsettings.json")
25-
.Build();
26-
27-
// define the database to use
28-
optionsBuilder.UseSqlServer(config.GetConnectionString("SSOConnection"));
29-
}
30-
3119
protected override void OnModelCreating(ModelBuilder builder)
3220
{
3321
base.OnModelCreating(builder);

src/Backend/Jp.Infra.Data/Context/EventStoreSQLContext.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Jp.Infra.Data.Context
99
public class EventStoreSQLContext : DbContext
1010
{
1111
public DbSet<StoredEvent> StoredEvent { get; set; }
12+
public EventStoreSQLContext(DbContextOptions<EventStoreSQLContext> options) : base(options) {}
1213

1314
protected override void OnModelCreating(ModelBuilder modelBuilder)
1415
{
@@ -17,16 +18,5 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
1718
base.OnModelCreating(modelBuilder);
1819
}
1920

20-
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
21-
{
22-
// get the configuration from the app settings
23-
var config = new ConfigurationBuilder()
24-
.SetBasePath(Directory.GetCurrentDirectory())
25-
.AddJsonFile("appsettings.json")
26-
.Build();
27-
28-
// define the database to use
29-
optionsBuilder.UseSqlServer(config.GetConnectionString("SSOConnection"));
30-
}
3121
}
3222
}

src/Backend/Jp.Infra.Data/Context/JpContext.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,7 @@ public JpContext(DbContextOptions<JpContext> options
1212
}
1313
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
1414
{
15-
// get the configuration from the app settings
16-
var config = new ConfigurationBuilder()
17-
.SetBasePath(Directory.GetCurrentDirectory())
18-
.AddJsonFile("appsettings.json")
19-
.Build();
20-
21-
// define the database to use
22-
optionsBuilder.UseSqlServer(config.GetConnectionString("SSOConnection"));
15+
2316
}
2417
}
2518

src/Backend/Jp.UserManagement/Configuration/IdentityConfig.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Jp.Infra.CrossCutting.Identity.Context;
1+
using System;
2+
using Jp.Infra.CrossCutting.Identity.Context;
23
using Jp.Infra.CrossCutting.Identity.Entities.Identity;
34
using Jp.Infra.Data.Context;
45
using Microsoft.AspNetCore.Identity;
@@ -12,9 +13,11 @@ public static class IdentityConfig
1213
{
1314
public static IServiceCollection AddIdentity(this IServiceCollection services, IConfiguration configuration)
1415
{
15-
string connectionString = configuration.GetConnectionString("SSOConnection");
16+
var connectionString = Environment.GetEnvironmentVariable("SQLSERVER_CONNECTION") ?? configuration.GetConnectionString("SSOConnection");
17+
1618
services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(connectionString));
1719
services.AddDbContext<JpContext>(options => options.UseSqlServer(connectionString));
20+
services.AddDbContext<EventStoreSQLContext>(options => options.UseSqlServer(connectionString));
1821

1922
services.AddIdentity<UserIdentity, UserIdentityRole>()
2023
.AddEntityFrameworkStores<ApplicationDbContext>()

src/Backend/Jp.UserManagement/Configuration/SwaggerConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static IServiceCollection AddSwagger(this IServiceCollection services)
1616
Title = "Identity Server 4 User Management API ",
1717
Description = "Swagger surface",
1818
Contact = new Contact { Name = "Bruno Brito", Email = "bhdebrito@gmail.com", Url = "http://www.brunobrito.net.br" },
19-
License = new License { Name = "MIT", Url = "https://github.com/brunohbrito/CognitesServicesAzure-Example/blob/master/LICENSE" },
19+
License = new License { Name = "MIT", Url = "https://github.com/brunohbrito/JP-Project/blob/master/LICENSE" },
2020

2121
});
2222

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
2+
WORKDIR /app
3+
EXPOSE 5002
4+
EXPOSE 5003
5+
6+
FROM microsoft/dotnet:2.1-sdk AS build
7+
WORKDIR /src
8+
COPY ["Backend/Jp.UserManagement/Jp.UserManagement.csproj", "Backend/Jp.UserManagement/"]
9+
COPY ["Backend/Jp.Domain.Core/Jp.Domain.Core.csproj", "Backend/Jp.Domain.Core/"]
10+
COPY ["Backend/Jp.Infra.Data/Jp.Infra.Data.csproj", "Backend/Jp.Infra.Data/"]
11+
COPY ["Backend/Jp.Domain/Jp.Domain.csproj", "Backend/Jp.Domain/"]
12+
COPY ["Backend/Jp.Infra.CrossCutting.Bus/Jp.Infra.CrossCutting.Bus.csproj", "Backend/Jp.Infra.CrossCutting.Bus/"]
13+
COPY ["Backend/Jp.Infra.CrossCutting.Identity/Jp.Infra.CrossCutting.Identity.csproj", "Backend/Jp.Infra.CrossCutting.Identity/"]
14+
COPY ["Backend/Jp.Application/Jp.Application.csproj", "Backend/Jp.Application/"]
15+
COPY ["Backend/Jp.Infra.CrossCutting.IoC/Jp.Infra.CrossCutting.IoC.csproj", "Backend/Jp.Infra.CrossCutting.IoC/"]
16+
COPY ["Backend/Jp.Infra.CrossCutting.Tools/Jp.Infra.CrossCutting.Tools.csproj", "Backend/Jp.Infra.CrossCutting.Tools/"]
17+
RUN dotnet restore "Backend/Jp.UserManagement/Jp.UserManagement.csproj"
18+
COPY . .
19+
WORKDIR "/src/Backend/Jp.UserManagement"
20+
RUN dotnet build "Jp.UserManagement.csproj" -c Release -o /app
21+
22+
FROM build AS publish
23+
RUN dotnet publish "Jp.UserManagement.csproj" -c Release -o /app
24+
25+
FROM base AS final
26+
WORKDIR /app
27+
COPY --from=publish /app .
28+
ENTRYPOINT ["dotnet", "Jp.UserManagement.dll"]

src/Backend/Jp.UserManagement/Jp.UserManagement.csproj

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,6 @@
66
<DockerTargetOS>Linux</DockerTargetOS>
77
</PropertyGroup>
88

9-
<ItemGroup>
10-
<Compile Remove="Model\**" />
11-
<Compile Remove="wwwroot\**" />
12-
<Content Remove="Model\**" />
13-
<Content Remove="wwwroot\**" />
14-
<EmbeddedResource Remove="Model\**" />
15-
<EmbeddedResource Remove="wwwroot\**" />
16-
<None Remove="Model\**" />
17-
<None Remove="wwwroot\**" />
18-
</ItemGroup>
19-
209
<ItemGroup>
2110
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="3.2.0" />
2211
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="2.6.0" />
@@ -38,4 +27,11 @@
3827
<ProjectReference Include="..\Jp.Infra.Data\Jp.Infra.Data.csproj" />
3928
</ItemGroup>
4029

30+
<ItemGroup>
31+
<Content Update="appsettings.json">
32+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
33+
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
34+
</Content>
35+
</ItemGroup>
36+
4137
</Project>

src/Backend/Jp.UserManagement/Properties/launchSettings.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
"windowsAuthentication": false,
44
"anonymousAuthentication": true,
55
"iisExpress": {
6-
"applicationUrl": "http://localhost:57194",
7-
"sslPort": 44311
6+
"applicationUrl": "http://localhost:5003",
7+
"sslPort": 5002
88
}
99
},
1010
"profiles": {
1111
"IIS Express": {
1212
"commandName": "IISExpress",
1313
"launchBrowser": true,
1414
"environmentVariables": {
15+
"SQLSERVER_PORT": "1433",
16+
"SQLSERVER_HOST": "localhost",
17+
"SQLSERVER_PASSWORD": "@Password1",
1518
"ASPNETCORE_ENVIRONMENT": "Development"
1619
}
1720
},
@@ -20,14 +23,17 @@
2023
"launchBrowser": true,
2124
"launchUrl": "swagger/index.html",
2225
"environmentVariables": {
26+
"SQLSERVER_PORT": "1433",
27+
"SQLSERVER_HOST": "localhost",
28+
"SQLSERVER_PASSWORD": "@Password1",
2329
"ASPNETCORE_ENVIRONMENT": "Development"
2430
},
25-
"applicationUrl": "https://localhost:5003;http://localhost:5002"
31+
"applicationUrl": "http://localhost:5003;https://localhost:5002"
2632
},
2733
"Docker": {
2834
"commandName": "Docker",
2935
"launchBrowser": true,
30-
"launchUrl": "{Scheme}://localhost:{ServicePort}"
36+
"launchUrl": "{Scheme}://localhost:{ServicePort}/swagger/index.html"
3137
}
3238
}
3339
}

src/Backend/Jp.UserManagement/Startup.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using IdentityServer4.AccessTokenValidation;
1+
using System;
2+
using IdentityServer4.AccessTokenValidation;
23
using Jp.Infra.CrossCutting.IoC;
34
using Jp.UserManagement.Configuration;
45
using MediatR;
@@ -12,24 +13,24 @@ namespace Jp.UserManagement
1213
public class Startup
1314
{
1415
public IConfiguration Configuration { get; }
15-
public IHostingEnvironment Environment { get; }
16+
public IHostingEnvironment HostEnvironment { get; }
1617

17-
public Startup(IHostingEnvironment environment)
18+
public Startup(IHostingEnvironment hostEnvironment)
1819
{
1920
var builder = new ConfigurationBuilder()
20-
.SetBasePath(environment.ContentRootPath)
21+
.SetBasePath(hostEnvironment.ContentRootPath)
2122
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
22-
.AddJsonFile($"appsettings.{environment.EnvironmentName}.json", optional: true, reloadOnChange: true)
23+
.AddJsonFile($"appsettings.{hostEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true)
2324
.AddEnvironmentVariables();
2425

25-
if (environment.IsDevelopment())
26+
if (hostEnvironment.IsDevelopment())
2627
{
2728
builder.AddUserSecrets<Startup>();
2829
}
2930

3031
builder.AddEnvironmentVariables();
3132
Configuration = builder.Build();
32-
Environment = environment;
33+
HostEnvironment = hostEnvironment;
3334
}
3435
// This method gets called by the runtime. Use this method to add services to the container.
3536
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
@@ -48,7 +49,7 @@ public void ConfigureServices(IServiceCollection services)
4849
})
4950
.AddIdentityServerAuthentication(options =>
5051
{
51-
options.Authority = "http://localhost:5000";
52+
options.Authority = Environment.GetEnvironmentVariable("AUTHORITY") ?? "http://localhost:5000";
5253
options.RequireHttpsMetadata = false;
5354
options.ApiSecret = "Q&tGrEQMypEk.XxPU:%bWDZMdpZeJiyMwpLv4F7d**w9x:7KuJ#fy,E8KPHpKz++";
5455
options.ApiName = "UserManagementApi";
@@ -76,6 +77,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
7677
else
7778
{
7879
app.UseHsts();
80+
app.UseHttpsRedirection();
7981
}
8082

8183
app.UseAuthentication();

0 commit comments

Comments
 (0)