Skip to content

Commit aaa36f6

Browse files
committed
Add wait-for-postgres script to Dockerfile and update entrypoint
1 parent 8ed27ae commit aaa36f6

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Presentation/BookLibraryAPI.Presentation/Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ WORKDIR /app
33
EXPOSE 8080
44
EXPOSE 9443
55

6+
67
# Copy dev certificate
78
COPY ./src/Presentation/BookLibraryAPI.Presentation/aspnet-dev-cert.pfx /https/aspnet-dev-cert.pfx
89

10+
# Copy wait-for-postgres script
11+
COPY ../../wait-for-postgres.sh /app/wait-for-postgres.sh
12+
RUN chmod +x /app/wait-for-postgres.sh
13+
914
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
1015
ARG BUILD_CONFIGURATION=Release
1116
WORKDIR /src
@@ -22,4 +27,4 @@ RUN dotnet publish "./BookLibraryAPI.Presentation.csproj" -c $BUILD_CONFIGURATIO
2227
FROM base AS final
2328
WORKDIR /app
2429
COPY --from=publish /app/publish .
25-
ENTRYPOINT ["dotnet", "BookLibraryAPI.Presentation.dll"]
30+
ENTRYPOINT ["/bin/sh", "-c", "/app/wait-for-postgres.sh dotnet BookLibraryAPI.Presentation.dll"]

wait-for-postgres.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
until pg_isready -h book-lib-postgres -p 5432 -U postgres; do
3+
echo "Waiting for postgres..."
4+
sleep 2
5+
done
6+
exec "$@"

0 commit comments

Comments
 (0)