Skip to content

Commit

Permalink
Mejoro dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasdepetrisd committed Feb 21, 2024
1 parent 31b5758 commit 6e02aa9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 39 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ jobs:
heroku_app_name: ${{secrets.HEROKU_APP_NAME}}
heroku_email: ${{secrets.HEROKU_EMAIL}}
usedocker: true
appdir: "."
8 changes: 4 additions & 4 deletions src/WebAPI/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ EXPOSE 8080
EXPOSE 8081

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
ARG BUILD_CONFIGURATION=Development
WORKDIR /src
COPY ["src/WebAPI/WebAPI.csproj", "src/WebAPI/"]
COPY ["src/Application/Application.csproj", "src/Application/"]
COPY ["src/Domain/Domain.csproj", "src/Domain/"]
COPY ["src/Infraestructure/Infraestructure.csproj", "src/Infraestructure/"]
RUN dotnet restore "./src/WebAPI/WebAPI.csproj"
COPY . .
WORKDIR "/src/WebAPI"
RUN dotnet build "./WebAPI.csproj" -c $BUILD_CONFIGURATION -o /app/build
WORKDIR ./src/WebAPI
RUN dotnet build ./WebAPI.csproj -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
ARG BUILD_CONFIGURATION=Development
RUN dotnet publish "./WebAPI.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
Expand Down
51 changes: 17 additions & 34 deletions src/WebAPI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,6 @@
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

/*if (builder.Environment.EnvironmentName == "Production")
{
var connectionUrl = Environment.GetEnvironmentVariable("DATABASE_URL");
connectionUrl = connectionUrl.Replace("mssqlserver://", string.Empty);
var userPassSide = connectionUrl.Split("@")[0];
var hostSide = connectionUrl.Split("@")[1];
var user = userPassSide.Split(":")[0];
var password = userPassSide.Split(":")[1];
var host = hostSide.Split("/")[0];
var database = hostSide.Split("/")[1].Split("?")[0];
string defaultConnectionString = $"Host={host};Database={database};Username={user};Password={password};SSL Mode=Require;Trust Server Certificate=true";
// Layers DI
builder.Services
.AddApplication()
.AddInfraestructure(defaultConnectionString);
}
else
{
}*/

// Layers DI
builder.Services
.AddApplication()
Expand All @@ -49,22 +25,29 @@
// Configure the HTTP request pipeline.
app.UseStaticFiles();

if (app.Environment.IsDevelopment())
//if (app.Environment.IsDevelopment())
//{
app.UseSwagger();
//app.UseSwaggerThemes(Theme.OneDark);
app.UseSwaggerUI(options =>
{
app.UseSwagger();
//app.UseSwaggerThemes(Theme.OneDark);
app.UseSwaggerUI(options =>
{
options.DocExpansion(DocExpansion.None);
options.InjectStylesheet("/Swagger/SwaggerDark.css");
options.EnableTryItOutByDefault();
});
}
options.DocExpansion(DocExpansion.None);
options.InjectStylesheet("/Swagger/SwaggerDark.css");
options.EnableTryItOutByDefault();
});
//}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

if (app.Environment.IsProduction())
{
var port = Environment.GetEnvironmentVariable("PORT");
app.Urls.Add($"http://*:{port}");
}
/*var port = Environment.GetEnvironmentVariable("PORT") ?? "8080";
var host = Environment.GetEnvironmentVariable("applicationUrl") ?? "localhost";*/
app.Run();
3 changes: 2 additions & 1 deletion src/WebAPI/WebAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>558b52cc-0347-4758-9da5-b8f4d979b767</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>
<DockerfileFile>..\..\Dockerfile</DockerfileFile>
<DockerfileContext>..\..</DockerfileContext>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 6e02aa9

Please sign in to comment.