Skip to content

Commit

Permalink
Docker compose with FrontDesk Blazor is working
Browse files Browse the repository at this point in the history
  • Loading branch information
ardalis committed Mar 30, 2021
1 parent 80cb9d9 commit f1e7aac
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ private void InitializeConnection(RabbitMqConfiguration settings)
catch (System.Exception ex)
{
_logger.LogError(ex, settings.ToString());
Thread.Sleep(5000); // let RabbitMQ service start in Docker Compose
throw;
}
}
Expand Down
11 changes: 6 additions & 5 deletions FrontDesk/src/FrontDesk.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@ public void ConfigureServices(IServiceCollection services)
options.AddPolicy(name: CORS_POLICY,
builder =>
{
builder.WithOrigins(baseUrlConfig.WebBase.Replace("host.docker.internal", "localhost").TrimEnd('/'));
builder.SetIsOriginAllowed(origin => new Uri(origin).Host == "localhost");
builder.AllowAnyMethod();
builder.AllowAnyHeader();
});
builder.WithOrigins(baseUrlConfig.WebBase.Replace("host.docker.internal", "localhost").TrimEnd('/'));
builder.SetIsOriginAllowed(origin => true);
//builder.SetIsOriginAllowed(origin => new Uri(origin).Host == "localhost");
builder.AllowAnyMethod();
builder.AllowAnyHeader();
});
});

services.AddControllers();
Expand Down
62 changes: 36 additions & 26 deletions FrontDesk/src/FrontDesk.Api/VetClinicPublicRabbitMqService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text;
using System;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -41,32 +42,41 @@ public VetClinicPublicRabbitMqService(

private void InitializeConnection(RabbitMqConfiguration settings)
{
var factory = new ConnectionFactory
try
{
HostName = settings.Hostname,
UserName = settings.UserName,
Password = settings.Password,
VirtualHost = settings.VirtualHost,
Port = settings.Port
};
_connection = factory.CreateConnection();
_channel = _connection.CreateModel();

_channel.ExchangeDeclare(_exchangeName, "direct",
durable: true,
autoDelete: false,
arguments: null);

_channel.QueueDeclare(queue: _queuein,
durable: true,
exclusive: false,
autoDelete: false,
arguments: null);

string routingKey = "appointment-confirmation";
_channel.QueueBind(_queuein, _exchangeName, routingKey: routingKey);

_logger.LogInformation($"*** Listening for messages on {_exchangeName}-{routingKey}...");
var factory = new ConnectionFactory
{
HostName = settings.Hostname,
UserName = settings.UserName,
Password = settings.Password,
VirtualHost = settings.VirtualHost,
Port = settings.Port
};
_connection = factory.CreateConnection();
_channel = _connection.CreateModel();

_channel.ExchangeDeclare(_exchangeName, "direct",
durable: true,
autoDelete: false,
arguments: null);

_channel.QueueDeclare(queue: _queuein,
durable: true,
exclusive: false,
autoDelete: false,
arguments: null);

string routingKey = "appointment-confirmation";
_channel.QueueBind(_queuein, _exchangeName, routingKey: routingKey);

_logger.LogInformation($"*** Listening for messages on {_exchangeName}-{routingKey}...");
}
catch (Exception ex)
{
_logger.LogError(ex, settings.ToString());
Thread.Sleep(5000); // let RabbitMQ service start in Docker Compose
throw;
}
}

protected override Task ExecuteAsync(CancellationToken stoppingToken)
Expand Down
4 changes: 2 additions & 2 deletions FrontDesk/src/FrontDesk.Api/appsettings.Docker.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"DefaultConnection": "Data Source=frontdesk-db;Initial Catalog=PluralsightDDD.FrontDesk;PersistSecurityInfo=True;User ID=sa;Password=P@ssW0rd!"
},
"baseUrls": {
"apiBase": "http://localhost/api/",
"webBase": "http://frontdesk-blazor/"
"apiBase": "http://localhost:5200/",
"webBase": "http://localhost:5100/blazor-frontdesk-demo/"
},
"Logging": {
"LogLevel": {
Expand Down
20 changes: 13 additions & 7 deletions FrontDesk/src/FrontDesk.Blazor.Host/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:5.0.102-ca-patch-buster-slim AS build
WORKDIR /src
COPY ["src/FrontDesk.Blazor.Host/FrontDesk.Blazor.Host.csproj", "src/FrontDesk.Blazor.Host/"]
RUN dotnet restore "src/FrontDesk.Blazor.Host/FrontDesk.Blazor.Host.csproj"
COPY . .
WORKDIR "/src/src/FrontDesk.Blazor.Host"
FROM mcr.microsoft.com/dotnet/sdk:5.0.201-buster-slim AS build
WORKDIR /app
# run this from repository root
COPY ./ ./
#RUN ls -lha .

RUN echo 'Building FrontDesk Blazor container'

WORKDIR /app/FrontDesk/src/FrontDesk.Blazor.Host
RUN ls -lha .
RUN dotnet restore -s "../FrontDesk.Blazor/deps" -s "https://api.nuget.org/v3/index.json"

RUN dotnet build "FrontDesk.Blazor.Host.csproj" -c Release -o /app/build

FROM build AS publish
Expand All @@ -19,4 +25,4 @@ RUN dotnet publish "FrontDesk.Blazor.Host.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "FrontDesk.Blazor.Host.dll"]
ENTRYPOINT ["dotnet", "FrontDesk.Blazor.Host.dll"]
10 changes: 6 additions & 4 deletions FrontDesk/src/FrontDesk.Blazor/FrontDesk.Blazor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<Content Include="nginx.conf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<None Include="wwwroot\_content\Telerik.UI.for.Blazor.Trial\js\telerik-blazor.js" />
</ItemGroup>

<ItemGroup>
Expand All @@ -24,10 +28,8 @@
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="5.0.4" />
<PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.9" />
<PackageReference Include="Telerik.DataSource" Version="2.0.8" />
<PackageReference Include="Telerik.Recurrence" Version="0.1.0" />
<PackageReference Include="Telerik.Documents.SpreadsheetStreaming" Version="2021.1.118" />
<PackageReference Include="Telerik.UI.for.Blazor.Trial" Version="2.21.0" />
<!--<PackageReference Include="Telerik.UI.for.Blazor.Trial.DDD" Version="2.21.0" />-->
<PackageReference Include="Pluralsight.DDD.Deps" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
7 changes: 4 additions & 3 deletions FrontDesk/src/FrontDesk.Blazor/nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
-->
<packageSources>
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<add key="nuget.telerik" value="https://nuget.telerik.com/nuget" />
<add key="infolder" value="../FrontDesk.Blazor/deps" />
<!--<add key="nuget.telerik" value="https://nuget.telerik.com/nuget" />-->
</packageSources>

<!-- Used to store credentials -->
<packageSourceCredentials>
<nuget.telerik>
<!--<nuget.telerik>
<add key="Username" value="your user name" />
<add key="ClearTextPassword" value="you password" />
<add key="ValidAuthenticationTypes" value="basic" />
</nuget.telerik>
</nuget.telerik>-->
</packageSourceCredentials>


Expand Down

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ services:
- rabbitmq
- frontdesk-db

frontdesk-blazor:
build:
context: .
dockerfile: ./FrontDesk/src/FrontDesk.Blazor.Host/Dockerfile
image: ddd.frontdesk.blazor
container_name: ddd.frontdesk.blazor
ports:
- 5100:80
environment:
- ASPNETCORE_ENVIRONMENT=Docker
- "ASPNETCORE_URLS=http://+"
restart: on-failure
depends_on:
- frontdesk-api

clinicmanagement-db:
image: mcr.microsoft.com/mssql/server:2019-CU3-ubuntu-18.04
container_name: ddd.clinicmanagement-db
Expand Down Expand Up @@ -89,4 +104,5 @@ services:
- "ASPNETCORE_URLS=http://+"
restart: on-failure
depends_on:
- rabbitmq
- mailserver

0 comments on commit f1e7aac

Please sign in to comment.