feat: Add APP_NAME env support for branding and deployment
- Make app name configurable via APP_NAME env variable - Update UI, HTML, Docker, scripts, and k8s to use APP_NAME - Add process-html.sh for template substitution - Document APP_NAME usage in docs/APP_NAME_CONFIGURATION.md - Update Dockerfile, compose, and scripts for dynamic naming - Add index.html.template for environment-based branding
This commit is contained in:
@@ -34,9 +34,10 @@ print_error() {
|
||||
# Cleanup function
|
||||
cleanup() {
|
||||
print_status "Cleaning up test containers..."
|
||||
docker stop meds-validation-test 2>/dev/null || true
|
||||
docker rm meds-validation-test 2>/dev/null || true
|
||||
docker compose -f docker/docker-compose.yaml -p meds-validation down 2>/dev/null || true
|
||||
APP_NAME_LOWER=$(echo "${APP_NAME:-meds}" | tr '[:upper:]' '[:lower:]')
|
||||
docker stop ${APP_NAME_LOWER}-validation-test 2>/dev/null || true
|
||||
docker rm ${APP_NAME_LOWER}-validation-test 2>/dev/null || true
|
||||
docker compose -f docker/docker-compose.yaml -p ${APP_NAME_LOWER}-validation down 2>/dev/null || true
|
||||
}
|
||||
|
||||
# Set trap for cleanup
|
||||
@@ -81,8 +82,12 @@ docker buildx use meds-builder
|
||||
print_status "4. Building multi-platform Docker image with buildx..."
|
||||
|
||||
# Build the image with buildx for multiple platforms
|
||||
# Build single-platform image for testing
|
||||
print_status "Building single-platform Docker image for testing..."
|
||||
APP_NAME_LOWER=$(echo "${APP_NAME:-meds}" | tr '[:upper:]' '[:lower:]')
|
||||
docker buildx build --no-cache \
|
||||
--platform linux/amd64,linux/arm64 \
|
||||
--platform "$HOST_PLATFORM" \
|
||||
--build-arg APP_NAME="${APP_NAME:-RxMinder}" \
|
||||
--build-arg COUCHDB_USER="${COUCHDB_USER:-admin}" \
|
||||
--build-arg COUCHDB_PASSWORD="${COUCHDB_PASSWORD:-change-this-secure-password}" \
|
||||
--build-arg VITE_COUCHDB_URL="${VITE_COUCHDB_URL:-http://localhost:5984}" \
|
||||
@@ -95,7 +100,7 @@ docker buildx build --no-cache \
|
||||
--build-arg MAILGUN_DOMAIN="${MAILGUN_DOMAIN:-}" \
|
||||
--build-arg MAILGUN_FROM_EMAIL="${MAILGUN_FROM_EMAIL:-}" \
|
||||
--build-arg NODE_ENV="${NODE_ENV:-production}" \
|
||||
-t meds-validation \
|
||||
-t ${APP_NAME_LOWER}-validation \
|
||||
--load \
|
||||
.
|
||||
|
||||
@@ -106,16 +111,16 @@ print_status "5. Testing container startup and health..."
|
||||
# Run container in background
|
||||
docker run --rm -d \
|
||||
-p 8083:80 \
|
||||
--name meds-validation-test \
|
||||
meds-validation
|
||||
--name ${APP_NAME_LOWER}-validation-test \
|
||||
${APP_NAME_LOWER}-validation
|
||||
|
||||
# Wait for container to start
|
||||
sleep 5
|
||||
|
||||
# Check if container is running
|
||||
if ! docker ps | grep -q meds-validation-test; then
|
||||
if ! docker ps | grep -q ${APP_NAME_LOWER}-validation-test; then
|
||||
print_error "Container failed to start"
|
||||
docker logs meds-validation-test
|
||||
docker logs ${APP_NAME_LOWER}-validation-test
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -154,17 +159,17 @@ print_success "Docker Compose build successful"
|
||||
|
||||
# Test docker-compose with validation project name
|
||||
print_status "8. Testing Docker Compose deployment..."
|
||||
docker compose -f docker/docker-compose.yaml -p meds-validation up -d --build
|
||||
docker compose -f docker/docker-compose.yaml -p ${APP_NAME_LOWER}-validation up -d --build
|
||||
|
||||
# Wait for services to start
|
||||
sleep 10
|
||||
|
||||
# Check service health
|
||||
if docker compose -f docker/docker-compose.yaml -p meds-validation ps | grep -q "Up"; then
|
||||
if docker compose -f docker/docker-compose.yaml -p ${APP_NAME_LOWER}-validation ps | grep -q "Up"; then
|
||||
print_success "Docker Compose services started successfully"
|
||||
else
|
||||
print_error "Docker Compose services failed to start"
|
||||
docker compose -f docker/docker-compose.yaml -p meds-validation logs
|
||||
docker compose -f docker/docker-compose.yaml -p ${APP_NAME_LOWER}-validation logs
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -176,13 +181,13 @@ else
|
||||
fi
|
||||
|
||||
print_status "9. Checking image size..."
|
||||
IMAGE_SIZE=$(docker image inspect meds-validation --format='{{.Size}}' | numfmt --to=iec)
|
||||
IMAGE_SIZE=$(docker image inspect ${APP_NAME_LOWER}-validation --format='{{.Size}}' | numfmt --to=iec)
|
||||
print_success "Image size: $IMAGE_SIZE"
|
||||
|
||||
print_status "10. Validating security configuration..."
|
||||
|
||||
# Check if image runs as non-root
|
||||
USER_INFO=$(docker run --rm meds-validation whoami)
|
||||
USER_INFO=$(docker run --rm ${APP_NAME_LOWER}-validation whoami)
|
||||
if [[ "$USER_INFO" != "root" ]]; then
|
||||
print_success "Container runs as non-root user: $USER_INFO"
|
||||
else
|
||||
@@ -190,7 +195,7 @@ else
|
||||
fi
|
||||
|
||||
# Check nginx configuration
|
||||
if docker run --rm meds-validation nginx -t 2>/dev/null; then
|
||||
if docker run --rm ${APP_NAME_LOWER}-validation nginx -t 2>/dev/null; then
|
||||
print_success "Nginx configuration is valid"
|
||||
else
|
||||
print_error "Nginx configuration has issues"
|
||||
|
||||
@@ -34,9 +34,10 @@ print_error() {
|
||||
# Cleanup function
|
||||
cleanup() {
|
||||
print_status "Cleaning up test containers..."
|
||||
docker stop meds-validation-test 2>/dev/null || true
|
||||
docker rm meds-validation-test 2>/dev/null || true
|
||||
docker compose -f docker/docker-compose.yaml -p meds-validation down 2>/dev/null || true
|
||||
APP_NAME_LOWER=$(echo "${APP_NAME:-meds}" | tr '[:upper:]' '[:lower:]')
|
||||
docker stop ${APP_NAME_LOWER}-validation-test 2>/dev/null || true
|
||||
docker rm ${APP_NAME_LOWER}-validation-test 2>/dev/null || true
|
||||
docker compose -f docker/docker-compose.yaml -p ${APP_NAME_LOWER}-validation down 2>/dev/null || true
|
||||
}
|
||||
|
||||
# Set trap for cleanup
|
||||
@@ -80,6 +81,9 @@ docker buildx use meds-builder
|
||||
|
||||
print_status "4. Building multi-platform Docker image with buildx..."
|
||||
|
||||
# Convert APP_NAME to lowercase for Docker compatibility
|
||||
APP_NAME_LOWER=$(echo "${APP_NAME:-meds}" | tr '[:upper:]' '[:lower:]')
|
||||
|
||||
# Determine host platform
|
||||
HOST_ARCH="$(uname -m)"
|
||||
case "$HOST_ARCH" in
|
||||
@@ -97,18 +101,19 @@ if [[ "${MULTI_PLATFORM:-0}" == "1" || -n "${CONTAINER_REGISTRY:-}" ]]; then
|
||||
if [[ -n "${CONTAINER_REGISTRY:-}" && "${CONTAINER_REGISTRY}" != */ ]]; then
|
||||
CONTAINER_REGISTRY="${CONTAINER_REGISTRY}/"
|
||||
fi
|
||||
IMAGE_TAG="${IMAGE_TAG:-${CONTAINER_REGISTRY:-}meds-validation:latest}"
|
||||
IMAGE_TAG="${IMAGE_TAG:-${CONTAINER_REGISTRY:-}${APP_NAME_LOWER}-validation:latest}"
|
||||
print_status "Multi-platform build enabled (platforms: $BUILD_PLATFORMS) -> push $IMAGE_TAG"
|
||||
else
|
||||
BUILD_PLATFORMS="$HOST_PLATFORM"
|
||||
EXPORT_MODE="--load"
|
||||
IMAGE_TAG="${IMAGE_TAG:-meds-validation}"
|
||||
IMAGE_TAG="${IMAGE_TAG:-${APP_NAME_LOWER}-validation}"
|
||||
print_status "Single-platform build ($BUILD_PLATFORMS) -> load locally as $IMAGE_TAG"
|
||||
fi
|
||||
|
||||
# Perform build
|
||||
docker buildx build --no-cache \
|
||||
--platform "$BUILD_PLATFORMS" \
|
||||
--build-arg APP_NAME="${APP_NAME:-RxMinder}" \
|
||||
--build-arg COUCHDB_USER="${COUCHDB_USER:-admin}" \
|
||||
--build-arg COUCHDB_PASSWORD="${COUCHDB_PASSWORD:-change-this-secure-password}" \
|
||||
--build-arg VITE_COUCHDB_URL="${VITE_COUCHDB_URL:-http://localhost:5984}" \
|
||||
@@ -138,16 +143,16 @@ print_status "5. Testing container startup and health..."
|
||||
# Run container in background
|
||||
docker run --rm -d \
|
||||
-p 8083:80 \
|
||||
--name meds-validation-test \
|
||||
--name ${APP_NAME_LOWER}-validation-test \
|
||||
"$IMAGE_TAG"
|
||||
|
||||
# Wait for container to start
|
||||
sleep 5
|
||||
|
||||
# Check if container is running
|
||||
if ! docker ps | grep -q meds-validation-test; then
|
||||
if ! docker ps | grep -q ${APP_NAME_LOWER}-validation-test; then
|
||||
print_error "Container failed to start"
|
||||
docker logs meds-validation-test
|
||||
docker logs ${APP_NAME_LOWER}-validation-test
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -186,17 +191,17 @@ print_success "Docker Compose build successful"
|
||||
|
||||
# Test docker-compose with validation project name
|
||||
print_status "8. Testing Docker Compose deployment..."
|
||||
docker compose -f docker/docker-compose.yaml -p meds-validation up -d --build
|
||||
docker compose -f docker/docker-compose.yaml -p ${APP_NAME_LOWER}-validation up -d --build
|
||||
|
||||
# Wait for services to start
|
||||
sleep 10
|
||||
|
||||
# Check service health
|
||||
if docker compose -f docker/docker-compose.yaml -p meds-validation ps | grep -q "Up"; then
|
||||
if docker compose -f docker/docker-compose.yaml -p ${APP_NAME_LOWER}-validation ps | grep -q "Up"; then
|
||||
print_success "Docker Compose services started successfully"
|
||||
else
|
||||
print_error "Docker Compose services failed to start"
|
||||
docker compose -f docker/docker-compose.yaml -p meds-validation logs
|
||||
docker compose -f docker/docker-compose.yaml -p ${APP_NAME_LOWER}-validation logs
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
24
scripts/process-html.sh
Executable file
24
scripts/process-html.sh
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Process HTML template with environment variables
|
||||
# This script substitutes environment variables in index.html.template
|
||||
|
||||
set -e
|
||||
|
||||
# Default values
|
||||
APP_NAME="${APP_NAME:-RxMinder}"
|
||||
|
||||
# Input and output files
|
||||
TEMPLATE_FILE="index.html.template"
|
||||
OUTPUT_FILE="index.html"
|
||||
|
||||
# Check if template exists
|
||||
if [[ ! -f "$TEMPLATE_FILE" ]]; then
|
||||
echo "Error: Template file $TEMPLATE_FILE not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Process template with environment variable substitution
|
||||
envsubst '$APP_NAME' < "$TEMPLATE_FILE" > "$OUTPUT_FILE"
|
||||
|
||||
echo "✅ Processed $TEMPLATE_FILE -> $OUTPUT_FILE with APP_NAME=$APP_NAME"
|
||||
@@ -34,9 +34,10 @@ print_error() {
|
||||
# Cleanup function
|
||||
cleanup() {
|
||||
print_status "Cleaning up test containers..."
|
||||
docker stop meds-validation-test 2>/dev/null || true
|
||||
docker rm meds-validation-test 2>/dev/null || true
|
||||
docker compose -f docker/docker-compose.yaml -p meds-validation down 2>/dev/null || true
|
||||
APP_NAME_LOWER=$(echo "${APP_NAME:-meds}" | tr '[:upper:]' '[:lower:]')
|
||||
docker stop ${APP_NAME_LOWER}-validation-test 2>/dev/null || true
|
||||
docker rm ${APP_NAME_LOWER}-validation-test 2>/dev/null || true
|
||||
docker compose -f docker/docker-compose.yaml -p ${APP_NAME_LOWER}-validation down 2>/dev/null || true
|
||||
}
|
||||
|
||||
# Set trap for cleanup
|
||||
@@ -80,9 +81,11 @@ docker buildx use meds-builder
|
||||
|
||||
print_status "4. Building multi-platform Docker image with buildx..."
|
||||
|
||||
# Build the image with buildx for multiple platforms
|
||||
# Build single-platform image for testing
|
||||
APP_NAME_LOWER=$(echo "${APP_NAME:-meds}" | tr '[:upper:]' '[:lower:]')
|
||||
docker buildx build --no-cache \
|
||||
--platform linux/amd64,linux/arm64 \
|
||||
--platform linux/amd64 \
|
||||
--build-arg APP_NAME="${APP_NAME:-RxMinder}" \
|
||||
--build-arg COUCHDB_USER="${COUCHDB_USER:-admin}" \
|
||||
--build-arg COUCHDB_PASSWORD="${COUCHDB_PASSWORD:-change-this-secure-password}" \
|
||||
--build-arg VITE_COUCHDB_URL="${VITE_COUCHDB_URL:-http://localhost:5984}" \
|
||||
@@ -95,7 +98,7 @@ docker buildx build --no-cache \
|
||||
--build-arg MAILGUN_DOMAIN="${MAILGUN_DOMAIN:-}" \
|
||||
--build-arg MAILGUN_FROM_EMAIL="${MAILGUN_FROM_EMAIL:-}" \
|
||||
--build-arg NODE_ENV="${NODE_ENV:-production}" \
|
||||
-t meds-validation \
|
||||
-t ${APP_NAME_LOWER}-validation \
|
||||
--load \
|
||||
.
|
||||
|
||||
@@ -106,16 +109,16 @@ print_status "5. Testing container startup and health..."
|
||||
# Run container in background
|
||||
docker run --rm -d \
|
||||
-p 8083:80 \
|
||||
--name meds-validation-test \
|
||||
meds-validation
|
||||
--name ${APP_NAME_LOWER}-validation-test \
|
||||
${APP_NAME_LOWER}-validation
|
||||
|
||||
# Wait for container to start
|
||||
sleep 5
|
||||
|
||||
# Check if container is running
|
||||
if ! docker ps | grep -q meds-validation-test; then
|
||||
if ! docker ps | grep -q ${APP_NAME_LOWER}-validation-test; then
|
||||
print_error "Container failed to start"
|
||||
docker logs meds-validation-test
|
||||
docker logs ${APP_NAME_LOWER}-validation-test
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -154,17 +157,17 @@ print_success "Docker Compose build successful"
|
||||
|
||||
# Test docker-compose with validation project name
|
||||
print_status "8. Testing Docker Compose deployment..."
|
||||
docker compose -f docker/docker-compose.yaml -p meds-validation up -d --build
|
||||
docker compose -f docker/docker-compose.yaml -p ${APP_NAME_LOWER}-validation up -d --build
|
||||
|
||||
# Wait for services to start
|
||||
sleep 10
|
||||
|
||||
# Check service health
|
||||
if docker compose -f docker/docker-compose.yaml -p meds-validation ps | grep -q "Up"; then
|
||||
if docker compose -f docker/docker-compose.yaml -p ${APP_NAME_LOWER}-validation ps | grep -q "Up"; then
|
||||
print_success "Docker Compose services started successfully"
|
||||
else
|
||||
print_error "Docker Compose services failed to start"
|
||||
docker compose -f docker/docker-compose.yaml -p meds-validation logs
|
||||
docker compose -f docker/docker-compose.yaml -p ${APP_NAME_LOWER}-validation logs
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -176,13 +179,13 @@ else
|
||||
fi
|
||||
|
||||
print_status "9. Checking image size..."
|
||||
IMAGE_SIZE=$(docker image inspect meds-validation --format='{{.Size}}' | numfmt --to=iec)
|
||||
IMAGE_SIZE=$(docker image inspect ${APP_NAME_LOWER}-validation --format='{{.Size}}' | numfmt --to=iec)
|
||||
print_success "Image size: $IMAGE_SIZE"
|
||||
|
||||
print_status "10. Validating security configuration..."
|
||||
|
||||
# Check if image runs as non-root
|
||||
USER_INFO=$(docker run --rm meds-validation whoami)
|
||||
USER_INFO=$(docker run --rm ${APP_NAME_LOWER}-validation whoami)
|
||||
if [[ "$USER_INFO" != "root" ]]; then
|
||||
print_success "Container runs as non-root user: $USER_INFO"
|
||||
else
|
||||
@@ -190,7 +193,7 @@ else
|
||||
fi
|
||||
|
||||
# Check nginx configuration
|
||||
if docker run --rm meds-validation nginx -t 2>/dev/null; then
|
||||
if docker run --rm ${APP_NAME_LOWER}-validation nginx -t 2>/dev/null; then
|
||||
print_success "Nginx configuration is valid"
|
||||
else
|
||||
print_error "Nginx configuration has issues"
|
||||
|
||||
Reference in New Issue
Block a user