From a2a046aa713f2e28cde5518efba1d8e2114e57a2 Mon Sep 17 00:00:00 2001 From: Xander Sigler Date: Sat, 31 Dec 2022 00:34:49 -0800 Subject: [PATCH] Updated docker file to build and package the application and allowed Swagger page to be accessible in production mode --- AdventOfCode/Dockerfile | 27 +++++++++++++++++++++++++++ AdventOfCode/Startup.cs | 5 +++-- 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 AdventOfCode/Dockerfile diff --git a/AdventOfCode/Dockerfile b/AdventOfCode/Dockerfile new file mode 100644 index 0000000..ddaf901 --- /dev/null +++ b/AdventOfCode/Dockerfile @@ -0,0 +1,27 @@ +FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base +WORKDIR /app +EXPOSE 80 +EXPOSE 443 + +FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build +WORKDIR /src +COPY . ./ +RUN dotnet restore + +#COPY ["/src/AdventOfCode/AdventOfCode.csproj", "AdventOfCode/"] +RUN dotnet restore "AdventOfCode.csproj" +#COPY ["AdventOfCode/", "AdventOfCode/."] + + +RUN dotnet build "AdventOfCode.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "./AdventOfCode.csproj" -c Release -o /app/publish + +FROM base AS final +WORKDIR /app + +ENV ASPNETCORE_ENVIRONMENT=Production +ENV ASPNETCORE_URLS=http://+:80 +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "AdventOfCode.dll"] \ No newline at end of file diff --git a/AdventOfCode/Startup.cs b/AdventOfCode/Startup.cs index e0345f2..1be6edb 100644 --- a/AdventOfCode/Startup.cs +++ b/AdventOfCode/Startup.cs @@ -51,10 +51,11 @@ namespace AdventOfCode if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); - app.UseSwagger(); - app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "AdventOfCode v1")); } + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "AdventOfCode v1")); + app.UseHttpsRedirection(); app.UseRouting();