Skip to content

Commit

Permalink
Updated docker configuration to include publishing the app for easier…
Browse files Browse the repository at this point in the history
… hosting.
  • Loading branch information
stijuh committed May 29, 2023
1 parent 650abee commit 3ef4340
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 52 deletions.
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM mcr.microsoft.com/dotnet/sdk:7.0 as build

WORKDIR /src

COPY ./GainsTracker.CoreAPI/GainsTracker.CoreAPI.csproj GainsTracker.CoreAPI/

RUN dotnet restore GainsTracker.CoreAPI/GainsTracker.CoreAPI.csproj

WORKDIR /src/GainsTracker.CoreAPI
COPY . .

RUN dotnet build GainsTracker.CoreAPI/GainsTracker.CoreAPI.csproj -c Release -o /app/build

FROM build AS publish
RUN dotnet publish GainsTracker.CoreAPI/GainsTracker.CoreAPI.csproj -c Release -o /app/publish --self-contained false

FROM mcr.microsoft.com/dotnet/aspnet:7.0 as runtime

ENV ASPNETCORE_URLS=http://*:4040
ENV ASPNETCORE_ENVIRONMENT=Development

WORKDIR /app
COPY --from=publish /app/publish .
EXPOSE 4040

ENTRYPOINT ["dotnet", "GainsTracker.CoreAPI.dll"]
2 changes: 1 addition & 1 deletion GainsTracker.ClientNative/GainsTracker.ClientNative.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
<None Remove="Resources\AppIcon\appiconfg.svg" />
<!-- <None Remove="Resources\AppIcon\appiconfg.svg" />-->
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static void RegisterEpicDependencies(this WebApplicationBuilder builder)
public static void ConfigureContextAndIdentity(this WebApplicationBuilder builder)
{
// Set DbContext.
builder.Services.AddDbContext<AppDbContext>(options => { options.UseNpgsql(builder.Configuration.GetConnectionString("databaseConnection")); });
builder.Services.AddDbContext<AppDbContext>(options => { options.UseNpgsql(builder.Configuration.GetConnectionString("databaseConnectionDocker")); });

// Map Identity to User and the database.
builder.Services.AddIdentity<User, IdentityRole>()
Expand Down
10 changes: 0 additions & 10 deletions GainsTracker.CoreAPI/Dockerfile

This file was deleted.

10 changes: 5 additions & 5 deletions GainsTracker.CoreAPI/GainsTracker.CoreAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.12" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.12"/>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3"/>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GainsTracker.Common\GainsTracker.Common.csproj" />
<ProjectReference Include="..\GainsTracker.Common\GainsTracker.Common.csproj"/>
</ItemGroup>
</Project>
68 changes: 38 additions & 30 deletions GainsTracker.CoreAPI/Program.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,53 @@
using System.Text.Json.Serialization;
using GainsTracker.CoreAPI.Configurations;

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
namespace GainsTracker.CoreAPI;

builder.Services.AddControllers()
.AddJsonOptions(options =>
public static class Program
{
public static void Main(string[] args)
{
options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
});
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddControllers()
.AddJsonOptions(options =>
{
options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
});

// Configuration.
builder.ConfigureContextAndIdentity();
builder.ConfigureAuthentication();
builder.AddSwaggerDocumentation();
builder.ConfigureCors();
builder.RegisterEpicDependencies();
builder.Services.AddEndpointsApiExplorer();

WebApplication app = builder.Build();
// Configuration.
builder.ConfigureContextAndIdentity();
builder.ConfigureAuthentication();
builder.AddSwaggerDocumentation();
builder.ConfigureCors();
builder.RegisterEpicDependencies();

app.ResetAndUpdateDatabase(false);
WebApplication app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.ResetAndUpdateDatabase();

app.UseCors("AllowBlazorDevClient");
app.UseHttpsRedirection();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

// Authentication
app.UseAuthentication();
app.UseAuthorization();
app.UseCors("AllowBlazorDevClient");
app.UseHttpsRedirection();

// Custom exception handling
app.AddGlobalErrorHandler();
// Authentication
app.UseAuthentication();
app.UseAuthorization();

app.MapControllers();
// Custom exception handling
app.AddGlobalErrorHandler();

app.Run();
app.MapControllers();

app.Run();
}
}
3 changes: 2 additions & 1 deletion GainsTracker.CoreAPI/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
}
},
"ConnectionStrings": {
"databaseConnection": "Host=db:5432; Database=gainstracker_db; Username=stoy; Password=postman"
"databaseConnection": "Host=localhost:15432; Database=gainstracker_db; Username=stoy; Password=postman",
"databaseConnectionDocker": "Host=db:5432; Database=gainstracker_db; Username=stoy; Password=postman"
},
"JWT": {
"ValidAudience": "http://localhost:4200",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Running "docker compose up" (active process)
# Running "docker compose up" (active process)
# or "docker compose start" (background process)
# will setup the development database
#
Expand All @@ -10,7 +10,7 @@
version: "3.7"
services:
db:
build: development/db
build: GainsTracker.CoreAPI/development/db
restart: always
ports:
- "15432:5432"
Expand All @@ -21,11 +21,11 @@ services:
DB_APP_USER: gainstracker_db
DB_APP_PASS: gainstracker_db
volumes:
- ./development/postgres/data:/var/lib/postgresql/data
- ./GainsTracker.CoreAPI/development/postgres/data:/var/lib/postgresql/data
api:
build: ./
restart: always
depends_on:
depends_on:
- db
ports:
- "420:4040" # funny

0 comments on commit 3ef4340

Please sign in to comment.