FROM nginx:1.27-alpine

COPY .git /tmp/repo/.git

# Configure nginx to listen on 5001 to match container port expectations.
RUN sed -i 's/listen       80;/listen       5001;/' /etc/nginx/conf.d/default.conf

# Build a custom landing page directly in the image and inject git revision.
RUN set -eux; \
	apk add --no-cache --virtual .git-deps git; \
	GIT_REVISION="$(git --git-dir=/tmp/repo/.git rev-parse --short HEAD 2>/dev/null || echo unknown)"; \
	{ \
		echo '<!doctype html>'; \
		echo '<html lang="en">'; \
		echo '<head>'; \
		echo '  <meta charset="utf-8">'; \
		echo '  <meta name="viewport" content="width=device-width, initial-scale=1">'; \
		echo '  <title>Brencher Test App</title>'; \
		echo '</head>'; \
		echo '<body>'; \
		echo '  <h1>Nginx Is Running</h1>'; \
		echo '  <p>Custom landing page for the Brencher test app container.</p>'; \
		echo '  <p>Port: 5001</p>'; \
		echo "  <p>Git revision: ${GIT_REVISION}</p>"; \
		echo '</body>'; \
		echo '</html>'; \
	} > /usr/share/nginx/html/index.html; \
	rm -rf /tmp/repo/.git; \
	apk del .git-deps

EXPOSE 5001
