Skip to content

Commit dd91722

Browse files
committed
changed to current wait for in docker and implemented healthchecks
1 parent 5f4da42 commit dd91722

6 files changed

Lines changed: 22 additions & 195 deletions

File tree

.env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
APPPort=5000
12
DBProvider=psql
23
DBName=NETEVENT
34
DBServer=netevent_psql
45
DBPort=5432
56
DBUser=NETEVENTDBUSER
67
DBPassword=NETEVENTDBPASSWORD
7-
TZ=Europe/Berlin
8-
ASPNETCORE_URLS=http://+:5000
8+
TZ=Europe/Berlin

Dockerfile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ RUN apt-get update -qqy && DEBIAN_FRONTEND=noninteractive apt-get install -y \
1313
RUN wget https://packages.microsoft.com/config/debian/11/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
1414
RUN dpkg -i packages-microsoft-prod.deb
1515
RUN rm packages-microsoft-prod.deb
16-
RUN apt-get update -qqy && apt-get install -y dotnet-sdk-6.0
16+
RUN apt-get update -qqy && apt-get install -y dotnet-sdk-6.0 python3 python3-pip wget
17+
RUN pip install lastversion
1718
RUN eval apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
1819

20+
#get wait-for
21+
RUN wget -q $(lastversion https://github.com/eficode/wait-for --format assets)
22+
1923
#get NetEvent and publish it
2024
COPY NetEvent /NetEvent
2125
WORKDIR /NetEvent
@@ -47,7 +51,7 @@ VOLUME [ "/data" ]
4751

4852
#container scripts
4953
COPY docker/start-container /usr/local/bin/start-container
50-
COPY docker/wait-for.sh /usr/local/bin/wait-for.sh
54+
COPY --from=build /wait-for /usr/local/bin/wait-for.sh
5155
RUN chmod +x /usr/local/bin/start-container
5256
RUN chmod +x /usr/local/bin/wait-for.sh
5357

@@ -57,7 +61,7 @@ RUN apt-get update -qqy && DEBIAN_FRONTEND=noninteractive apt-get install -y \
5761
RUN wget https://packages.microsoft.com/config/debian/11/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
5862
RUN dpkg -i packages-microsoft-prod.deb
5963
RUN rm packages-microsoft-prod.deb
60-
RUN apt-get update -qqy && apt-get install -y aspnetcore-runtime-6.0
64+
RUN apt-get update -qqy && apt-get install -y aspnetcore-runtime-6.0 netcat curl
6165
RUN eval apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
6266

6367
#copy NetEvent files
@@ -83,4 +87,5 @@ USER NetEvent
8387

8488
# run
8589
WORKDIR /NetEvent
86-
CMD [ "/bin/sh", "-c", "start-container" ]
90+
CMD [ "/bin/sh", "-c", "start-container" ]
91+
HEALTHCHECK --retries=3 --timeout=10s CMD curl --fail http://localhost:5000/healthcheck || exit

NetEvent/Server/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
builder.Services.AddEndpointsApiExplorer();
5454
builder.Services.AddSwaggerGen();
5555

56+
builder.Services.AddHealthChecks();
57+
5658
var app = builder.Build();
5759

5860
using (IServiceScope scope = app.Services.CreateScope())
@@ -72,6 +74,7 @@
7274
}
7375
else
7476
{
77+
app.UseHealthChecks("/healthcheck");
7578
app.UseExceptionHandler("/Error");
7679
app.UseHsts();
7780
}

docker-compose.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ services:
33
netevent:
44
image: lan2play/netevent
55
ports:
6-
- '5000:5000/tcp'
6+
- '${APPPort:-5000}:5000'
77
env_file: .env
88
environment:
9-
ASPNETCORE_URLS: '${ASPNETCORE_URLS}'
109
DBProvider: "${DBProvider}"
1110
DBName: "${DBName}"
1211
DBServer: "${DBServer}"
@@ -20,6 +19,10 @@ services:
2019
- netevent
2120
depends_on:
2221
- netevent_psql
22+
healthcheck:
23+
test: ["CMD-SHELL", "curl --fail http://localhost:5000/healthcheck || exit"]
24+
retries: 3
25+
timeout: 10s
2326

2427
netevent_psql:
2528
image: 'postgres:latest'
@@ -34,9 +37,9 @@ services:
3437
networks:
3538
- netevent
3639
healthcheck:
37-
test: ["CMD-SHELL", "pg_isready -U postgres"]
40+
test: ["CMD-SHELL", "pg_isready -U ${DBUser} -d ${DBName}"]
3841
retries: 3
39-
timeout: 5s
42+
timeout: 10s
4043

4144
networks:
4245
netevent:

docker/start-container

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ then
77
# Database Wait check
88
echo "---------------"
99
echo "WAITING FOR $DBServer:$DBPort..."
10-
wait-for.sh $DBServer:$DBPort --timeout=30 --strict -- /NetEvent/NetEvent.Server
10+
wait-for.sh $DBServer:$DBPort --timeout=30 -- /NetEvent/NetEvent.Server
1111
fi
1212
if [[ "$DBProvider" = "sqlite" ]]
1313
then

docker/wait-for.sh

Lines changed: 0 additions & 184 deletions
This file was deleted.

0 commit comments

Comments
 (0)