From 1b65998d19b69f5d127c61fb4ad902c0dfe686d1 Mon Sep 17 00:00:00 2001 From: Clement FERRERE Date: Wed, 23 Feb 2022 15:39:04 +0100 Subject: [PATCH] =?UTF-8?q?Premi=C3=A8re=20tentative=20de=20dockerisation,?= =?UTF-8?q?=20docker=20compose=20ne=20fonctionne=20pas=20mais=20le=20conte?= =?UTF-8?q?neur=20de=20l'api=20se=20lance=20de=20mani=C3=A8re=20correcteme?= =?UTF-8?q?nt=20ind=C3=A9pendante?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Collaborateur_Epa_Back/.dockerignore | 25 ++++++++++++ Collaborateur_Epa_Back/.env | 6 +++ Collaborateur_Epa_Back/docker-compose.dcproj | 20 ++++++++++ .../docker-compose.override.yml | 14 +++++++ Collaborateur_Epa_Back/docker-compose.yml | 38 +++++++++++++++++++ .../espacecollab.backend.api/Dockerfile | 29 ++++++++++++++ .../Properties/launchSettings.json | 17 ++++++--- .../espacecollab.backend.api/appsettings.json | 2 +- .../espacecollab.backend.api.csproj | 4 ++ .../espacecollab.backend.sln | 8 +++- 10 files changed, 156 insertions(+), 7 deletions(-) create mode 100644 Collaborateur_Epa_Back/.dockerignore create mode 100644 Collaborateur_Epa_Back/.env create mode 100644 Collaborateur_Epa_Back/docker-compose.dcproj create mode 100644 Collaborateur_Epa_Back/docker-compose.override.yml create mode 100644 Collaborateur_Epa_Back/docker-compose.yml create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.api/Dockerfile diff --git a/Collaborateur_Epa_Back/.dockerignore b/Collaborateur_Epa_Back/.dockerignore new file mode 100644 index 0000000..3729ff0 --- /dev/null +++ b/Collaborateur_Epa_Back/.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/Collaborateur_Epa_Back/.env b/Collaborateur_Epa_Back/.env new file mode 100644 index 0000000..91933b3 --- /dev/null +++ b/Collaborateur_Epa_Back/.env @@ -0,0 +1,6 @@ +DATABASE_HOSTNAME=localhost +DATABASE_PORT=3306 +DATABASE_NAME=collaborateur_epa +APP_DB_USERNAME=root +APP_DB_PASSWORD=root +APP_DB_ROOT_PASSWORD=root diff --git a/Collaborateur_Epa_Back/docker-compose.dcproj b/Collaborateur_Epa_Back/docker-compose.dcproj new file mode 100644 index 0000000..0bf187e --- /dev/null +++ b/Collaborateur_Epa_Back/docker-compose.dcproj @@ -0,0 +1,20 @@ + + + + 2.1 + Linux + 815b6abd-7550-4d79-a53b-e84f4d4a7475 + LaunchBrowser + {Scheme}://localhost:{ServicePort}/swagger + espacecollab.backend.api + + + + + docker-compose.yml + + + + + + \ No newline at end of file diff --git a/Collaborateur_Epa_Back/docker-compose.override.yml b/Collaborateur_Epa_Back/docker-compose.override.yml new file mode 100644 index 0000000..f554f84 --- /dev/null +++ b/Collaborateur_Epa_Back/docker-compose.override.yml @@ -0,0 +1,14 @@ +version: '3.4' + +services: + espacecollab.backend.api: + environment: + - ASPNETCORE_ENVIRONMENT=Development + - ASPNETCORE_URLS=https://+:443;http://+:80 + - ASPNETCORE_Kestrel__Certificates__Default__Password=password + - ASPNETCORE_Kestrel__Certificates__Default__Path=${APPDATA}/ASP.NET/Https/espacecollab.pfx + ports: + - "8001:80" + - "8000:443" + volumes: + - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro \ No newline at end of file diff --git a/Collaborateur_Epa_Back/docker-compose.yml b/Collaborateur_Epa_Back/docker-compose.yml new file mode 100644 index 0000000..24d1bea --- /dev/null +++ b/Collaborateur_Epa_Back/docker-compose.yml @@ -0,0 +1,38 @@ +version: '3.4' + +volumes: + data-volume: {} + +services: + + maria_db: + image: "mariadb:10.7.1" + restart: always + ports: + - 3304:3306 + environment: + - MYSQL_DATABASE=${DATABASE_NAME} + - MYSQL_USERNAME=${APP_DB_USERNAME} + - MYSQL_PASSWORD=${APP_DB_PASSWORD} + - MYSQL_ROOT_PASSWORD=${APP_DB_ROOT_PASSWORD} + volumes: + - data-volume:/var/lib/mysql + + espacecollab.backend.api: + image: ${DOCKER_REGISTRY-}espacecollabbackendapi + build: + context: . + dockerfile: espacecollab.backend.api/Dockerfile + ports: + - "5000:80" + - "5001:443" + links: + - maria_db + environment: + - DATABASE_HOSTNAME=maria_db + - DATABASE_PORT=3306 + - DATABASE_NAME=${DATABASE_NAME} + - DATABASE_USERNAME=${APP_DB_USERNAME} + - DATABASE_PASSWORD=${APP_DB_PASSWORD} + + diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Dockerfile b/Collaborateur_Epa_Back/espacecollab.backend.api/Dockerfile new file mode 100644 index 0000000..9d074f5 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Dockerfile @@ -0,0 +1,29 @@ +#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. + +FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base +WORKDIR /app +EXPOSE 80 +EXPOSE 443 + +FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build +WORKDIR /src +COPY ["espacecollab.backend.api/espacecollab.backend.api.csproj", "espacecollab.backend.api/"] +COPY ["espacecollab.backend.appservices/espacecollab.backend.appservices.csproj", "espacecollab.backend.appservices/"] +COPY ["espacecollab.backend.appservices.dtos/espacecollab.backend.appservices.dtos.csproj", "espacecollab.backend.appservices.dtos/"] +COPY ["espacecollab.backend.infrastructure.sql.dtos/espacecollab.backend.infrastructure.sql.dtos.csproj", "espacecollab.backend.infrastructure.sql.dtos/"] +COPY ["espacecollab.backend.appservices.interfaces/espacecollab.backend.appservices.interfaces.csproj", "espacecollab.backend.appservices.interfaces/"] +COPY ["espacecollab.backend.infrastructure.sql/espacecollab.backend.infrastructure.sql.csproj", "espacecollab.backend.infrastructure.sql/"] +COPY ["espacecollab.backend.infrastructure.interfaces/espacecollab.backend.infrastructure.interfaces.csproj", "espacecollab.backend.infrastructure.interfaces/"] +COPY ["espacecollab.backend.infrastructure.fake/espacecollab.backend.infrastructure.fake.csproj", "espacecollab.backend.infrastructure.fake/"] +RUN dotnet restore "espacecollab.backend.api/espacecollab.backend.api.csproj" +COPY . . +WORKDIR "/src/espacecollab.backend.api" +RUN dotnet build "espacecollab.backend.api.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "espacecollab.backend.api.csproj" -c Release -o /app/publish + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "espacecollab.backend.api.dll"] \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Properties/launchSettings.json b/Collaborateur_Epa_Back/espacecollab.backend.api/Properties/launchSettings.json index 631c563..8505599 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Properties/launchSettings.json +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Properties/launchSettings.json @@ -1,4 +1,4 @@ -{ +{ "$schema": "https://json.schemastore.org/launchsettings.json", "iisSettings": { "windowsAuthentication": false, @@ -11,13 +11,13 @@ "profiles": { "espacecollab.backend.api": { "commandName": "Project", - "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "swagger", - "applicationUrl": "https://localhost:7125;http://localhost:5125", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - } + }, + "applicationUrl": "https://localhost:8081;http://localhost:8080", + "dotnetRunMessages": true }, "IIS Express": { "commandName": "IISExpress", @@ -26,6 +26,13 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } + }, + "Docker": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", + "publishAllPorts": true, + "useSSL": true } } -} +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json b/Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json index bc26e00..c7c63da 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json @@ -7,7 +7,7 @@ }, "AllowedHosts": "*", "Sql": { - "LoadFake": false, + "LoadFake": true, "ConnectionString": "server=localhost;user=root;password=root;database=collaborateur_epa" } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/espacecollab.backend.api.csproj b/Collaborateur_Epa_Back/espacecollab.backend.api/espacecollab.backend.api.csproj index 0c9099a..c417134 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/espacecollab.backend.api.csproj +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/espacecollab.backend.api.csproj @@ -4,10 +4,14 @@ net6.0 enable enable + 5a7cf5e2-2bf7-4dae-aea9-2522da3cf955 + Linux + ..\docker-compose.dcproj + diff --git a/Collaborateur_Epa_Back/espacecollab.backend.sln b/Collaborateur_Epa_Back/espacecollab.backend.sln index cfbc75f..8230b4d 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.sln +++ b/Collaborateur_Epa_Back/espacecollab.backend.sln @@ -25,7 +25,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "espacecollab.backend.infras EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "espacecollab.backend.appservices.interfaces", "espacecollab.backend.appservices.interfaces\espacecollab.backend.appservices.interfaces.csproj", "{7872657E-46E2-44A1-AFA6-0D3B9E45084A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "espacecollab.backend.api.tests", "espacecollab.backend.api.tests\espacecollab.backend.api.tests.csproj", "{5EA7CAB6-B7A8-4A54-8A1D-774A376974CB}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "espacecollab.backend.api.tests", "espacecollab.backend.api.tests\espacecollab.backend.api.tests.csproj", "{5EA7CAB6-B7A8-4A54-8A1D-774A376974CB}" +EndProject +Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{815B6ABD-7550-4D79-A53B-E84F4D4A7475}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -69,6 +71,10 @@ Global {5EA7CAB6-B7A8-4A54-8A1D-774A376974CB}.Debug|Any CPU.Build.0 = Debug|Any CPU {5EA7CAB6-B7A8-4A54-8A1D-774A376974CB}.Release|Any CPU.ActiveCfg = Release|Any CPU {5EA7CAB6-B7A8-4A54-8A1D-774A376974CB}.Release|Any CPU.Build.0 = Release|Any CPU + {815B6ABD-7550-4D79-A53B-E84F4D4A7475}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {815B6ABD-7550-4D79-A53B-E84F4D4A7475}.Debug|Any CPU.Build.0 = Debug|Any CPU + {815B6ABD-7550-4D79-A53B-E84F4D4A7475}.Release|Any CPU.ActiveCfg = Release|Any CPU + {815B6ABD-7550-4D79-A53B-E84F4D4A7475}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE