mirror of
https://github.com/narrrl/holy-flavor-rater.git
synced 2026-11-04 00:47:02 +01:00
improved docker startup: frontend now waits for healthy backend
This commit is contained in:
1 parent
2774516051
commit
42e6905db4
5 files changed
+42
-2
No files matched your search
+5
-1
@@ -27,6 +27,10 @@ FROM nginx:stable-alpine
|
||||
# Copy built files
|
||||
COPY --from=build-stage /app/dist /usr/share/nginx/html
|
||||
|
||||
# Copy entrypoint script
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
|
||||
# Custom Nginx config to handle React Router (SPA)
|
||||
RUN printf 'server {\n\
|
||||
listen 80;\n\
|
||||
@@ -38,4 +42,4 @@ RUN printf 'server {\n\
|
||||
}' > /etc/nginx/conf.d/default.conf
|
||||
|
||||
EXPOSE 80
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
@@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
|
||||
# The backend hostname is 'holy-backend' based on docker-compose.yml
|
||||
# We wait for port 8000 to be open
|
||||
echo "Waiting for backend (holy-backend:8000) to be available..."
|
||||
|
||||
MAX_RETRIES=30
|
||||
COUNT=0
|
||||
|
||||
while ! nc -z holy-backend 8000; do
|
||||
COUNT=$((COUNT + 1))
|
||||
if [ $COUNT -ge $MAX_RETRIES ]; then
|
||||
echo "Backend timed out after $MAX_RETRIES attempts - starting Nginx anyway"
|
||||
break
|
||||
fi
|
||||
echo "Backend is unavailable (attempt $COUNT/$MAX_RETRIES) - sleeping"
|
||||
sleep 2
|
||||
done
|
||||
|
||||
echo "Starting Nginx..."
|
||||
exec nginx -g "daemon off;"
|
||||
Reference in new issue
Block a user