diff --git a/ShowcaseProject/ShowcaseAPI/Dockerfile b/ShowcaseProject/ShowcaseAPI/Dockerfile index 06fa820..af07f27 100644 --- a/ShowcaseProject/ShowcaseAPI/Dockerfile +++ b/ShowcaseProject/ShowcaseAPI/Dockerfile @@ -1,18 +1,18 @@ # Base image for running the .NET API -FROM mcr.microsoft.com/dotnet/sdk:9.0 AS base +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base WORKDIR /app EXPOSE 8080 EXPOSE 8081 # Development stage (voor dotnet watch) -FROM mcr.microsoft.com/dotnet/sdk:9.0 AS dev +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS dev WORKDIR /app COPY ./ShowcaseAPI ./ShowcaseAPI WORKDIR /app/ShowcaseAPI CMD ["dotnet", "watch", "run", "--no-launch-profile", "--urls", "http://+:80"] # Build stage (voor productie) -FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /src COPY ["ShowcaseAPI/ShowcaseAPI.csproj", "ShowcaseAPI/"] RUN dotnet restore "ShowcaseAPI/ShowcaseAPI.csproj" @@ -27,7 +27,15 @@ FROM build AS publish RUN dotnet publish "ShowcaseAPI.csproj" -c Release -o /app/publish /p:UseAppHost=false # Final production stage -FROM base AS final +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final WORKDIR /app + +# Kopieer wait script +COPY ShowcaseAPI/wait-for-sql.sh . +RUN chmod +x wait-for-sql.sh + +# Kopieer build output COPY --from=publish /app/publish . -ENTRYPOINT ["dotnet", "ShowcaseAPI.dll"] + +# Start script dat wacht op SQL Server +ENTRYPOINT ["./wait-for-sql.sh"] diff --git a/ShowcaseProject/ShowcaseAPI/Program.cs b/ShowcaseProject/ShowcaseAPI/Program.cs index d8e2e79..e736532 100644 --- a/ShowcaseProject/ShowcaseAPI/Program.cs +++ b/ShowcaseProject/ShowcaseAPI/Program.cs @@ -20,7 +20,7 @@ .AllowCredentials(); }); }); - + Env.Load(); // Add services to the container. diff --git a/ShowcaseProject/ShowcaseAPI/ShowcaseAPI.csproj b/ShowcaseProject/ShowcaseAPI/ShowcaseAPI.csproj index 262f525..035d3a7 100644 --- a/ShowcaseProject/ShowcaseAPI/ShowcaseAPI.csproj +++ b/ShowcaseProject/ShowcaseAPI/ShowcaseAPI.csproj @@ -1,7 +1,7 @@ - + - net9.0 + net8.0 enable enable aspnet-ShowcaseAPI-700326db-d48c-416d-95f7-7cfed2b3e725 @@ -11,9 +11,9 @@ - - - + + + @@ -21,12 +21,11 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - - + diff --git a/ShowcaseProject/ShowcaseAPI/wait-for-sql.sh b/ShowcaseProject/ShowcaseAPI/wait-for-sql.sh new file mode 100644 index 0000000..8d16daa --- /dev/null +++ b/ShowcaseProject/ShowcaseAPI/wait-for-sql.sh @@ -0,0 +1,13 @@ +#!/bin/bash +SQLSERVER_HOST=${SQLSERVER_HOST:-sqlserver} +SQLSERVER_PORT=${SQLSERVER_PORT:-1433} + +echo "Wachten op SQL Server op $SQLSERVER_HOST:$SQLSERVER_PORT..." + +while ! echo > /dev/tcp/$SQLSERVER_HOST/$SQLSERVER_PORT 2>/dev/null; do + echo "SQL Server nog niet bereikbaar..." + sleep 2 +done + +echo "SQL Server is beschikbaar, start API" +exec dotnet ShowcaseAPI.dll diff --git a/ShowcaseProject/ShowcaseApiTesting/Dockerfile b/ShowcaseProject/ShowcaseApiTesting/Dockerfile new file mode 100644 index 0000000..68eab41 --- /dev/null +++ b/ShowcaseProject/ShowcaseApiTesting/Dockerfile @@ -0,0 +1,13 @@ +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +WORKDIR /src + +COPY ["ShowcaseApiTesting/ShowcaseApiTesting.csproj", "ShowcaseApiTesting/"] +COPY ["ShowcaseAPI/ShowcaseAPI.csproj", "ShowcaseAPI/"] +RUN dotnet restore "ShowcaseApiTesting/ShowcaseApiTesting.csproj" + +COPY . . +WORKDIR "/src/ShowcaseApiTesting" + +RUN dotnet build "ShowcaseApiTesting.csproj" -c Release --no-restore + +CMD ["dotnet", "test", "ShowcaseApiTesting.csproj", "-c", "Release", "--logger:trx;LogFileName=test_results.trx", "--results-directory", "./TestResults", "--verbosity", "normal"] diff --git a/ShowcaseProject/ShowcaseApiTesting/GameHubTests.cs b/ShowcaseProject/ShowcaseApiTesting/GameHubTests.cs index d69d149..85602a0 100644 --- a/ShowcaseProject/ShowcaseApiTesting/GameHubTests.cs +++ b/ShowcaseProject/ShowcaseApiTesting/GameHubTests.cs @@ -1,11 +1,9 @@ namespace ShowcaseApiTesting { - using Xunit; using Moq; using ShowcaseAPI.Hubs; using Microsoft.AspNetCore.SignalR; using System.Threading.Tasks; - using System.Collections.Generic; [TestFixture] public class GameHubTests @@ -29,7 +27,7 @@ public async Task CreateGroup() _mockClients.Setup(clients => clients.Caller).Returns(_mockClientProxy.Object); - var groupName = "123456"; + var groupName = "123456"; var connectionId = "test-connection"; _mockContext.Setup(c => c.ConnectionId).Returns(connectionId); diff --git a/ShowcaseProject/ShowcaseApiTesting/Properties/launchSettings.json b/ShowcaseProject/ShowcaseApiTesting/Properties/launchSettings.json new file mode 100644 index 0000000..3632511 --- /dev/null +++ b/ShowcaseProject/ShowcaseApiTesting/Properties/launchSettings.json @@ -0,0 +1,10 @@ +{ + "profiles": { + "ShowcaseApiTesting": { + "commandName": "Project" + }, + "Container (Dockerfile)": { + "commandName": "Docker" + } + } +} \ No newline at end of file diff --git a/ShowcaseProject/ShowcaseApiTesting/ShowcaseApiTesting.csproj b/ShowcaseProject/ShowcaseApiTesting/ShowcaseApiTesting.csproj index 1c0175e..db65c60 100644 --- a/ShowcaseProject/ShowcaseApiTesting/ShowcaseApiTesting.csproj +++ b/ShowcaseProject/ShowcaseApiTesting/ShowcaseApiTesting.csproj @@ -1,22 +1,23 @@  - net9.0 + net8.0 latest enable enable false + Linux + - diff --git a/ShowcaseProject/ShowcaseFrontend/Program.cs b/ShowcaseProject/ShowcaseFrontend/Program.cs index b38ced3..8d5e77a 100644 --- a/ShowcaseProject/ShowcaseFrontend/Program.cs +++ b/ShowcaseProject/ShowcaseFrontend/Program.cs @@ -7,7 +7,7 @@ builder.Services.AddHttpClient("NoSSL", client => { - client.BaseAddress = new Uri("http://showcaseapi"); + client.BaseAddress = new Uri("http://showcaseapi" ); }) .ConfigurePrimaryHttpMessageHandler(() => { diff --git a/ShowcaseProject/docker-compose.yml b/ShowcaseProject/docker-compose.yml index 07d290b..b5c8436 100644 --- a/ShowcaseProject/docker-compose.yml +++ b/ShowcaseProject/docker-compose.yml @@ -12,6 +12,23 @@ services: volumes: - sql_data:/var/opt/mssql + showcasefrontend: + build: + context: . + dockerfile: ShowcaseFrontend/Dockerfile + target: dev + container_name: showcasefrontend + ports: + - "8080:80" + depends_on: + - showcaseapi + environment: + - API_BASE_URL=http://showcaseapi + volumes: + - ./ShowcaseFrontend:/app/ShowcaseFrontend + - ~/.nuget/packages:/root/.nuget/packages:ro + command: ["dotnet", "watch", "run", "--project", "/app/ShowcaseFrontend/ShowcaseFrontend.csproj", "--no-launch-profile", "--urls=http://0.0.0.0:80"] + showcaseapi: build: context: . @@ -23,23 +40,19 @@ services: - sqlserver env_file: - .env + environment: + - SQLSERVER_HOST=sqlserver + - SQLSERVER_PORT=1433 - showcasefrontend: + showcaseapitesting: build: context: . - dockerfile: ShowcaseFrontend/Dockerfile - target: dev - container_name: showcasefrontend - ports: - - "8080:80" + dockerfile: ShowcaseApiTesting/Dockerfile + container_name: showcaseapitesting depends_on: - showcaseapi - environment: - - API_BASE_URL=http://showcaseapi volumes: - - ./ShowcaseFrontend:/app/ShowcaseFrontend - - ~/.nuget/packages:/root/.nuget/packages:ro - command: ["dotnet", "watch", "run", "--project", "/app/ShowcaseFrontend/ShowcaseFrontend.csproj", "--no-launch-profile", "--urls=http://0.0.0.0:80"] + - ./ShowcaseApiTesting/TestResults:/src/ShowcaseApiTesting/TestResults volumes: - sql_data: \ No newline at end of file + sql_data: