Skip to content

Commit

Permalink
Merge pull request #1 from tcortega/features/docker-integration
Browse files Browse the repository at this point in the history
feat: adds dockerfile and docker-compose
  • Loading branch information
tcortega authored Jul 8, 2022
2 parents f8fb3e1 + 3ed29ba commit eedd4d7
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/appsettings.Development.json
**/.classpath
**/.dockerignore
**/.env
Expand All @@ -22,4 +23,4 @@
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
README.md
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -347,4 +347,7 @@ healthchecksdb
MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/
.ionide/
.template.config/

.idea/
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src

COPY ["./src/N-Tier.API/N-Tier.API.csproj", "src/N-Tier.API/"]
COPY ["./src/N-Tier.Application/N-Tier.Application.csproj", "src/N-Tier.Application/"]
COPY ["./src/N-Tier.Core/N-Tier.Core.csproj", "src/N-Tier.Core/"]
COPY ["./src/N-Tier.DataAccess/N-Tier.DataAccess.csproj", "src/N-Tier.DataAccess/"]
COPY ["./src/N-Tier.Shared/N-Tier.Shared.csproj", "src/N-Tier.Shared/"]

RUN dotnet restore "src/N-Tier.API/N-Tier.API.csproj"

COPY . .

WORKDIR "src/N-Tier.API/"
RUN dotnet build -c Release -o /app/build

FROM build AS publish
RUN dotnet publish -c Release -o /app/publish

FROM base AS runtime
WORKDIR /app

COPY --from=publish /app/publish .

ENTRYPOINT [ "dotnet", "N-Tier.API.dll" ]
7 changes: 7 additions & 0 deletions N-Tier.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "N-Tier.Application.UnitTest
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "N-Tier.Api.IntegrationTests", "tests\N-Tier.Api.IntegrationTests\N-Tier.Api.IntegrationTests.csproj", "{FD31F369-27D3-48B3-9FF7-F4A357F73B1E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docker", "docker", "{4C079880-AEA7-40E6-BA1A-F669D09BBC9D}"
ProjectSection(SolutionItems) = preProject
Dockerfile = Dockerfile
docker-compose.yml = docker-compose.yml
.dockerignore = .dockerignore
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: "3.9"
services:
db:
image: "mcr.microsoft.com/mssql/server"
environment:
SA_PASSWORD: "Admin123.?"
ACCEPT_EULA: "Y"
web:
build: .
ports:
- "5000:80"
depends_on:
- db
environment:
ASPNETCORE_ENVIRONMENT: "Production"
CONNECTION_STRING: "Server=db;Database=NTier;User=sa;Password=Admin123.?;"
12 changes: 12 additions & 0 deletions src/N-Tier.API/Controllers/HealthcheckController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Mvc;

namespace N_Tier.API.Controllers;

public class HealthcheckController : ApiController
{
[HttpGet]
public IActionResult Get()
{
return Ok();
}
}
25 changes: 0 additions & 25 deletions src/N-Tier.API/Dockerfile

This file was deleted.

16 changes: 16 additions & 0 deletions src/N-Tier.API/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,21 @@
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"Database": {
"UseInMemoryDatabase": true,
"ConnectionString": "Server=db;Database=NTier;User=sa;Password=Admin123.?;"
},
"JwtConfiguration": {
"SecretKey": "Super secret token key"
},
"SmtpSettings": {
"Server": "smtp.gmail.com",
"Port": 587,
"SenderName": "N-Tier",
"SenderEmail": "<account>@gmail.com",
"Username": "<account>@gmail.com",
"Password": "<account-password>"
}
}
4 changes: 2 additions & 2 deletions src/N-Tier.API/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
},
"AllowedHosts": "*",
"Database": {
"UseInMemoryDatabase": true,
"ConnectionString": "Data Source=(LocalDb)\\MSSQLLocalDB;Initial Catalog=NTier;Integrated Security=True"
"UseInMemoryDatabase": false,
"ConnectionString": "Server=db;Database=NTier;User=sa;Password=Admin123.?;"
},
"JwtConfiguration": {
"SecretKey": "Super secret token key"
Expand Down
11 changes: 2 additions & 9 deletions src/N-Tier.DataAccess/DataAccessDependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ private static void AddRepositories(this IServiceCollection services)
private static void AddDatabase(this IServiceCollection services, IConfiguration configuration)
{
var databaseConfig = configuration.GetSection("Database").Get<DatabaseConfiguration>();
var connectionString = string.IsNullOrEmpty(databaseConfig.ConnectionString) ? configuration["CONNECTION_STRING"] : databaseConfig.ConnectionString;

if (databaseConfig.UseInMemoryDatabase)
services.AddDbContext<DatabaseContext>(options =>
Expand All @@ -41,7 +42,7 @@ private static void AddDatabase(this IServiceCollection services, IConfiguration
});
else
services.AddDbContext<DatabaseContext>(options =>
options.UseSqlServer(databaseConfig.ConnectionString,
options.UseSqlServer(connectionString,
opt => opt.MigrationsAssembly(typeof(DatabaseContext).Assembly.FullName)));
}

Expand Down Expand Up @@ -69,11 +70,3 @@ private static void AddIdentity(this IServiceCollection services)
});
}
}

// TODO move outside?
public class DatabaseConfiguration
{
public bool UseInMemoryDatabase { get; set; }

public string ConnectionString { get; set; }
}
8 changes: 8 additions & 0 deletions src/N-Tier.DataAccess/DatabaseConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace N_Tier.DataAccess;

public class DatabaseConfiguration
{
public bool UseInMemoryDatabase { get; set; }

public string ConnectionString { get; set; }
}

0 comments on commit eedd4d7

Please sign in to comment.