From 4ebbb4dee1ebb15cf2cfa1be8541fc477993a183 Mon Sep 17 00:00:00 2001 From: Fredi Machado Date: Wed, 15 May 2024 19:18:43 +1000 Subject: [PATCH] Fix local deployment with docker compose --- .env-local | 6 ++++-- .gitignore | 2 ++ Build.ps1 | 19 +++++++++++++++++++ NCafe.sln | 4 +++- build.sh | 19 +++++++++++++++++++ global.json | 5 +++++ infrastructure-compose.yaml | 2 -- services-compose.yaml | 25 +++++++++++++++++-------- src/UI/NCafe.Web/prepare-appsettings.sh | 4 ++-- 9 files changed, 71 insertions(+), 15 deletions(-) create mode 100644 Build.ps1 create mode 100644 build.sh create mode 100644 global.json diff --git a/.env-local b/.env-local index 7a6956b..4bfd337 100644 --- a/.env-local +++ b/.env-local @@ -1,4 +1,6 @@ ASPNETCORE_ENVIRONMENT=Development -ASPNETCORE_Kestrel__Certificates__Default__Password=ncafe -ASPNETCORE_Kestrel__Certificates__Default__Path=/https/ncafe-aspnetapp.pfx CONNECTIONSTRINGS__EVENTSTORE=esdb://eventstore:2113?tls=false +CONNECTIONSTRINGS__RABBITMQ=host=rabbitmq;username=myuser;password=mypassword +ADMIN_BASE_ADDRESS=http://localhost:5010 +CASHIER_BASE_ADDRESS=http://localhost:5020 +BARISTA_BASE_ADDRESS=http://localhost:5030 diff --git a/.gitignore b/.gitignore index 8afdcb6..d42523a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ ## ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore +output/ + # User-specific files *.rsuser *.suo diff --git a/Build.ps1 b/Build.ps1 new file mode 100644 index 0000000..e3b8235 --- /dev/null +++ b/Build.ps1 @@ -0,0 +1,19 @@ +$projectPaths = @( + '.\src\Admin\NCafe.Admin.Api' + '.\src\Barista\NCafe.Barista.Api' + '.\src\Cashier\NCafe.Cashier.Api' + '.\src\UI\NCafe.Web' +) + +Write-Host "Restoring packages for all projects..." +dotnet restore + +foreach ($projectPath in $projectPaths) { + Write-Host "Building project $($projectPath)..." + dotnet build -c Release --no-restore $projectPath +} + +foreach ($projectPath in $projectPaths) { + Write-Host "Publishing project $($projectPath)..." + dotnet publish -c Release --no-restore -o "$($projectPath)\output" $projectPath +} diff --git a/NCafe.sln b/NCafe.sln index c8e87ea..d93e5de 100644 --- a/NCafe.sln +++ b/NCafe.sln @@ -35,6 +35,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig .env-local = .env-local + Build.ps1 = Build.ps1 + build.sh = build.sh Directory.Build.props = Directory.Build.props Directory.Packages.props = Directory.Packages.props infrastructure-compose.yaml = infrastructure-compose.yaml @@ -73,7 +75,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NCafe.Shared", "src\Common\ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{49528FFA-842E-4853-9B8F-77BCE9970D11}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NCafe.Common.Tests", "src\Common\NCafe.Common.Tests\NCafe.Common.Tests.csproj", "{0203B146-09CB-4350-8375-9759F132BDC2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NCafe.Common.Tests", "src\Common\NCafe.Common.Tests\NCafe.Common.Tests.csproj", "{0203B146-09CB-4350-8375-9759F132BDC2}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..b4348cd --- /dev/null +++ b/build.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -e + +projectPaths=("src/Admin/NCafe.Admin.Api" "src/Barista/NCafe.Barista.Api" "src/Cashier/NCafe.Cashier.Api" "src/UI/NCafe.Web") + +echo "Restoring packages for all projects..." +dotnet restore + +for projectPath in "${projectPaths[@]}" +do + echo "Building project $projectPath..." + dotnet build -c Release --no-restore $projectPath +done + +for projectPath in "${projectPaths[@]}" +do + echo "Publishing project $projectPath..." + dotnet publish -c Release --no-restore -o "$projectPath/output" $projectPath +done diff --git a/global.json b/global.json new file mode 100644 index 0000000..7fa817c --- /dev/null +++ b/global.json @@ -0,0 +1,5 @@ +{ + "sdk": { + "version": "8.0.300" + } +} \ No newline at end of file diff --git a/infrastructure-compose.yaml b/infrastructure-compose.yaml index c0d113e..5ee853c 100644 --- a/infrastructure-compose.yaml +++ b/infrastructure-compose.yaml @@ -1,5 +1,3 @@ -version: '3.4' - services: eventstore: image: eventstore/eventstore:20.10.0-buster-slim diff --git a/services-compose.yaml b/services-compose.yaml index d888aa8..edec660 100644 --- a/services-compose.yaml +++ b/services-compose.yaml @@ -1,36 +1,45 @@ -version: '3.4' - services: admin: build: - dockerfile: src/Admin/NCafe.Admin.Api/Dockerfile + context: src/Admin/NCafe.Admin.Api/ container_name: ncafe-admin restart: unless-stopped env_file: .env-local ports: - - 5010:80 + - 5010:8080 networks: - ncafe cashier: build: - dockerfile: src/Cashier/NCafe.Cashier.Api/Dockerfile + context: src/Cashier/NCafe.Cashier.Api/ container_name: ncafe-cashier restart: unless-stopped env_file: .env-local ports: - - 5020:80 + - 5020:8080 networks: - ncafe barista: build: - dockerfile: src/Barista/NCafe.Barista.Api/Dockerfile + context: src/Barista/NCafe.Barista.Api/ container_name: ncafe-barista restart: unless-stopped env_file: .env-local ports: - - 5030:80 + - 5030:8080 + networks: + - ncafe + + web-ui: + build: + context: src/UI/NCafe.Web/ + container_name: ncafe-ui + restart: unless-stopped + env_file: .env-local + ports: + - 5000:80 networks: - ncafe diff --git a/src/UI/NCafe.Web/prepare-appsettings.sh b/src/UI/NCafe.Web/prepare-appsettings.sh index 2d3aa5e..6714735 100644 --- a/src/UI/NCafe.Web/prepare-appsettings.sh +++ b/src/UI/NCafe.Web/prepare-appsettings.sh @@ -5,8 +5,8 @@ set -e APPSETTINGS=/user/share/nginx/html/appsettings.json # delete compressed (brotli/gzip) appsettings files -rm "$APPSETTINGS.br" -rm "$APPSETTINGS.gz" +rm -rf "$APPSETTINGS.br" +rm -rf "$APPSETTINGS.gz" # update base address value using environment variables sed -i -E "s|(\"AdminBaseAddress\"\:) \"(.*)\"(,)?|\1 \"$ADMIN_BASE_ADDRESS\"\3|g" $APPSETTINGS