Reorganize infrastructure as code and implement versioning schema

This commit is contained in:
Alphaeus Mote
2025-05-21 19:40:57 -04:00
parent 8d1a6dd188
commit 2db108aa6b
34 changed files with 4870 additions and 870 deletions
+257
View File
@@ -0,0 +1,257 @@
# Infrastructure as Code (IaC)
This directory contains all the infrastructure as code configurations for deploying the Active Directory Management application.
## Directory Structure
- **docker/**: Docker-related files
- `Dockerfile`: Multi-stage Docker build file
- `docker-compose.yml`: Docker Compose configuration
- `build.sh`: Bash script for building and pushing Docker images (Linux/macOS)
- `build.ps1`: PowerShell script for building and pushing Docker images (Windows)
- `.env`: Environment variables for Docker deployment
- `.env.example`: Example environment variables
- `.env.production`: Production environment variables
- **version.txt**: Central version file in yyyy.MM.dd.HHmm format
- **update-version.sh**: Bash script to update version.txt (Linux/macOS)
- **update-version.ps1**: PowerShell script to update version.txt (Windows)
- **update-all.sh**: Comprehensive script to update all version references (Linux/macOS)
- **update-all.ps1**: Comprehensive script to update all version references (Windows)
- **kubernetes/**: Kubernetes manifests
- `namespace.yaml`: Namespace definition
- `configmap.yaml`: ConfigMap for non-sensitive configuration
- `secrets.yaml`: Secrets for sensitive configuration
- `postgres.yaml`: PostgreSQL StatefulSet and Service
- `redis.yaml`: Redis StatefulSet and Service
- `deployment.yaml`: Application Deployment and Service
- `ingress.yaml`: Ingress for external access
- `kustomization.yaml`: Kustomize configuration
## Docker
### Versioning
The application uses a versioning scheme in the format `yyyy.MM.dd.HHmm` (year, month, day, hour, minute).
#### Comprehensive Version Update
To update the version and apply it to all components (recommended):
On Linux/macOS:
```bash
# Navigate to the iac directory
cd iac
# Make the script executable
chmod +x update-all.sh
# Update all version references
./update-all.sh
```
On Windows:
```powershell
# Navigate to the iac directory
cd iac
# Update all version references
.\update-all.ps1
```
#### Manual Version Update
To update only the version.txt file:
On Linux/macOS:
```bash
# Navigate to the iac directory
cd iac
# Make the script executable
chmod +x update-version.sh
# Update the version
./update-version.sh
```
On Windows:
```powershell
# Navigate to the iac directory
cd iac
# Update the version
.\update-version.ps1
```
### Building Docker Images
#### Using the build scripts
On Linux/macOS:
```bash
# Navigate to the iac/docker directory
cd iac/docker
# Make the script executable
chmod +x build.sh
# Build the image with version from version.txt
./build.sh
# Build with custom tag
./build.sh --tag 2025.05.21.1430
# Build and push to a registry
./build.sh --registry your-registry.com --push
```
On Windows:
```powershell
# Navigate to the iac/docker directory
cd iac\docker
# Build the image with version from version.txt
.\build.ps1
# Build with custom tag
.\build.ps1 -tag 2025.05.21.1430
# Build and push to a registry
.\build.ps1 -registry your-registry.com -push
```
#### Manually
```bash
# Navigate to the project root
cd /path/to/project
# Get the version from version.txt
VERSION=$(cat iac/version.txt)
# Build the image
docker build -t ActiveDirectoryManager:$VERSION -f iac/docker/Dockerfile .
# Tag the image for a registry
docker tag ActiveDirectoryManager:$VERSION your-registry.com/ActiveDirectoryManager:$VERSION
# Push to registry
docker push your-registry.com/ActiveDirectoryManager:$VERSION
```
### Running with Docker Compose
```bash
# Navigate to the iac/docker directory
cd iac/docker
# Create a .env file from the example if you haven't already
cp .env.example .env
# Edit the .env file with your configuration
# Load the version from version.txt
source .env.version
# Start the application stack
docker-compose up -d
# View logs
docker-compose logs -f
# Stop the application stack
docker-compose down
```
## Kubernetes
### Prerequisites
- Kubernetes cluster (v1.19+)
- kubectl configured to communicate with your cluster
- Kustomize (v4.0+) or kubectl v1.14+ which includes kustomize
### Updating Deployment Version
Before deploying, you should update the Kubernetes deployment to use the current version:
On Linux/macOS:
```bash
# Navigate to the iac/kubernetes directory
cd iac/kubernetes
# Make the script executable
chmod +x update-deployment-version.sh
# Update the deployment version
./update-deployment-version.sh
```
On Windows:
```powershell
# Navigate to the iac/kubernetes directory
cd iac\kubernetes
# Update the deployment version
.\update-deployment-version.ps1
```
### Deployment
```bash
# Navigate to the iac/kubernetes directory
cd iac/kubernetes
# Apply all resources
kubectl apply -k .
# Or from anywhere in the project
kubectl apply -k iac/kubernetes
```
### Customization
To customize the deployment for different environments:
1. Create a new directory for your environment:
```bash
mkdir -p iac/kubernetes/environments/production
```
2. Create a kustomization.yaml file that references the base configuration:
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: ad-management-production
resources:
- ../../ # Reference the base configuration
patches:
# Add your patches here
```
3. Apply the environment-specific configuration:
```bash
kubectl apply -k iac/kubernetes/environments/production
```
## CI/CD Integration
The Docker build scripts are designed to be used in CI/CD pipelines. Example integration with GitHub Actions:
```yaml
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build and push Docker image
run: |
cd iac/docker
chmod +x build.sh
./build.sh --registry ghcr.io --tag ${{ github.sha }} --push
```
+21
View File
@@ -0,0 +1,21 @@
# Environment Variables for Docker Deployment
# Copy from .env.example and customize as needed
# Database Configuration
POSTGRES_USER=admanagement
POSTGRES_PASSWORD=change_this_to_a_secure_password
POSTGRES_DB=admanagement
# Application Configuration
NODE_ENV=production
PORT=5000
BASE_URL=http://localhost:5000
SESSION_SECRET=change_this_to_a_random_string
JWT_SECRET=change_this_to_a_different_random_string
# Default Admin User Configuration
DEFAULT_ADMIN_USERNAME=admin
DEFAULT_ADMIN_PASSWORD=change_this_to_a_secure_password
DEFAULT_ADMIN_EMAIL=admin@example.com
DEFAULT_ADMIN_FULLNAME=System Administrator
DISABLE_REGISTRATION=false
+56
View File
@@ -0,0 +1,56 @@
# Database Configuration
POSTGRES_USER=admanagement
POSTGRES_PASSWORD=strong_password_here
POSTGRES_DB=admanagement
DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}
# Redis Configuration
REDIS_URL=redis://redis:6379
# Application Configuration
NODE_ENV=production
PORT=5000
BASE_URL=http://localhost:5000
SESSION_SECRET=change_this_to_a_random_string
DEBUG=api:*
# JWT Secret for API tokens
JWT_SECRET=change_this_to_a_different_random_string
JWT_EXPIRY=24h
# LDAP Connection Default Settings
LDAP_CONNECT_TIMEOUT=10000
LDAP_IDLE_TIMEOUT=60000
LDAP_RECONNECT_TIMEOUT=10000
# Rate Limiting
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX_REQUESTS=1000
# Logging
LOG_LEVEL=info
# Default Admin User Configuration
DEFAULT_ADMIN_USERNAME=admin
DEFAULT_ADMIN_PASSWORD=password
DEFAULT_ADMIN_EMAIL=admin@example.com
DEFAULT_ADMIN_FULLNAME=System Administrator
DISABLE_REGISTRATION=false
# LDAP Authentication Configuration (Optional)
# LDAP_SERVER=ldap.example.com
# LDAP_PORT=389
# LDAP_USE_TLS=true
# LDAP_BIND_DN=cn=admin,dc=example,dc=com
# LDAP_BIND_PASSWORD=admin_password
# LDAP_SEARCH_BASE=dc=example,dc=com
# LDAP_SEARCH_FILTER=(uid={{username}})
# OpenID Connect Authentication Configuration (Optional)
# OIDC_ISSUER=https://accounts.google.com
# OIDC_AUTHORIZATION_URL=https://accounts.google.com/o/oauth2/v2/auth
# OIDC_TOKEN_URL=https://oauth2.googleapis.com/token
# OIDC_USERINFO_URL=https://openidconnect.googleapis.com/v1/userinfo
# OIDC_CLIENT_ID=your_client_id
# OIDC_CLIENT_SECRET=your_client_secret
# OIDC_CALLBACK_URL=http://localhost:5000/api/auth/oidc/callback
+25
View File
@@ -0,0 +1,25 @@
# Production Environment Settings
# Node Environment
NODE_ENV=production
# Server Configuration
PORT=5000
HOST=0.0.0.0
# Logging
LOG_LEVEL=info
DEBUG=api:error,api:cache
# Performance Tuning
COMPRESSION_LEVEL=6
BODY_PARSER_LIMIT=10mb
# Security Settings
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX_REQUESTS=500
SESSION_COOKIE_SECURE=true
SESSION_COOKIE_HTTPONLY=true
# API Settings
SWAGGER_ENABLED=true
+3
View File
@@ -0,0 +1,3 @@
# This file is used to set the VERSION environment variable for docker-compose
# It reads the version from the version.txt file
VERSION=$(cat ../version.txt)
+65
View File
@@ -0,0 +1,65 @@
FROM node:20-alpine AS builder
# Set working directory
WORKDIR /app
# Copy package.json and package-lock.json
COPY package*.json ./
# Install dependencies
RUN npm ci
# Copy project files
COPY . .
# Build the application
RUN npm run build
# Production image
FROM node:20-alpine AS production
# Set working directory
WORKDIR /app
# Set environment variables
ENV NODE_ENV=production
ENV PORT=5000
ENV BASE_URL=http://localhost:5000
# Authentication environment variables
ENV JWT_SECRET=change-this-in-production
ENV SESSION_SECRET=change-this-in-production
ENV DEFAULT_ADMIN_USERNAME=admin
ENV DEFAULT_ADMIN_PASSWORD=password
ENV DEFAULT_ADMIN_EMAIL=
ENV DEFAULT_ADMIN_FULLNAME="System Administrator"
ENV DISABLE_REGISTRATION=false
# Database configuration
ENV DATABASE_URL=postgres://postgres:postgres@postgres:5432/admgr
# Copy package files
COPY package*.json ./
# Install production dependencies only
RUN npm ci --only=production
# Copy built application from builder stage
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
# Copy migration files
COPY --from=builder /app/migrations ./migrations
# Create a non-root user and set ownership
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
RUN chown -R appuser:appgroup /app
# Switch to non-root user
USER appuser
# Expose the port the app runs on
EXPOSE 5000
# Start the application
CMD ["node", "dist/server/index.js"]
+74
View File
@@ -0,0 +1,74 @@
# PowerShell script for building Docker images (Windows)
param (
[string]$tag = "",
[string]$registry = "",
[switch]$push = $false,
[string]$imageName = "ActiveDirectoryManager"
)
# If no tag is provided, use the version from version.txt
if (-not $tag) {
$versionFile = Join-Path (Split-Path $PSScriptRoot) "version.txt"
if (Test-Path $versionFile) {
$tag = Get-Content $versionFile -Raw
$tag = $tag.Trim()
} else {
# If version.txt doesn't exist, use current date/time in yyyy.MM.dd.HHmm format
$tag = Get-Date -Format "yyyy.MM.dd.HHmm"
}
}
# Set error action preference to stop on any error
$ErrorActionPreference = "Stop"
# Display build information
Write-Host "Building Docker image: $imageName" -ForegroundColor Green
Write-Host "Tag: $tag" -ForegroundColor Green
if ($registry) {
Write-Host "Registry: $registry" -ForegroundColor Green
}
# Determine the full image name
$fullImageName = if ($registry) { "$registry/$imageName" } else { $imageName }
# Check if Docker is available
try {
docker --version
}
catch {
Write-Host "Docker is not available. Please install Docker and try again." -ForegroundColor Red
exit 1
}
# Build the Docker image
try {
Write-Host "Building image: $fullImageName`:$tag" -ForegroundColor Cyan
# Navigate to the root directory (two levels up from the script location)
$rootDir = (Get-Item $PSScriptRoot).Parent.Parent.FullName
# Build the Docker image
docker build -t "$fullImageName`:$tag" -f "$PSScriptRoot/Dockerfile" $rootDir
if ($LASTEXITCODE -ne 0) {
throw "Docker build failed with exit code $LASTEXITCODE"
}
Write-Host "Successfully built image: $fullImageName`:$tag" -ForegroundColor Green
# Push the image if requested
if ($push) {
Write-Host "Pushing image to registry: $fullImageName`:$tag" -ForegroundColor Cyan
docker push "$fullImageName`:$tag"
if ($LASTEXITCODE -ne 0) {
throw "Docker push failed with exit code $LASTEXITCODE"
}
Write-Host "Successfully pushed image: $fullImageName`:$tag" -ForegroundColor Green
}
}
catch {
Write-Host "Error: $_" -ForegroundColor Red
exit 1
}
+91
View File
@@ -0,0 +1,91 @@
#!/bin/bash
# Bash script for building Docker images (Linux/macOS)
# Default values
TAG=""
REGISTRY=""
PUSH=false
IMAGE_NAME="ActiveDirectoryManager"
# If no tag is provided, use the version from version.txt
if [ -z "$TAG" ]; then
VERSION_FILE="$(dirname "$(dirname "$0")")/version.txt"
if [ -f "$VERSION_FILE" ]; then
TAG=$(cat "$VERSION_FILE" | tr -d '[:space:]')
else
# If version.txt doesn't exist, use current date/time in yyyy.MM.dd.HHmm format
TAG=$(date +"%Y.%m.%d.%H%M")
fi
fi
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--tag)
TAG="$2"
shift 2
;;
--registry)
REGISTRY="$2"
shift 2
;;
--push)
PUSH=true
shift
;;
--image-name)
IMAGE_NAME="$2"
shift 2
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
# Determine the full image name
if [ -n "$REGISTRY" ]; then
FULL_IMAGE_NAME="$REGISTRY/$IMAGE_NAME"
else
FULL_IMAGE_NAME="$IMAGE_NAME"
fi
# Display build information
echo -e "\e[32mBuilding Docker image: $IMAGE_NAME\e[0m"
echo -e "\e[32mTag: $TAG\e[0m"
if [ -n "$REGISTRY" ]; then
echo -e "\e[32mRegistry: $REGISTRY\e[0m"
fi
# Check if Docker is available
if ! command -v docker &> /dev/null; then
echo -e "\e[31mDocker is not available. Please install Docker and try again.\e[0m"
exit 1
fi
# Build the Docker image
echo -e "\e[36mBuilding image: $FULL_IMAGE_NAME:$TAG\e[0m"
# Navigate to the root directory (two levels up from the script location)
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
# Build the Docker image
if ! docker build -t "$FULL_IMAGE_NAME:$TAG" -f "$(dirname "${BASH_SOURCE[0]}")/Dockerfile" "$ROOT_DIR"; then
echo -e "\e[31mDocker build failed\e[0m"
exit 1
fi
echo -e "\e[32mSuccessfully built image: $FULL_IMAGE_NAME:$TAG\e[0m"
# Push the image if requested
if [ "$PUSH" = true ]; then
echo -e "\e[36mPushing image to registry: $FULL_IMAGE_NAME:$TAG\e[0m"
if ! docker push "$FULL_IMAGE_NAME:$TAG"; then
echo -e "\e[31mDocker push failed\e[0m"
exit 1
fi
echo -e "\e[32mSuccessfully pushed image: $FULL_IMAGE_NAME:$TAG\e[0m"
fi
+80
View File
@@ -0,0 +1,80 @@
services:
app:
build:
context: ../../
dockerfile: iac/docker/Dockerfile
image: ActiveDirectoryManager:${VERSION:-latest}
container_name: ActiveDirectoryManager-api
restart: unless-stopped
ports:
- "5000:5000"
environment:
- NODE_ENV=production
- PORT=5000
- BASE_URL=${BASE_URL:-http://localhost:5000}
- DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}
- REDIS_URL=redis://redis:6379
- SESSION_SECRET=${SESSION_SECRET}
- JWT_SECRET=${JWT_SECRET}
- DEFAULT_ADMIN_USERNAME=${DEFAULT_ADMIN_USERNAME:-admin}
- DEFAULT_ADMIN_PASSWORD=${DEFAULT_ADMIN_PASSWORD:-password}
- DEFAULT_ADMIN_EMAIL=${DEFAULT_ADMIN_EMAIL}
- DEFAULT_ADMIN_FULLNAME=${DEFAULT_ADMIN_FULLNAME:-System Administrator}
- DISABLE_REGISTRATION=${DISABLE_REGISTRATION:-false}
depends_on:
- postgres
- redis
networks:
- app-network
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:5000/api/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
postgres:
image: postgres:15-alpine
container_name: ActiveDirectoryManager-postgres
restart: unless-stopped
environment:
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_DB=${POSTGRES_DB}
volumes:
- postgres-data:/var/lib/postgresql/data
ports:
- "5432:5432"
networks:
- app-network
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
redis:
image: redis:7-alpine
container_name: ActiveDirectoryManager-redis
restart: unless-stopped
command: redis-server --appendonly yes
volumes:
- redis-data:/data
ports:
- "6379:6379"
networks:
- app-network
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
networks:
app-network:
driver: bridge
volumes:
postgres-data:
redis-data:
+14
View File
@@ -0,0 +1,14 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: ad-management-config
namespace: ad-management
data:
NODE_ENV: "production"
PORT: "5000"
BASE_URL: "https://ad-management.example.com"
DEFAULT_ADMIN_USERNAME: "admin"
DEFAULT_ADMIN_FULLNAME: "System Administrator"
DISABLE_REGISTRATION: "false"
POSTGRES_DB: "admgr"
POSTGRES_USER: "postgres"
+73
View File
@@ -0,0 +1,73 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: ad-management
namespace: ad-management
spec:
replicas: 2
selector:
matchLabels:
app: ad-management
template:
metadata:
labels:
app: ad-management
spec:
containers:
- name: activedirectorymanager
image: ActiveDirectoryManager:2025.05.21.1430
imagePullPolicy: Always
ports:
- containerPort: 5000
name: http
envFrom:
- configMapRef:
name: ad-management-config
- secretRef:
name: ad-management-secrets
env:
- name: REDIS_HOST
value: "redis"
- name: REDIS_PORT
value: "6379"
- name: POSTGRES_HOST
value: "postgres"
- name: POSTGRES_PORT
value: "5432"
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "300m"
livenessProbe:
httpGet:
path: /api/health
port: http
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3
readinessProbe:
httpGet:
path: /api/health
port: http
initialDelaySeconds: 5
periodSeconds: 5
timeoutSeconds: 3
failureThreshold: 1
---
apiVersion: v1
kind: Service
metadata:
name: ad-management
namespace: ad-management
spec:
selector:
app: ad-management
ports:
- port: 80
targetPort: 5000
name: http
type: ClusterIP
+26
View File
@@ -0,0 +1,26 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ad-management-ingress
namespace: ad-management
annotations:
kubernetes.io/ingress.class: "nginx"
cert-manager.io/cluster-issuer: "letsencrypt-prod"
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/proxy-body-size: "50m"
spec:
tls:
- hosts:
- ad-management.example.com
secretName: ad-management-tls
rules:
- host: ad-management.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: ad-management
port:
name: http
+13
View File
@@ -0,0 +1,13 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: ad-management
resources:
- namespace.yaml
- configmap.yaml
- secrets.yaml
- postgres.yaml
- redis.yaml
- deployment.yaml
- ingress.yaml
+6
View File
@@ -0,0 +1,6 @@
apiVersion: v1
kind: Namespace
metadata:
name: ad-management
labels:
name: ad-management
+89
View File
@@ -0,0 +1,89 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: postgres
namespace: ad-management
spec:
serviceName: postgres
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:15-alpine
ports:
- containerPort: 5432
name: postgres
env:
- name: POSTGRES_DB
valueFrom:
configMapKeyRef:
name: ad-management-config
key: POSTGRES_DB
- name: POSTGRES_USER
valueFrom:
configMapKeyRef:
name: ad-management-config
key: POSTGRES_USER
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: ad-management-secrets
key: POSTGRES_PASSWORD
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "1Gi"
cpu: "500m"
livenessProbe:
exec:
command:
- pg_isready
- -U
- postgres
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3
readinessProbe:
exec:
command:
- pg_isready
- -U
- postgres
initialDelaySeconds: 5
periodSeconds: 5
timeoutSeconds: 3
failureThreshold: 1
volumeClaimTemplates:
- metadata:
name: postgres-data
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 10Gi
---
apiVersion: v1
kind: Service
metadata:
name: postgres
namespace: ad-management
spec:
selector:
app: postgres
ports:
- port: 5432
targetPort: 5432
clusterIP: None # Headless service for StatefulSet
+71
View File
@@ -0,0 +1,71 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: redis
namespace: ad-management
spec:
serviceName: redis
replicas: 1
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
containers:
- name: redis
image: redis:7-alpine
ports:
- containerPort: 6379
name: redis
volumeMounts:
- name: redis-data
mountPath: /data
resources:
requests:
memory: "128Mi"
cpu: "50m"
limits:
memory: "256Mi"
cpu: "200m"
livenessProbe:
exec:
command:
- redis-cli
- ping
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3
readinessProbe:
exec:
command:
- redis-cli
- ping
initialDelaySeconds: 5
periodSeconds: 5
timeoutSeconds: 3
failureThreshold: 1
volumeClaimTemplates:
- metadata:
name: redis-data
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: Service
metadata:
name: redis
namespace: ad-management
spec:
selector:
app: redis
ports:
- port: 6379
targetPort: 6379
clusterIP: None # Headless service for StatefulSet
+14
View File
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Secret
metadata:
name: ad-management-secrets
namespace: ad-management
type: Opaque
data:
# These are example values. In production, replace with your own base64-encoded secrets
# Example: echo -n "your-secret-value" | base64
JWT_SECRET: Y2hhbmdlLXRoaXMtaW4tcHJvZHVjdGlvbg==
SESSION_SECRET: Y2hhbmdlLXRoaXMtaW4tcHJvZHVjdGlvbg==
DEFAULT_ADMIN_PASSWORD: cGFzc3dvcmQ=
DEFAULT_ADMIN_EMAIL: YWRtaW5AZXhhbXBsZS5jb20=
POSTGRES_PASSWORD: cG9zdGdyZXM=
@@ -0,0 +1,40 @@
# PowerShell script to update the Kubernetes deployment with the current version
# Get the directory of this script
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$parentDir = Split-Path -Parent $scriptDir
# Read the version from version.txt
$versionFile = Join-Path $parentDir "version.txt"
if (-not (Test-Path $versionFile)) {
Write-Host "Error: version.txt not found at $versionFile" -ForegroundColor Red
exit 1
}
$version = Get-Content $versionFile -Raw
$version = $version.Trim()
Write-Host "Using version: $version" -ForegroundColor Cyan
# Update the deployment.yaml file
$deploymentFile = Join-Path $scriptDir "deployment.yaml"
if (-not (Test-Path $deploymentFile)) {
Write-Host "Error: deployment.yaml not found at $deploymentFile" -ForegroundColor Red
exit 1
}
# Read the deployment file
$content = Get-Content $deploymentFile -Raw
# Replace the image version
$pattern1 = 'image: ActiveDirectoryManager:[0-9]{4}\.[0-9]{2}\.[0-9]{2}\.[0-9]{4}'
$replacement1 = "image: ActiveDirectoryManager:$version"
$content = $content -replace $pattern1, $replacement1
$pattern2 = 'image: ActiveDirectoryManager:latest'
$replacement2 = "image: ActiveDirectoryManager:$version"
$content = $content -replace $pattern2, $replacement2
# Write the updated content back to the file
$content | Set-Content $deploymentFile
Write-Host "Updated deployment.yaml with version $version" -ForegroundColor Green
@@ -0,0 +1,36 @@
#!/bin/bash
# Script to update the Kubernetes deployment with the current version
# Get the directory of this script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PARENT_DIR="$(dirname "$SCRIPT_DIR")"
# Read the version from version.txt
VERSION_FILE="$PARENT_DIR/version.txt"
if [ ! -f "$VERSION_FILE" ]; then
echo "Error: version.txt not found at $VERSION_FILE"
exit 1
fi
VERSION=$(cat "$VERSION_FILE" | tr -d '[:space:]')
echo "Using version: $VERSION"
# Update the deployment.yaml file
DEPLOYMENT_FILE="$SCRIPT_DIR/deployment.yaml"
if [ ! -f "$DEPLOYMENT_FILE" ]; then
echo "Error: deployment.yaml not found at $DEPLOYMENT_FILE"
exit 1
fi
# Use sed to replace the image version
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS requires a different sed syntax
sed -i '' "s|image: ActiveDirectoryManager:[0-9]\{4\}\.[0-9]\{2\}\.[0-9]\{2\}\.[0-9]\{4\}|image: ActiveDirectoryManager:$VERSION|g" "$DEPLOYMENT_FILE"
sed -i '' "s|image: ActiveDirectoryManager:latest|image: ActiveDirectoryManager:$VERSION|g" "$DEPLOYMENT_FILE"
else
# Linux
sed -i "s|image: ActiveDirectoryManager:[0-9]\{4\}\.[0-9]\{2\}\.[0-9]\{2\}\.[0-9]\{4\}|image: ActiveDirectoryManager:$VERSION|g" "$DEPLOYMENT_FILE"
sed -i "s|image: ActiveDirectoryManager:latest|image: ActiveDirectoryManager:$VERSION|g" "$DEPLOYMENT_FILE"
fi
echo "Updated deployment.yaml with version $VERSION"
+24
View File
@@ -0,0 +1,24 @@
# PowerShell script to update version and apply it to all components
# Get the directory of this script
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
# Update version.txt with current date/time
Write-Host "Updating version.txt..." -ForegroundColor Cyan
& "$scriptDir\update-version.ps1"
# Read the new version
$version = Get-Content "$scriptDir\version.txt" -Raw
$version = $version.Trim()
Write-Host "New version: $version" -ForegroundColor Green
# Update Kubernetes deployment
Write-Host "Updating Kubernetes deployment..." -ForegroundColor Cyan
& "$scriptDir\kubernetes\update-deployment-version.ps1"
Write-Host "Version update complete. New version: $version" -ForegroundColor Green
Write-Host ""
Write-Host "Next steps:" -ForegroundColor Yellow
Write-Host "1. Build Docker image: cd $scriptDir\docker; .\build.ps1" -ForegroundColor Yellow
Write-Host "2. Push Docker image: cd $scriptDir\docker; .\build.ps1 -push" -ForegroundColor Yellow
Write-Host "3. Deploy to Kubernetes: cd $scriptDir\kubernetes; kubectl apply -k ." -ForegroundColor Yellow
+24
View File
@@ -0,0 +1,24 @@
#!/bin/bash
# Comprehensive script to update version and apply it to all components
# Get the directory of this script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Update version.txt with current date/time
echo "Updating version.txt..."
"$SCRIPT_DIR/update-version.sh"
# Read the new version
VERSION=$(cat "$SCRIPT_DIR/version.txt" | tr -d '[:space:]')
echo "New version: $VERSION"
# Update Kubernetes deployment
echo "Updating Kubernetes deployment..."
"$SCRIPT_DIR/kubernetes/update-deployment-version.sh"
echo "Version update complete. New version: $VERSION"
echo ""
echo "Next steps:"
echo "1. Build Docker image: cd $SCRIPT_DIR/docker && ./build.sh"
echo "2. Push Docker image: cd $SCRIPT_DIR/docker && ./build.sh --push"
echo "3. Deploy to Kubernetes: cd $SCRIPT_DIR/kubernetes && kubectl apply -k ."
+10
View File
@@ -0,0 +1,10 @@
# PowerShell script to update the version.txt file with the current date and time
# Generate version in yyyy.MM.dd.HHmm format
$version = Get-Date -Format "yyyy.MM.dd.HHmm"
# Update version.txt
$versionFile = Join-Path $PSScriptRoot "version.txt"
$version | Out-File -FilePath $versionFile -NoNewline
Write-Host "Version updated to: $version"
+10
View File
@@ -0,0 +1,10 @@
#!/bin/bash
# Script to update the version.txt file with the current date and time
# Generate version in yyyy.MM.dd.HHmm format
VERSION=$(date +"%Y.%m.%d.%H%M")
# Update version.txt
echo "$VERSION" > "$(dirname "$0")/version.txt"
echo "Version updated to: $VERSION"
+1
View File
@@ -0,0 +1 @@
2025.05.21.1430