Skip to main content

Startup Scripts

The /home/schwab-scripts directory contains essential scripts for setting up and managing the development container environment. These scripts handle the initial configuration, authentication, and repository setup required for the NextJS Web Monorepo development workflow.

Directory Structure

/home/schwab-scripts/
├── setup-container.sh # Main container setup orchestrator
├── setup-env-git.sh # Git environment configuration
├── setup-env-pnpm.sh # PNPM and registry configuration
├── setup-pull-repos.sh # Repository cloning and dependency installation
├── start-container.sh # Container startup initialization
├── kill.sh # Port cleanup utility
└── git-hooks/
├── pre-commit.hook # Pre-commit validation
└── pre-push.hook # Pre-push quality gates

Script Overview

setup-container.sh

Purpose: Main orchestrator script that initializes the entire container environment.

Functionality:

  • Executes git environment setup
  • Configures PNPM environment
  • Uses environment variables when available
#!/bin/bash
set -e
cd /home/schwab-scripts/
./setup-env-git.sh useVars
./setup-env-pnpm.sh useVars

Usage:

  • Automatically called during container initialization
  • Can be run manually for environment reset

setup-env-git.sh

Purpose: Configures Git environment for Schwab development standards.

Key Features:

  • Interactive username and email configuration
  • GitHub token setup for authentication
  • SSL certificate configuration for corporate environment
  • Repository URL configuration with authentication

Configuration Applied:

git config --global --add safe.directory /home
git config --global http.sslverify false
git config --global http.sslCAinfo /etc/ssl/certs/ZscalerRootCA.pem
git config --global user.name $username
git config --global http.postBuffer 524288000
git config --global user.email "$email"
git config --global core.compression 0
git config --global remote.origin.proxy ""
git config --global https.proxy ""

Security Features:

  • URL encoding for special characters in credentials
  • Safe directory configuration
  • Corporate SSL certificate integration

setup-env-pnpm.sh

Purpose: Configures PNPM package manager for Schwab's internal registries and proxy settings.

Key Configurations:

Registry Setup

  • Primary Registry: https://mavenrepo.schwab.com/nexus/content/groups/npm-all/
  • Schwab Packages: @schwab:registryhttps://sol.schwab.com/npm/npm-feed/
  • Charles Schwab Packages: @charlesschwab:registryhttps://sol.schwab.com/npm/npm-github-feed/
  • Vercel Private: @vercel-private:registryhttps://vercel-private-registry.vercel.sh/registry

Proxy Configuration

  • ZScaler: http://host.docker.internal:9000
  • BlueCoast: http://username:password@proxy.schwab.com:8080

Security Settings

  • SSL verification disabled for corporate environment
  • Corporate CA certificate configuration
  • Authentication token setup for private registries
  • Extended timeout configurations for corporate network

setup-pull-repos.sh

Purpose: Clones the NextJS Web repository and installs dependencies.

Key Features:

  • Configurable branch and depth cloning
  • Automatic Git hooks installation
  • PNPM dependency installation
  • GitHub authentication handling

Git Hooks Installation:

  • Copies pre-commit.hook and pre-push.hook to repository
  • Sets executable permissions
  • Ensures quality gates are enforced

start-container.sh

Purpose: Container startup initialization script.

Functionality:

  • Displays startup confirmation
  • Sources bash aliases
  • Prepares development environment

kill.sh

Purpose: Utility script for cleaning up port processes.

Usage:

./kill.sh 3000 3001 8080  # Kills processes on specified ports

Functionality:

  • Uses fuser to terminate processes on specified TCP ports
  • Useful for cleaning up hung development servers

Git Hooks

pre-commit.hook

Purpose: Validates branch naming conventions before commits.

Validation Rules:

  • Branch names must follow pattern: (feature|bugfix|release|hotfix|[a-zA-Z0-9]*)?(\W)?([A-Z]{2,}-\d+){1}(?:.*)
  • Examples of valid branch names:
    • feature/CMS-75499-upgrade-docusaurus
    • bugfix/API-12345-fix-authentication
    • hotfix/SEC-98765-security-patch

Error Handling:

  • Prevents commits on invalid branch names
  • Provides clear error messaging

pre-push.hook

Purpose: Comprehensive quality gate validation before pushing code.

Quality Checks Performed (in sequence):

  1. Linting (pnpm lint)
  2. Type Checking (pnpm type-check)
  3. Conformance (pnpm conformance)
  4. Unit Tests (pnpm test:fast)
  5. Build Validation (pnpm build)

Features:

  • Sequential execution with early termination on failure
  • Visual status indicators (✅ success, 🚨 failure)
  • Descriptive error messages
  • Prevents pushing broken code to remote repositories

Environment Variables

The scripts support environment variable configuration for automated setup:

VariablePurposeUsed By
usernameDeveloper usernameAll setup scripts
passwordDeveloper passwordPNPM setup
emailDeveloper emailGit setup
gh_tokenGitHub access tokenGit and repo setup
proxyconfigProxy configuration choicePNPM setup
pull_nextjsEnable/disable repo cloningRepo setup
default_branch_nextjswebDefault branch to cloneRepo setup
default_depth_nextjswebGit clone depthRepo setup

Security Considerations

Authentication

  • GitHub tokens are used for repository access
  • Base64 encoding for internal registry authentication
  • URL encoding for special characters in credentials

Network Security

  • Corporate SSL certificate integration
  • Proxy configuration for corporate networks
  • Registry authentication for internal packages

Access Control

  • Safe directory configuration prevents Git security warnings
  • Executable permissions properly set on hooks
  • Environment variable validation

Usage Patterns

Initial Container Setup

# Automatic during container creation
/home/schwab-scripts/setup-container.sh

Manual Environment Reset

cd /home/schwab-scripts
./setup-env-git.sh
./setup-env-pnpm.sh

Repository Refresh

./setup-pull-repos.sh

Port Cleanup

./kill.sh 3000 3001 4000  # Clean up development server ports

Integration with Development Workflow

The startup scripts integrate seamlessly with the development workflow:

  1. Container Initialization: setup-container.sh runs automatically
  2. Repository Setup: Code is cloned and dependencies installed
  3. Quality Gates: Git hooks enforce code quality standards
  4. Development: Scripts provide utilities for ongoing development

Troubleshooting

Common Issues

Authentication Failures

  • Verify GitHub token has appropriate permissions
  • Check username format (periods converted to hyphens for GitHub)
  • Ensure password encoding handles special characters

Network Issues

  • Verify proxy configuration matches corporate network
  • Check SSL certificate installation
  • Validate registry URLs are accessible

Git Configuration Issues

  • Ensure safe directory configuration
  • Verify SSL settings for corporate environment
  • Check remote URL formatting with authentication

PNPM Issues

  • Verify registry configurations
  • Check authentication tokens
  • Validate proxy settings

Debugging Commands

# Check Git configuration
git config --list --global

# Verify PNPM configuration
pnpm config list

# Test registry access
pnpm ping

# Check network connectivity
curl -I https://mavenrepo.schwab.com/nexus/content/groups/npm-all/

# Validate GitHub access
git ls-remote origin

Best Practices

Script Maintenance

  • Keep authentication tokens secure and rotated
  • Regularly update SSL certificates
  • Validate registry URLs and endpoints
  • Test scripts in clean environments

Development Workflow

  • Always run quality checks before pushing
  • Use appropriate branch naming conventions
  • Keep dependencies up to date
  • Monitor for security vulnerabilities

Container Management

  • Regularly rebuild containers with updated scripts
  • Document any custom modifications
  • Test startup scripts with various network configurations
  • Maintain backup authentication methods

This documentation provides a comprehensive guide to the startup scripts that enable efficient development within the Schwab containerized environment, ensuring consistent setup and maintaining code quality standards across the development team.