Skip to content

Commit 202ba93

Browse files
committed
Added script to showcase api to wait for sql server by building.
1 parent b31795f commit 202ba93

File tree

8 files changed

+83
-28
lines changed

8 files changed

+83
-28
lines changed

ShowcaseProject/ShowcaseAPI/Dockerfile

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# Base image for running the .NET API
2-
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS base
2+
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
33
WORKDIR /app
44
EXPOSE 8080
55
EXPOSE 8081
66

77
# Development stage (voor dotnet watch)
8-
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS dev
8+
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS dev
99
WORKDIR /app
1010
COPY ./ShowcaseAPI ./ShowcaseAPI
1111
WORKDIR /app/ShowcaseAPI
1212
CMD ["dotnet", "watch", "run", "--no-launch-profile", "--urls", "http://+:80"]
1313

1414
# Build stage (voor productie)
15-
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
15+
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
1616
WORKDIR /src
1717
COPY ["ShowcaseAPI/ShowcaseAPI.csproj", "ShowcaseAPI/"]
1818
RUN dotnet restore "ShowcaseAPI/ShowcaseAPI.csproj"
@@ -27,7 +27,15 @@ FROM build AS publish
2727
RUN dotnet publish "ShowcaseAPI.csproj" -c Release -o /app/publish /p:UseAppHost=false
2828

2929
# Final production stage
30-
FROM base AS final
30+
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
3131
WORKDIR /app
32+
33+
# Kopieer wait script
34+
COPY ShowcaseAPI/wait-for-sql.sh .
35+
RUN chmod +x wait-for-sql.sh
36+
37+
# Kopieer build output
3238
COPY --from=publish /app/publish .
33-
ENTRYPOINT ["dotnet", "ShowcaseAPI.dll"]
39+
40+
# Start script dat wacht op SQL Server
41+
ENTRYPOINT ["./wait-for-sql.sh"]
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<UserSecretsId>aspnet-ShowcaseAPI-700326db-d48c-416d-95f7-7cfed2b3e725</UserSecretsId>
@@ -11,22 +11,21 @@
1111
<ItemGroup>
1212
<PackageReference Include="DotNetEnv" Version="3.1.1" />
1313
<PackageReference Include="JWT" Version="11.0.0" />
14-
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.1" NoWarn="NU1605" />
15-
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="9.0.1" NoWarn="NU1605" />
16-
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="9.0.1" />
14+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.15" />
15+
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.15" />
16+
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.15" />
1717
<PackageReference Include="Microsoft.AspNetCore.SignalR.Core" Version="1.2.0" />
1818
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.1" />
1919
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.1">
2020
<PrivateAssets>all</PrivateAssets>
2121
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2222
</PackageReference>
2323
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.1" />
24-
<PackageReference Include="Microsoft.Identity.Web" Version="3.6.2" />
25-
<PackageReference Include="Microsoft.Identity.Web.DownstreamApi" Version="3.6.2" />
2624
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
2725
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
2826
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
2927
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.6.0" />
28+
3029
</ItemGroup>
3130

3231
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
SQLSERVER_HOST=${SQLSERVER_HOST:-sqlserver}
3+
SQLSERVER_PORT=${SQLSERVER_PORT:-1433}
4+
5+
echo "Wachten op SQL Server op $SQLSERVER_HOST:$SQLSERVER_PORT..."
6+
7+
while ! echo > /dev/tcp/$SQLSERVER_HOST/$SQLSERVER_PORT 2>/dev/null; do
8+
echo "SQL Server nog niet bereikbaar..."
9+
sleep 2
10+
done
11+
12+
echo "SQL Server is beschikbaar, start API"
13+
exec dotnet ShowcaseAPI.dll
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
2+
WORKDIR /src
3+
4+
COPY ["ShowcaseApiTesting/ShowcaseApiTesting.csproj", "ShowcaseApiTesting/"]
5+
COPY ["ShowcaseAPI/ShowcaseAPI.csproj", "ShowcaseAPI/"]
6+
RUN dotnet restore "ShowcaseApiTesting/ShowcaseApiTesting.csproj"
7+
8+
COPY . .
9+
WORKDIR "/src/ShowcaseApiTesting"
10+
11+
RUN dotnet build "ShowcaseApiTesting.csproj" -c Release --no-restore
12+
13+
CMD ["dotnet", "test", "ShowcaseApiTesting.csproj", "-c", "Release", "--logger:trx;LogFileName=test_results.trx", "--results-directory", "./TestResults", "--verbosity", "normal"]

ShowcaseProject/ShowcaseApiTesting/GameHubTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
namespace ShowcaseApiTesting
22
{
3-
using Xunit;
43
using Moq;
54
using ShowcaseAPI.Hubs;
65
using Microsoft.AspNetCore.SignalR;
76
using System.Threading.Tasks;
8-
using System.Collections.Generic;
97

108
[TestFixture]
119
public class GameHubTests
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"profiles": {
3+
"ShowcaseApiTesting": {
4+
"commandName": "Project"
5+
},
6+
"Container (Dockerfile)": {
7+
"commandName": "Docker"
8+
}
9+
}
10+
}

ShowcaseProject/ShowcaseApiTesting/ShowcaseApiTesting.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<LangVersion>latest</LangVersion>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<IsPackable>false</IsPackable>
9+
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
910
</PropertyGroup>
1011

1112
<ItemGroup>
1213
<PackageReference Include="coverlet.collector" Version="6.0.2" />
1314
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.2.0" />
1415
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
16+
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
1517
<PackageReference Include="Moq" Version="4.20.72" />
1618
<PackageReference Include="NUnit" Version="4.2.2" />
1719
<PackageReference Include="NUnit.Analyzers" Version="4.3.0" />
1820
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
19-
<PackageReference Include="xunit" Version="2.9.3" />
2021
</ItemGroup>
2122

2223
<ItemGroup>

ShowcaseProject/docker-compose.yml

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@ services:
1212
volumes:
1313
- sql_data:/var/opt/mssql
1414

15+
showcasefrontend:
16+
build:
17+
context: .
18+
dockerfile: ShowcaseFrontend/Dockerfile
19+
target: dev
20+
container_name: showcasefrontend
21+
ports:
22+
- "8080:80"
23+
depends_on:
24+
- showcaseapi
25+
environment:
26+
- API_BASE_URL=http://showcaseapi
27+
volumes:
28+
- ./ShowcaseFrontend:/app/ShowcaseFrontend
29+
- ~/.nuget/packages:/root/.nuget/packages:ro
30+
command: ["dotnet", "watch", "run", "--project", "/app/ShowcaseFrontend/ShowcaseFrontend.csproj", "--no-launch-profile", "--urls=http://0.0.0.0:80"]
31+
1532
showcaseapi:
1633
build:
1734
context: .
@@ -23,23 +40,19 @@ services:
2340
- sqlserver
2441
env_file:
2542
- .env
43+
environment:
44+
- SQLSERVER_HOST=sqlserver
45+
- SQLSERVER_PORT=1433
2646

27-
showcasefrontend:
47+
showcaseapitesting:
2848
build:
2949
context: .
30-
dockerfile: ShowcaseFrontend/Dockerfile
31-
target: dev
32-
container_name: showcasefrontend
33-
ports:
34-
- "8080:80"
50+
dockerfile: ShowcaseApiTesting/Dockerfile
51+
container_name: showcaseapitesting
3552
depends_on:
3653
- showcaseapi
37-
environment:
38-
- API_BASE_URL=http://showcaseapi
3954
volumes:
40-
- ./ShowcaseFrontend:/app/ShowcaseFrontend
41-
- ~/.nuget/packages:/root/.nuget/packages:ro
42-
command: ["dotnet", "watch", "run", "--project", "/app/ShowcaseFrontend/ShowcaseFrontend.csproj", "--no-launch-profile", "--urls=http://0.0.0.0:80"]
55+
- ./ShowcaseApiTesting/TestResults:/src/ShowcaseApiTesting/TestResults
4356

4457
volumes:
45-
sql_data:
58+
sql_data:

0 commit comments

Comments
 (0)