Skip to content

Commit 22aaf35

Browse files
committed
feat: add nginx configuration and basic auth setup for documentation site
1 parent 48ebf33 commit 22aaf35

5 files changed

Lines changed: 47 additions & 1 deletion

File tree

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Required
2+
BASIC_AUTH_USER=
3+
BASIC_AUTH_PASS=

Dockerfile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ RUN npm ci
99
COPY . .
1010
RUN npm run build
1111

12-
# ---- Production image: serves the prebuilt static site via nginx ----
12+
# ---- Production image: serves the prebuilt static site via nginx, behind basic auth ----
1313
FROM nginxinc/nginx-unprivileged:1.27-alpine AS prod
14+
USER root
15+
RUN apk add --no-cache apache2-utils
1416
COPY --from=build /app/build /usr/share/nginx/html
17+
COPY docker/nginx.conf /etc/nginx/conf.d/default.conf
18+
COPY docker/start.sh /usr/local/bin/start.sh
19+
RUN chmod +x /usr/local/bin/start.sh
20+
USER nginx
1521
EXPOSE 8080
22+
CMD ["/usr/local/bin/start.sh"]

docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@ services:
22
docs-prod:
33
build:
44
context: .
5+
environment:
6+
BASIC_AUTH_USER: ${BASIC_AUTH_USER:?BASIC_AUTH_USER is required}
7+
BASIC_AUTH_PASS: ${BASIC_AUTH_PASS:?BASIC_AUTH_PASS is required}
58
ports:
69
- '3000:8080'

docker/nginx.conf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
server {
2+
listen 8080;
3+
server_name _;
4+
5+
root /usr/share/nginx/html;
6+
index index.html;
7+
8+
auth_basic "Docs Preview";
9+
auth_basic_user_file /tmp/.htpasswd;
10+
11+
location = /health {
12+
auth_basic off;
13+
access_log off;
14+
default_type text/plain;
15+
return 200 "ok";
16+
}
17+
18+
location / {
19+
try_files $uri $uri/ $uri.html =404;
20+
}
21+
}

docker/start.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
# Source vault-injected secrets if present (K8s openbao/vault agent)
5+
[ -f /vault/secrets/auth ] && . /vault/secrets/auth
6+
7+
: "${BASIC_AUTH_USER:?BASIC_AUTH_USER env var is required}"
8+
: "${BASIC_AUTH_PASS:?BASIC_AUTH_PASS env var is required}"
9+
10+
htpasswd -bc /tmp/.htpasswd "$BASIC_AUTH_USER" "$BASIC_AUTH_PASS"
11+
12+
exec nginx -g 'daemon off;'

0 commit comments

Comments
 (0)