From 072885528136a2e65cab1da6758eef093749a993 Mon Sep 17 00:00:00 2001 From: Emil Balitzki Date: Sun, 9 Jun 2024 20:37:22 +0200 Subject: [PATCH] Included the new api-gateway inside the docker compose Signed-off-by: Emil Balitzki --- backend/api-gateway/.dockerignore | 25 ++++++++++++++++ .../{api-gateway.csproj => APIGateway.csproj} | 2 +- .../Controllers/APIGatewayController.cs | 6 ++-- backend/api-gateway/Dockerfile | 30 +++++++++++++++++++ backend/api-gateway/Models/GeoJsonResponse.cs | 2 +- backend/api-gateway/api-gateway.http | 6 ---- 6 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 backend/api-gateway/.dockerignore rename backend/api-gateway/{api-gateway.csproj => APIGateway.csproj} (89%) create mode 100644 backend/api-gateway/Dockerfile delete mode 100644 backend/api-gateway/api-gateway.http diff --git a/backend/api-gateway/.dockerignore b/backend/api-gateway/.dockerignore new file mode 100644 index 00000000..3729ff0c --- /dev/null +++ b/backend/api-gateway/.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/backend/api-gateway/api-gateway.csproj b/backend/api-gateway/APIGateway.csproj similarity index 89% rename from backend/api-gateway/api-gateway.csproj rename to backend/api-gateway/APIGateway.csproj index 56432243..7c057d4c 100644 --- a/backend/api-gateway/api-gateway.csproj +++ b/backend/api-gateway/APIGateway.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - api_gateway + APIGateway diff --git a/backend/api-gateway/Controllers/APIGatewayController.cs b/backend/api-gateway/Controllers/APIGatewayController.cs index 110cae6f..3589a994 100644 --- a/backend/api-gateway/Controllers/APIGatewayController.cs +++ b/backend/api-gateway/Controllers/APIGatewayController.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; using Microsoft.Extensions.Logging; using System.Text.Json; -using api_gateway.Models; +using APIGateway.Models; using System.ComponentModel.DataAnnotations; namespace BIE.Core.API.Controllers @@ -49,8 +49,8 @@ public async Task GetDatasetViewportData( } _logger.LogInformation($"Fetching data for DatasetID: {datasetID}, ZoomLevel: {zoomLevel}, Viewport: [{BottomLat}, {BottomLong}] to [{TopLat}, {TopLong}]"); - - var targetUrl = $"http://localhost:8081/api/v1.0/Dataset/1/data?ZoomLevel={zoomLevel}&BottomLat={BottomLat}&BottomLong={BottomLong}&TopLat={TopLat}&TopLong={TopLong}"; + // Here the port 80 is used not 8080. This is due to the docker containers using the interal ports to communicate and not the external ones. + var targetUrl = $"http://api-composer:80/api/v1.0/Dataset/1/data?ZoomLevel={zoomLevel}&BottomLat={BottomLat}&BottomLong={BottomLong}&TopLat={TopLat}&TopLong={TopLong}"; try { diff --git a/backend/api-gateway/Dockerfile b/backend/api-gateway/Dockerfile new file mode 100644 index 00000000..fe275f81 --- /dev/null +++ b/backend/api-gateway/Dockerfile @@ -0,0 +1,30 @@ +# Use the official Microsoft .NET SDK image to build the app +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build + +# Set the working directory inside the container +WORKDIR /app + +# Copy the .csproj file and restore any dependencies +COPY *.csproj ./ +RUN dotnet restore + +# Copy the remaining source code +COPY . ./ + +# Build the application +RUN dotnet publish -c Release -o out + +# Use the official Microsoft .NET runtime image to run the app +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime + +# Set the working directory inside the container +WORKDIR /app + +# Copy the build output from the build stage +COPY --from=build /app/out . + +# Expose the port the application will run on +EXPOSE 8080 + +# Start the application +ENTRYPOINT ["dotnet", "APIGateway.dll"] diff --git a/backend/api-gateway/Models/GeoJsonResponse.cs b/backend/api-gateway/Models/GeoJsonResponse.cs index d1bf6c47..54cde7e1 100644 --- a/backend/api-gateway/Models/GeoJsonResponse.cs +++ b/backend/api-gateway/Models/GeoJsonResponse.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace api_gateway.Models +namespace APIGateway.Models { public class GeoJsonResponse { diff --git a/backend/api-gateway/api-gateway.http b/backend/api-gateway/api-gateway.http deleted file mode 100644 index 1257dc01..00000000 --- a/backend/api-gateway/api-gateway.http +++ /dev/null @@ -1,6 +0,0 @@ -@api_gateway_HostAddress = http://localhost:5028 - -GET {{api_gateway_HostAddress}}/weatherforecast/ -Accept: application/json - -###