switch between arti and default

This commit is contained in:
pratik
2025-10-15 14:28:38 -05:00
parent b8cabbe0c8
commit 56dcc04ad7
13 changed files with 749 additions and 8 deletions

7
.gitignore vendored
View File

@@ -87,3 +87,10 @@ tmp/
temp/
*.tmp
.claude/settings.local.json
# Node/NPM
frontend/node_modules/
frontend/.angular/
frontend/dist/
# Keep .npmrc but ignore sensitive auth info
# The active .npmrc will be generated from .npmrc.public or .npmrc.artifactory

View File

@@ -1,13 +1,23 @@
# Multi-stage build: First stage builds Angular frontend
FROM node:18-alpine as frontend-builder
# Build argument to select npm registry (public or artifactory)
ARG NPM_REGISTRY=public
ARG ARTIFACTORY_AUTH_TOKEN=""
# Install dependencies for native modules
RUN apk add --no-cache python3 make g++
WORKDIR /frontend
# Copy package files first for better layer caching
# Copy package files and registry configs
COPY frontend/package*.json ./
COPY frontend/.npmrc.${NPM_REGISTRY} ./.npmrc
# If using artifactory and auth token is provided, configure it
RUN if [ "$NPM_REGISTRY" = "artifactory" ] && [ -n "$ARTIFACTORY_AUTH_TOKEN" ]; then \
echo "Configuring Artifactory authentication..."; \
fi
# Clean install dependencies
RUN npm ci --force

View File

@@ -269,6 +269,23 @@ Store compiled binaries, test data files, or any binary artifacts with full meta
## Development
### NPM Registry Configuration
The frontend supports working with multiple npm registries (public npm vs corporate Artifactory). See [frontend/README-REGISTRY.md](frontend/README-REGISTRY.md) for detailed instructions.
**Quick switch:**
```bash
cd frontend
# Use public npm (default)
npm run registry:public
npm ci --force
# Use Artifactory
npm run registry:artifactory
npm ci --force
```
### Running Tests
```bash
pytest tests/ -v

1
frontend/.npmrc Normal file
View File

@@ -0,0 +1 @@
registry=https://registry.npmjs.org/

View File

@@ -0,0 +1,11 @@
# Replace YOUR_ARTIFACTORY_URL with your actual Artifactory URL
registry=https://YOUR_ARTIFACTORY_URL/artifactory/api/npm/npm-virtual/
# If authentication is required, uncomment and configure:
# //YOUR_ARTIFACTORY_URL/artifactory/api/npm/npm-virtual/:_auth=${ARTIFACTORY_AUTH_TOKEN}
# //YOUR_ARTIFACTORY_URL/artifactory/api/npm/npm-virtual/:always-auth=true
# Alternative: username/password (less secure, not recommended)
# //YOUR_ARTIFACTORY_URL/artifactory/api/npm/npm-virtual/:username=${ARTIFACTORY_USERNAME}
# //YOUR_ARTIFACTORY_URL/artifactory/api/npm/npm-virtual/:_password=${ARTIFACTORY_PASSWORD}
# //YOUR_ARTIFACTORY_URL/artifactory/api/npm/npm-virtual/:email=your-email@company.com

1
frontend/.npmrc.public Normal file
View File

@@ -0,0 +1 @@
registry=https://registry.npmjs.org/

192
frontend/README-REGISTRY.md Normal file
View File

@@ -0,0 +1,192 @@
# NPM Registry Configuration
This project supports working with two different npm registries:
1. **Public registry** - registry.npmjs.org (default)
2. **Artifactory** - Your corporate Artifactory npm registry
## Quick Start
### Switching Registries Locally
**On Linux/Mac:**
```bash
cd frontend
# Use public npm registry (default)
./switch-registry.sh public
npm ci --force
# Use Artifactory registry
./switch-registry.sh artifactory
# Set auth token if required
export ARTIFACTORY_AUTH_TOKEN="your_token_here"
npm ci --force
```
**On Windows:**
```powershell
cd frontend
# Use public npm registry (default)
.\switch-registry.ps1 public
npm ci --force
# Use Artifactory registry
.\switch-registry.ps1 artifactory
# Set auth token if required
$env:ARTIFACTORY_AUTH_TOKEN = "your_token_here"
npm ci --force
```
### Building with Docker
**Using public npm registry (default):**
```bash
docker compose build app
```
**Using Artifactory registry:**
```bash
# Without authentication
docker compose build app --build-arg NPM_REGISTRY=artifactory
# With authentication
docker compose build app \
--build-arg NPM_REGISTRY=artifactory \
--build-arg ARTIFACTORY_AUTH_TOKEN="your_token_here"
```
**On Windows PowerShell:**
```powershell
# With authentication
docker compose build app `
--build-arg NPM_REGISTRY=artifactory `
--build-arg ARTIFACTORY_AUTH_TOKEN="your_token_here"
```
## Configuration Files
- **`.npmrc.public`** - Configuration for public npm registry
- **`.npmrc.artifactory`** - Configuration for Artifactory registry (edit this with your Artifactory URL)
- **`.npmrc`** - Active configuration (generated by switch-registry scripts)
## Setup Artifactory Configuration
1. Edit `frontend/.npmrc.artifactory` and replace `YOUR_ARTIFACTORY_URL` with your actual Artifactory URL:
```
registry=https://artifactory.yourcompany.com/artifactory/api/npm/npm-virtual/
```
2. If authentication is required, uncomment the auth lines and use one of these methods:
**Method 1: Auth Token (Recommended)**
```
//artifactory.yourcompany.com/artifactory/api/npm/npm-virtual/:_auth=${ARTIFACTORY_AUTH_TOKEN}
//artifactory.yourcompany.com/artifactory/api/npm/npm-virtual/:always-auth=true
```
Then set the environment variable:
```bash
export ARTIFACTORY_AUTH_TOKEN="your_base64_encoded_token"
```
**Method 2: Username/Password**
```
//artifactory.yourcompany.com/artifactory/api/npm/npm-virtual/:username=${ARTIFACTORY_USERNAME}
//artifactory.yourcompany.com/artifactory/api/npm/npm-virtual/:_password=${ARTIFACTORY_PASSWORD}
//artifactory.yourcompany.com/artifactory/api/npm/npm-virtual/:email=your-email@company.com
```
## Handling package-lock.json
The `package-lock.json` file will be different depending on which registry you use. Here are strategies to manage this:
### Strategy 1: Separate Lockfiles (Recommended)
Keep two lockfiles and switch between them:
```bash
# After switching to public and installing
npm ci --force
cp package-lock.json package-lock.public.json
# After switching to artifactory and installing
npm ci --force
cp package-lock.json package-lock.artifactory.json
# When switching registries in the future
cp package-lock.public.json package-lock.json # or
cp package-lock.artifactory.json package-lock.json
```
### Strategy 2: Regenerate Lockfile
Always regenerate the lockfile after switching:
```bash
./switch-registry.sh artifactory
rm package-lock.json
npm install
```
### Strategy 3: Git Ignore Lockfile (Not Recommended for Production)
If you're frequently switching and don't need deterministic builds:
Add to `.gitignore`:
```
frontend/package-lock.json
```
**Warning:** This reduces build reproducibility.
## Troubleshooting
### Issue: "npm ci requires package-lock.json"
**Solution:** Delete `package-lock.json` and run `npm install` to generate a new one for your current registry.
### Issue: "404 Not Found - GET https://registry.npmjs.org/..."
**Solution:** Your .npmrc is pointing to Artifactory but packages don't exist there.
```bash
./switch-registry.sh public
npm ci --force
```
### Issue: "401 Unauthorized"
**Solution:** Check your authentication configuration in `.npmrc.artifactory` and ensure environment variables are set correctly.
### Issue: "ENOENT: no such file or directory, open '.npmrc.public'"
**Solution:** You're missing the registry config files. Make sure both `.npmrc.public` and `.npmrc.artifactory` exist in the frontend directory.
## CI/CD Integration
For CI/CD pipelines, use environment variables to select the registry:
**GitHub Actions Example:**
```yaml
- name: Build with Artifactory
env:
NPM_REGISTRY: artifactory
ARTIFACTORY_AUTH_TOKEN: ${{ secrets.ARTIFACTORY_TOKEN }}
run: |
docker compose build app \
--build-arg NPM_REGISTRY=artifactory \
--build-arg ARTIFACTORY_AUTH_TOKEN="${ARTIFACTORY_AUTH_TOKEN}"
```
**GitLab CI Example:**
```yaml
build:
script:
- docker compose build app
--build-arg NPM_REGISTRY=artifactory
--build-arg ARTIFACTORY_AUTH_TOKEN="${ARTIFACTORY_AUTH_TOKEN}"
variables:
NPM_REGISTRY: artifactory
ARTIFACTORY_AUTH_TOKEN: ${CI_ARTIFACTORY_TOKEN}
```
## Best Practices
1. **Never commit credentials** - Use environment variables for tokens/passwords
2. **Document your Artifactory URL** - Update `.npmrc.artifactory` with your team's URL
3. **Keep both config files** - Commit `.npmrc.public` and `.npmrc.artifactory` to git
4. **Use the scripts** - Always use `switch-registry.sh/ps1` instead of manually editing `.npmrc`
5. **Clean installs** - Use `npm ci --force` after switching to ensure a clean dependency tree

View File

@@ -0,0 +1,339 @@
# NPM Registry - Usage Examples
## Quick Reference
### Use Public NPM (Default)
```bash
# Linux/Mac
./quickstart.sh
# Windows
.\quickstart.ps1
```
### Use Artifactory
```bash
# Linux/Mac
export ARTIFACTORY_AUTH_TOKEN="your_token_here"
./quickstart.sh -bsf
# Windows
$env:ARTIFACTORY_AUTH_TOKEN = "your_token_here"
.\quickstart.ps1 -Bsf
```
### Rebuild with Artifactory
```bash
# Linux/Mac
export ARTIFACTORY_AUTH_TOKEN="your_token_here"
./quickstart.sh --rebuild -bsf
# Windows
$env:ARTIFACTORY_AUTH_TOKEN = "your_token_here"
.\quickstart.ps1 -Rebuild -Bsf
```
## Local Development (Without Docker)
### Switch Registry for Local Development
**Linux/Mac:**
```bash
cd frontend
# Switch to public npm
./switch-registry.sh public
npm ci --force
npm start
# Switch to Artifactory
./switch-registry.sh artifactory
export ARTIFACTORY_AUTH_TOKEN="your_token"
npm ci --force
npm start
```
**Windows:**
```powershell
cd frontend
# Switch to public npm
.\switch-registry.ps1 public
npm ci --force
npm start
# Switch to Artifactory
.\switch-registry.ps1 artifactory
$env:ARTIFACTORY_AUTH_TOKEN = "your_token"
npm ci --force
npm start
```
**Using NPM Scripts (Cross-platform):**
```bash
cd frontend
# Switch to public npm
npm run registry:public
npm ci --force
npm start
# Switch to Artifactory
npm run registry:artifactory
npm ci --force
npm start
```
## Docker Build Examples
### Build Specific Service with Registry
**Public NPM:**
```bash
docker compose build app
```
**Artifactory:**
```bash
# Without auth
docker compose build app --build-arg NPM_REGISTRY=artifactory
# With auth
docker compose build app \
--build-arg NPM_REGISTRY=artifactory \
--build-arg ARTIFACTORY_AUTH_TOKEN="your_token"
```
**Windows PowerShell:**
```powershell
docker compose build app `
--build-arg NPM_REGISTRY=artifactory `
--build-arg ARTIFACTORY_AUTH_TOKEN="your_token"
```
## Common Workflows
### Corporate Network Development
When working from a corporate network that requires Artifactory:
1. **First time setup:**
```bash
# Edit .npmrc.artifactory with your Artifactory URL
nano frontend/.npmrc.artifactory
# Set auth token (get from your Artifactory admin)
export ARTIFACTORY_AUTH_TOKEN="your_base64_token"
# Start with Artifactory
./quickstart.sh -bsf
```
2. **Daily development:**
```bash
export ARTIFACTORY_AUTH_TOKEN="your_token"
./quickstart.sh -bsf
```
### Home/Public Network Development
When working from home or a network with npm access:
```bash
# Just run without -bsf flag
./quickstart.sh
```
### Switching Between Environments
**Moving from Corporate to Home:**
```bash
# Stop existing containers
docker compose down
# Rebuild with public npm
./quickstart.sh --rebuild
```
**Moving from Home to Corporate:**
```bash
# Stop existing containers
docker compose down
# Rebuild with Artifactory
export ARTIFACTORY_AUTH_TOKEN="your_token"
./quickstart.sh --rebuild -bsf
```
## Handling Multiple package-lock.json Files
### Save lockfiles for both registries:
```bash
cd frontend
# Generate public lockfile
./switch-registry.sh public
rm package-lock.json
npm install
cp package-lock.json package-lock.public.json
# Generate artifactory lockfile
./switch-registry.sh artifactory
rm package-lock.json
npm install
cp package-lock.json package-lock.artifactory.json
# Add to git
git add package-lock.public.json package-lock.artifactory.json
```
### Use the appropriate lockfile:
```bash
# When using public npm
cp package-lock.public.json package-lock.json
npm ci
# When using Artifactory
cp package-lock.artifactory.json package-lock.json
npm ci
```
## CI/CD Examples
### GitHub Actions
**.github/workflows/build.yml**
```yaml
name: Build
on: [push, pull_request]
jobs:
build-public:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build with public npm
run: |
docker compose build app
docker compose up -d
build-artifactory:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build with Artifactory
env:
ARTIFACTORY_AUTH_TOKEN: ${{ secrets.ARTIFACTORY_TOKEN }}
run: |
./quickstart.sh -bsf
```
### GitLab CI
**.gitlab-ci.yml**
```yaml
variables:
NPM_REGISTRY: "public"
build:public:
stage: build
script:
- docker compose build app
- docker compose up -d
only:
- main
build:artifactory:
stage: build
variables:
NPM_REGISTRY: "artifactory"
script:
- export ARTIFACTORY_AUTH_TOKEN="${CI_ARTIFACTORY_TOKEN}"
- ./quickstart.sh -bsf
only:
- develop
```
### Jenkins Pipeline
**Jenkinsfile**
```groovy
pipeline {
agent any
environment {
ARTIFACTORY_AUTH_TOKEN = credentials('artifactory-npm-token')
}
stages {
stage('Build with Artifactory') {
steps {
sh './quickstart.sh -bsf'
}
}
}
}
```
## Troubleshooting
### Build fails with "Cannot find .npmrc.public"
**Problem:** Registry config files are missing.
**Solution:**
```bash
cd frontend
# Verify files exist
ls -la .npmrc.*
# If missing, they should be committed to git
git status
```
### "ENOENT: no such file or directory, open '/frontend/dist/frontend/browser'"
**Problem:** Frontend build failed due to registry issues.
**Solution:**
```bash
# Check build logs
docker compose logs app | grep npm
# Try rebuilding with verbose logging
docker compose build app --no-cache --progress=plain
```
### npm ci fails with 404 errors
**Problem:** Wrong registry is configured.
**Solution:**
```bash
cd frontend
cat .npmrc # Check which registry is active
# If using wrong one, switch:
npm run registry:public # or registry:artifactory
npm ci --force
```
### Authentication fails with Artifactory
**Problem:** Token is invalid or not set.
**Solution:**
```bash
# Check token is set
echo $ARTIFACTORY_AUTH_TOKEN # Linux/Mac
echo $env:ARTIFACTORY_AUTH_TOKEN # Windows
# Get new token from Artifactory UI:
# Artifactory -> User Profile -> Generate Token
# Set the token
export ARTIFACTORY_AUTH_TOKEN="your_new_token"
```

View File

@@ -6,7 +6,9 @@
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
"test": "ng test",
"registry:public": "node -e \"require('fs').copyFileSync('.npmrc.public', '.npmrc'); console.log('✓ Switched to public npm registry');\"",
"registry:artifactory": "node -e \"require('fs').copyFileSync('.npmrc.artifactory', '.npmrc'); console.log('✓ Switched to Artifactory registry');\""
},
"private": true,
"dependencies": {

View File

@@ -0,0 +1,34 @@
[CmdletBinding()]
param(
[Parameter(Position=0)]
[ValidateSet("public", "artifactory")]
[string]$RegistryType = "public"
)
$ErrorActionPreference = "Stop"
switch ($RegistryType) {
"public" {
Write-Host "Switching to public npm registry..." -ForegroundColor Yellow
Copy-Item ".npmrc.public" ".npmrc" -Force
Write-Host "[OK] Now using registry.npmjs.org" -ForegroundColor Green
Write-Host ""
Write-Host "To install dependencies:" -ForegroundColor White
Write-Host " npm ci --force" -ForegroundColor Cyan
}
"artifactory" {
Write-Host "Switching to Artifactory registry..." -ForegroundColor Yellow
Copy-Item ".npmrc.artifactory" ".npmrc" -Force
Write-Host "[OK] Now using Artifactory registry" -ForegroundColor Green
Write-Host ""
Write-Host "Make sure to set environment variables if authentication is required:" -ForegroundColor White
Write-Host ' $env:ARTIFACTORY_AUTH_TOKEN = "your_token"' -ForegroundColor Cyan
Write-Host ""
Write-Host "To install dependencies:" -ForegroundColor White
Write-Host " npm ci --force" -ForegroundColor Cyan
}
}
Write-Host ""
Write-Host "Current .npmrc contents:" -ForegroundColor White
Get-Content ".npmrc"

View File

@@ -0,0 +1,42 @@
#!/bin/bash
# Script to switch between npm registries
# Usage: ./switch-registry.sh [public|artifactory]
set -e
REGISTRY_TYPE=${1:-public}
case $REGISTRY_TYPE in
public)
echo "Switching to public npm registry..."
cp .npmrc.public .npmrc
echo "✓ Now using registry.npmjs.org"
echo ""
echo "To install dependencies:"
echo " npm ci --force"
;;
artifactory)
echo "Switching to Artifactory registry..."
cp .npmrc.artifactory .npmrc
echo "✓ Now using Artifactory registry"
echo ""
echo "Make sure to set environment variables if authentication is required:"
echo " export ARTIFACTORY_AUTH_TOKEN=your_token"
echo ""
echo "To install dependencies:"
echo " npm ci --force"
;;
*)
echo "Usage: $0 [public|artifactory]"
echo ""
echo "Options:"
echo " public - Use registry.npmjs.org (default)"
echo " artifactory - Use Artifactory npm registry"
exit 1
;;
esac
echo ""
echo "Current .npmrc contents:"
cat .npmrc

View File

@@ -1,6 +1,7 @@
[CmdletBinding()]
param(
[switch]$Rebuild,
[switch]$Bsf,
[switch]$Help
)
@@ -15,8 +16,12 @@ if ($Help) {
Write-Host ""
Write-Host "Options:" -ForegroundColor Yellow
Write-Host " -Rebuild Force rebuild of all containers" -ForegroundColor White
Write-Host " -Bsf Use Artifactory npm registry instead of public npm" -ForegroundColor White
Write-Host " -Help Show this help message" -ForegroundColor White
Write-Host ""
Write-Host "Environment Variables (when using -Bsf):" -ForegroundColor Yellow
Write-Host ' $env:ARTIFACTORY_AUTH_TOKEN Authentication token for Artifactory' -ForegroundColor White
Write-Host ""
Write-Host "Brings up the complete stack: database, backend API, and frontend" -ForegroundColor Green
Write-Host ""
exit 0
@@ -27,6 +32,29 @@ Write-Host "Obsidian - Quick Start" -ForegroundColor Cyan
Write-Host "=========================================" -ForegroundColor Cyan
Write-Host ""
# Determine npm registry and build arguments
$NpmRegistry = "public"
$BuildArgs = @()
if ($Bsf) {
$NpmRegistry = "artifactory"
$BuildArgs += "--build-arg"
$BuildArgs += "NPM_REGISTRY=artifactory"
Write-Host "Using Artifactory npm registry" -ForegroundColor Yellow
if ($env:ARTIFACTORY_AUTH_TOKEN) {
Write-Host "[OK] Artifactory auth token detected" -ForegroundColor Green
$BuildArgs += "--build-arg"
$BuildArgs += "ARTIFACTORY_AUTH_TOKEN=$env:ARTIFACTORY_AUTH_TOKEN"
} else {
Write-Host "[WARNING] ARTIFACTORY_AUTH_TOKEN not set (may be required for authentication)" -ForegroundColor Yellow
}
} else {
Write-Host "Using public npm registry (registry.npmjs.org)" -ForegroundColor Green
}
Write-Host ""
# Check if Docker is installed
if (-not (Get-Command "docker" -ErrorAction SilentlyContinue)) {
Write-Host "Error: Docker is not installed. Please install Docker Desktop first." -ForegroundColor Red
@@ -73,20 +101,40 @@ if ($Rebuild) {
Write-Host "Removing existing images for rebuild..." -ForegroundColor White
& docker compose down --rmi local
Write-Host "Building and starting all services..." -ForegroundColor White
& docker compose up -d --build
if ($BuildArgs.Count -gt 0) {
& docker compose build $BuildArgs
& docker compose up -d
} else {
& docker compose up -d --build
}
} else {
& docker-compose down
Write-Host "Removing existing images for rebuild..." -ForegroundColor White
& docker-compose down --rmi local
Write-Host "Building and starting all services..." -ForegroundColor White
& docker-compose up -d --build
if ($BuildArgs.Count -gt 0) {
& docker-compose build $BuildArgs
& docker-compose up -d
} else {
& docker-compose up -d --build
}
}
} else {
Write-Host "Starting all services..." -ForegroundColor Green
if ($ComposeCmd -eq "docker compose") {
& docker compose up -d
if ($BuildArgs.Count -gt 0) {
& docker compose build $BuildArgs
& docker compose up -d
} else {
& docker compose up -d
}
} else {
& docker-compose up -d
if ($BuildArgs.Count -gt 0) {
& docker-compose build $BuildArgs
& docker-compose up -d
} else {
& docker-compose up -d
}
}
}

View File

@@ -26,6 +26,9 @@ fi
# Parse command line arguments
REBUILD=false
USE_ARTIFACTORY=false
NPM_REGISTRY="public"
BUILD_ARGS=""
while [[ $# -gt 0 ]]; do
case $1 in
@@ -33,13 +36,23 @@ while [[ $# -gt 0 ]]; do
REBUILD=true
shift
;;
-bsf)
USE_ARTIFACTORY=true
NPM_REGISTRY="artifactory"
BUILD_ARGS="--build-arg NPM_REGISTRY=artifactory"
shift
;;
--help)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --rebuild Force rebuild of all containers"
echo " -bsf Use Artifactory npm registry instead of public npm"
echo " --help Show this help message"
echo ""
echo "Environment Variables (when using -bsf):"
echo " ARTIFACTORY_AUTH_TOKEN Authentication token for Artifactory"
echo ""
echo "Brings up the complete stack: database, backend API, and frontend"
echo ""
exit 0
@@ -52,6 +65,20 @@ while [[ $# -gt 0 ]]; do
esac
done
# If using Artifactory, add auth token to build args if available
if [ "$USE_ARTIFACTORY" = true ]; then
echo "Using Artifactory npm registry"
if [ -n "$ARTIFACTORY_AUTH_TOKEN" ]; then
echo "✓ Artifactory auth token detected"
BUILD_ARGS="$BUILD_ARGS --build-arg ARTIFACTORY_AUTH_TOKEN=$ARTIFACTORY_AUTH_TOKEN"
else
echo "⚠ Warning: ARTIFACTORY_AUTH_TOKEN not set (may be required for authentication)"
fi
else
echo "Using public npm registry (registry.npmjs.org)"
fi
echo ""
# Create .env file if it doesn't exist
if [ ! -f .env ]; then
echo "Creating .env file from .env.example..."
@@ -71,10 +98,20 @@ if [ "$REBUILD" = true ]; then
echo "Removing existing images for rebuild..."
$COMPOSE_CMD down --rmi local 2>/dev/null || true
echo "Building and starting all services..."
$COMPOSE_CMD up -d --build
if [ -n "$BUILD_ARGS" ]; then
$COMPOSE_CMD build $BUILD_ARGS
$COMPOSE_CMD up -d
else
$COMPOSE_CMD up -d --build
fi
else
echo "Starting all services..."
$COMPOSE_CMD up -d
if [ -n "$BUILD_ARGS" ]; then
$COMPOSE_CMD build $BUILD_ARGS
$COMPOSE_CMD up -d
else
$COMPOSE_CMD up -d
fi
fi
echo ""