From 6c3b9f2601f54d73f84b8dde1c3e8eeac3804497 Mon Sep 17 00:00:00 2001 From: Julien Leicher Date: Tue, 15 Dec 2020 15:49:23 +0100 Subject: [PATCH] add Docker stuff to prepare heroku deployment --- .dockerignore | 3 +++ Apps/Website/Dockerfile | 23 +++++++++++++++++++++++ Apps/Website/Program.cs | 2 ++ Apps/Website/Startup.cs | 2 +- README.md | 6 ++++++ 5 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Apps/Website/Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8b3dd3b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +**/bin +**/obj +**/Dockerfile \ No newline at end of file diff --git a/Apps/Website/Dockerfile b/Apps/Website/Dockerfile new file mode 100644 index 0000000..1a2c383 --- /dev/null +++ b/Apps/Website/Dockerfile @@ -0,0 +1,23 @@ +FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build +WORKDIR /source + +COPY *.sln . +COPY Application/*.csproj ./Application/ +COPY Domain/*.csproj ./Domain/ +COPY Infrastructure/*.csproj ./Infrastructure/ +COPY Apps/Website/*.csproj ./Apps/Website/ +RUN dotnet restore + +COPY Application/. ./Application/ +COPY Domain/. ./Domain/ +COPY Infrastructure/. ./Infrastructure/ +COPY Apps/Website/. ./Apps/Website/ + +WORKDIR /source/Apps/Website +RUN dotnet publish -c release -o /app --no-restore + +FROM mcr.microsoft.com/dotnet/aspnet:5.0 +WORKDIR /app +COPY --from=build /app ./ +EXPOSE 80 +ENTRYPOINT ["dotnet", "Website.dll"] \ No newline at end of file diff --git a/Apps/Website/Program.cs b/Apps/Website/Program.cs index 767bdd9..4ead8f4 100644 --- a/Apps/Website/Program.cs +++ b/Apps/Website/Program.cs @@ -1,3 +1,4 @@ +using System; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Hosting; @@ -14,6 +15,7 @@ namespace Website Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { + webBuilder.UseUrls($"http://0.0.0.0:{Environment.GetEnvironmentVariable("PORT") ?? "5000"}"); webBuilder.UseStartup(); }); } diff --git a/Apps/Website/Startup.cs b/Apps/Website/Startup.cs index fe73284..360a510 100644 --- a/Apps/Website/Startup.cs +++ b/Apps/Website/Startup.cs @@ -78,7 +78,7 @@ namespace Website // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } - app.UseHttpsRedirection(); + // app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); diff --git a/README.md b/README.md index 9e91a79..35f9e11 100644 --- a/README.md +++ b/README.md @@ -166,3 +166,9 @@ project.csproj true bin\YourApi.XML + +## Docker + +On build à la racine de la solution avec `docker build -f .\Apps\Website\Dockerfile -t hn .`. + +Et on lance avec `docker run -it --rm -p "8000:80" hn`.