From b9acfacab137e15b089b6727aa57e76fd42190f3 Mon Sep 17 00:00:00 2001 From: Alex Vorobiev Date: Tue, 16 Jun 2020 10:50:46 +0200 Subject: [PATCH] Bad async multipart fix; fixes #112 (#136) * Container waits for msbuild to finish now * Async stream copying is awaited now, removing possibility of incomplete file streams on Linux * Simple nginx compose configuration for testing * Working port changed to 8088 --- CDP4WebServices.API/Modules/10-25/ApiBase.cs | 7 ++- compose.bat | 14 ++++- docker-compose-nginx.yml | 65 ++++++++++++++++++++ nginx/nginx.conf | 15 +++++ 4 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 docker-compose-nginx.yml create mode 100644 nginx/nginx.conf diff --git a/CDP4WebServices.API/Modules/10-25/ApiBase.cs b/CDP4WebServices.API/Modules/10-25/ApiBase.cs index cfd6a7d7..b605d3ff 100644 --- a/CDP4WebServices.API/Modules/10-25/ApiBase.cs +++ b/CDP4WebServices.API/Modules/10-25/ApiBase.cs @@ -33,6 +33,7 @@ namespace CDP4WebServices.API.Modules using System.Net.Http; using System.Security.Cryptography; using System.Text; + using System.Threading.Tasks; using CDP4Common.DTO; @@ -832,7 +833,7 @@ private void PrepareMultiPartResponse( } // stream the multipart content to the request contents target stream - content.CopyToAsync(targetStream); + content.CopyToAsync(targetStream).Wait(); this.AddMultiPartMimeEndpoint(targetStream); } @@ -906,7 +907,7 @@ private void PrepareArchivedResponse( content.Add(binaryContent); // stream the multipart content to the request contents target stream - content.CopyToAsync(targetStream); + content.CopyToAsync(targetStream).Wait(); this.AddMultiPartMimeEndpoint(targetStream); } @@ -949,7 +950,7 @@ private void CreateFileResponseStream(Stream targetStream, string path) var content = new ByteArrayContent(buffer); // stream the multipart content to the request contents target stream - content.CopyToAsync(targetStream); + content.CopyToAsync(targetStream).Wait(); } System.IO.File.Delete(path); diff --git a/compose.bat b/compose.bat index 38b76815..184ca65c 100644 --- a/compose.bat +++ b/compose.bat @@ -19,12 +19,24 @@ IF %1==devtest GOTO DevTest IF %1==devtestbg GOTO DevTestBg IF %1==devdown GOTO DevDown IF %1==devtestdown GOTO DevTestDown +IF %1==nginx GOTO Serv +IF %1==nginxdown GOTO ServDown GOTO End +:Serv +rem Need to build the application in Release before making the image +CALL MSBuild.exe CDP4-Server.sln -property:Configuration=Release -restore +START /B docker-compose -f docker-compose-nginx.yml up --build +GOTO End + +:ServDown +START /B docker-compose -f docker-compose-nginx.yml down --remove-orphans +GOTO End + :Build rem Need to build the application in Release before making the image -START /B MSBuild.exe CDP4-Server.sln -property:Configuration=Release -restore +CALL MSBuild.exe CDP4-Server.sln -property:Configuration=Release -restore START /B docker-compose up --build GOTO End diff --git a/docker-compose-nginx.yml b/docker-compose-nginx.yml new file mode 100644 index 00000000..561f3dfe --- /dev/null +++ b/docker-compose-nginx.yml @@ -0,0 +1,65 @@ +version: '3.8' +services: + + cdp4_db: + image: rheagroup/cdp4-database-community-edition:latest + hostname: cdp4-postgresql + command: postgres -c max_locks_per_transaction=1024 + environment: + - POSTGRES_PASSWORD=${DB_POSTGRESPASSWORD} + - POSTGRES_USER=postgres + networks: + cdp4: + aliases: + - cdp4-postgresql + container_name: cdp4-database-community-edition + restart: always + ports: + - '${DB_HOSTPORT}:5432' + expose: + - '5432' + volumes: + - cdpdbdata:/var/lib/postgresql/data + - cdpdblogs:/logs + + cdp4_webservices: + hostname: cdp4-webservices + restart: always + build: . + networks: + cdp4: + aliases: + - cdp4-webservices + depends_on: + - cdp4_db + expose: + - '5000' + volumes: + - cdpwslogs:/app/logs + - cdpwsstorage:/app/storage + - cdpwsupload:/app/upload + + nginx: + image: nginx:latest + container_name: cdp4-nginx + restart: always + depends_on: + - cdp4_webservices + volumes: + - ./nginx/nginx.conf:/etc/nginx/nginx.conf + ports: + - 8088:80 + networks: + cdp4: + aliases: + - cdp4-nginx + +networks: + cdp4: + +volumes: + cdpdbdata: + cdpdblogs: + cdpwslogs: + cdpwsstorage: + cdpwsupload: \ No newline at end of file diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 00000000..b2e00fd1 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,15 @@ +events { + +} + +http { + error_log /etc/nginx/error_log.log warn; + + server { + listen 80; + + location / { + proxy_pass http://cdp4-webservices:5000; + } + } +} \ No newline at end of file