Skip to main content

Docker & Deployment

BonardaHR is packaged as an optimized, multi-stage Docker container served by Nginx Alpine.


Docker logo Dockerfile Architecture​

# Stage 1: Build the React app
FROM node:22-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

# Stage 2: Serve with Nginx
FROM nginx:stable-alpine
RUN apk add --no-cache gettext
COPY --from=build /app/dist /usr/share/nginx/html
COPY env.template.js /usr/share/nginx/html/env.template.js
COPY docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh

COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80

ENTRYPOINT ["/docker-entrypoint.sh"]

Nginx Configuration (nginx.conf)​

Key features configured in nginx.conf:

  1. SPA Fallback Routing: try_files $uri $uri/ /index.html; ensures React Router handles deep URLs.
  2. Gzip Compression: Compresses HTML, CSS, JavaScript, JSON, and SVG assets for high-speed delivery.
  3. No-Cache Policy for Runtime Config: Prevents stale env.js caching.
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
index index.html;

location = /env.js {
add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate";
add_header Pragma "no-cache";
add_header Expires "0";
try_files $uri =404;
}

# React Router / Vite SPA fallback
location / {
try_files $uri $uri/ /index.html;
}

# Gzip compression
gzip on;
gzip_vary on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
}

Helm & Kubernetes Deployment​

The frontend repository includes Helm chart definitions under helm/ for deployment to Kubernetes clusters:

  • Configures ingress hosts, TLS certificates, readiness & liveness probes.
  • Injects environment variables (VITE_API_BASE_URL, VITE_AZURE_CLIENT_ID, etc.) directly into the container pod spec.

Building & Testing the Docker Container Locally​

# Build the Docker image
docker build -t bonarda-hr-frontend .

# Run container with custom API backend
docker run -p 8080:80 \
-e VITE_API_BASE_URL=https://api-staging.bonardahr.com/api/v1 \
-e VITE_APP_NAME="Bonarda HR (Staging)" \
bonarda-hr-frontend

# Access via browser
open http://localhost:8080