From 4ba7ac8948dbcc5a3c7d5c1215ff99a8a841c04f Mon Sep 17 00:00:00 2001 From: Filippo Passeggieri Date: Wed, 30 Aug 2023 17:37:12 +0200 Subject: [PATCH] Docker Support --- .dockerignore | 25 +++++++++++++++++++++++ Dockerfile | 21 +++++++++++++++++++ Properties/launchSettings.json | 37 +++++++++++++++++++++------------- my-weather-api.csproj | 3 +++ my-weather-api.sln | 25 +++++++++++++++++++++++ 5 files changed, 97 insertions(+), 14 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 my-weather-api.sln diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3729ff0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,25 @@ +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d660cf1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. + +FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base +WORKDIR /app +EXPOSE 80 + +FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build +WORKDIR /src +COPY ["my-weather-api.csproj", "."] +RUN dotnet restore "./my-weather-api.csproj" +COPY . . +WORKDIR "/src/." +RUN dotnet build "my-weather-api.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "my-weather-api.csproj" -c Release -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "my-weather-api.dll"] \ No newline at end of file diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json index 2b9e17d..c5bb6b9 100644 --- a/Properties/launchSettings.json +++ b/Properties/launchSettings.json @@ -1,23 +1,14 @@ -{ - "$schema": "https://json.schemastore.org/launchsettings.json", - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:4809", - "sslPort": 0 - } - }, +{ "profiles": { "http": { "commandName": "Project", - "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "swagger", - "applicationUrl": "http://localhost:5017", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - } + }, + "dotnetRunMessages": true, + "applicationUrl": "http://localhost:5017" }, "IIS Express": { "commandName": "IISExpress", @@ -26,6 +17,24 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } + }, + "Docker": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", + "environmentVariables": { + "ASPNETCORE_URLS": "http://+:80" + }, + "publishAllPorts": true + } + }, + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:4809", + "sslPort": 0 } } -} +} \ No newline at end of file diff --git a/my-weather-api.csproj b/my-weather-api.csproj index ae74865..6158de7 100644 --- a/my-weather-api.csproj +++ b/my-weather-api.csproj @@ -5,10 +5,13 @@ enable enable my_weather_api + Linux + . + diff --git a/my-weather-api.sln b/my-weather-api.sln new file mode 100644 index 0000000..befac86 --- /dev/null +++ b/my-weather-api.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34018.315 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "my-weather-api", "my-weather-api.csproj", "{B05ABBAD-4EEC-453E-A3CB-CF5BEF6DBEEE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B05ABBAD-4EEC-453E-A3CB-CF5BEF6DBEEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B05ABBAD-4EEC-453E-A3CB-CF5BEF6DBEEE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B05ABBAD-4EEC-453E-A3CB-CF5BEF6DBEEE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B05ABBAD-4EEC-453E-A3CB-CF5BEF6DBEEE}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {99664F82-6C35-4D02-9D75-55C140CE08BC} + EndGlobalSection +EndGlobal