Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
2f3c452
feat: Add Istio sidecar resource annotations for cart, products, sear…
naveenkumarkumanan Jul 12, 2025
8508966
feat: Refactor DevSpace configurations for cart, products, search, st…
naveenkumarkumanan Jul 13, 2025
dd42905
feat: Add Istio Gateway and VirtualService configurations for store-ui
naveenkumarkumanan Jul 13, 2025
9a8c983
feat: Add VirtualService configurations for cart, products, search, a…
naveenkumarkumanan Jul 13, 2025
f6b0ec7
Refactor Kubernetes manifest paths to use K8S_DIR variable for consis…
naveenkumarkumanan Jul 13, 2025
e0dd71f
Improved UX
naveenkumarkumanan Jul 14, 2025
2ae9efe
feat: Enhance authentication pages with social login options and impr…
naveenkumarkumanan Jul 14, 2025
b4e98a4
feat: Enhance Cart page with recommended products section and improve…
naveenkumarkumanan Jul 14, 2025
568bdad
feat: Implement user address management in Checkout; add address sele…
naveenkumarkumanan Jul 14, 2025
7f3b0ee
feat: Add scripts for building, pushing images, and managing Kind clu…
naveenkumarkumanan Jul 16, 2025
c73f40e
chore: remove obsolete Kind cluster configuration and setup scripts
naveenkumarkumanan Jul 16, 2025
c24edec
feat: update service imports to use devpilot scripts for all microser…
naveenkumarkumanan Jul 16, 2025
447d6c6
feat: update scripts for Docker registry setup and improve server man…
naveenkumarkumanan Jul 20, 2025
ad1090f
fix: correct script directory paths in install-cluster.sh
naveenkumarkumanan Jul 20, 2025
b12efd4
Merge remote-tracking branch 'origin/master'
naveenkumarkumanan Jul 20, 2025
5f13ea4
feat: update test scripts and add API tests
naveenkumarkumanan Jul 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .devpilot-scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.devpilot-logs
.devpilot-backups
14 changes: 14 additions & 0 deletions .devpilot-scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# e-commerce-microservices-sample DevPilot Scripts

This directory contains automation scripts managed by DevPilot.

## Available Commands

- `devpilot setup-env`: Setup the development environment
- `devpilot start-env`: Start the development environment
- `devpilot stop-env`: Stop the development environment
- `devpilot delete-env`: Delete the development environment
- `devpilot run-server`: Run the development server
- `devpilot build-server`: Build the server
- `devpilot deploy-server`: Deploy the server
- `devpilot test-server`: Run tests
3 changes: 3 additions & 0 deletions .devpilot-scripts/build-and-push-images.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# PowerShell script to build and push images
Write-Host "Building and pushing images..."
# Add your image build and push commands here
184 changes: 184 additions & 0 deletions .devpilot-scripts/build-and-push-images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
#!/bin/bash
# Helper Functions
function write_phase() {
echo -e "\n🚀 $1"
}

function write_step() {
echo -e "\n📋 $1"
}

function write_progress() {
echo -e " $1"
}

function write_success() {
echo -e "✅ $1"
}

function write_warning() {
echo -e "⚠️ $1"
}

function write_error() {
echo -e "❌ $1"
}

# Configuration - Can be overridden by environment variables
registry_url=${REGISTRY_URL:-"image.registry.local:5001"}

# Get the script directory and project directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"

# Load service locations from devpilot.json
DEVPILOT_CONFIG="$PROJECT_DIR/.devpilot.json"
if [ ! -f "$DEVPILOT_CONFIG" ]; then
write_error "DevPilot configuration file not found at $DEVPILOT_CONFIG"
write_error "Please run 'devpilot init' first to configure your project"
exit 1
fi

write_phase "Loading service configuration from DevPilot config"
# Use jq if available, otherwise use grep and sed as fallback
if command -v jq &> /dev/null; then
write_progress "Using jq to parse configuration"
# Try to extract services from the devpilot.json using jq
SERVICES_JSON=$(jq -c '.services[]' "$DEVPILOT_CONFIG" 2>/dev/null)

if [ -z "$SERVICES_JSON" ]; then
write_warning "No services found in DevPilot config or jq command failed"
write_warning "Falling back to default service detection"
# Default fallback
declare -a services=(
"cart:$PROJECT_DIR/cart-cna-microservice:latest"
"products:$PROJECT_DIR/products-cna-microservice:latest"
"search:$PROJECT_DIR/search-cna-microservice:latest"
"store-ui:$PROJECT_DIR/store-ui:latest"
"users:$PROJECT_DIR/users-cna-microservice:latest"
)
else
# Parse JSON into services array
declare -a services=()
while IFS= read -r service_obj; do
service_name=$(echo "$service_obj" | jq -r '.name')
service_location=$(echo "$service_obj" | jq -r '.location')
# Make relative paths absolute
if [[ "$service_location" != /* ]]; then
service_location="$PROJECT_DIR/$service_location"
fi
services+=("$service_name:$service_location:latest")
write_progress "Detected service: $service_name at $service_location"
done <<< "$SERVICES_JSON"
fi
else
write_warning "jq not found, using fallback method to parse configuration"
# Fallback method using grep and sed if jq is not available
services_section=$(grep -A 100 '"services":' "$DEVPILOT_CONFIG" | grep -B 100 -m 1 '^\s*\]' || grep -A 100 '"services":' "$DEVPILOT_CONFIG")

declare -a services=()
while IFS= read -r line; do
if [[ "$line" =~ \"name\":\ *\"([^\"]+)\" ]]; then
service_name="${BASH_REMATCH[1]}"
# Try to get the location from the next few lines
location_line=$(grep -A 5 "\"name\": \"$service_name\"" "$DEVPILOT_CONFIG" | grep "\"location\"")
if [[ "$location_line" =~ \"location\":\ *\"([^\"]+)\" ]]; then
service_location="${BASH_REMATCH[1]}"
# Make relative paths absolute
if [[ "$service_location" != /* ]]; then
service_location="$PROJECT_DIR/$service_location"
fi
services+=("$service_name:$service_location:latest")
write_progress "Detected service: $service_name at $service_location"
fi
fi
done <<< "$services_section"

# If no services detected, use default fallback
if [ ${#services[@]} -eq 0 ]; then
write_warning "No services detected in DevPilot config, using default service detection"
declare -a services=(
"cart:$PROJECT_DIR/cart-cna-microservice:latest"
"products:$PROJECT_DIR/products-cna-microservice:latest"
"search:$PROJECT_DIR/search-cna-microservice:latest"
"store-ui:$PROJECT_DIR/store-ui:latest"
"users:$PROJECT_DIR/users-cna-microservice:latest"
)
fi
fi

# Check if registry is running
write_phase "Checking Local Registry"
# Check for either the old kind-registry or the new dev-harbor container
registry_container=$(docker ps --filter "name=kind-registry" --format "{{.Names}}")
harbor_container=$(docker ps --filter "name=dev-harbor" --format "{{.Names}}")

if [[ -z "$registry_container" && -z "$harbor_container" ]]; then
write_warning "Local registry is not running! Please run setup-kind.sh first."
exit 1
fi

if [[ -n "$harbor_container" ]]; then
write_success "Harbor registry is running at $registry_url"
else
write_success "Local registry is running at $registry_url"
fi

# Process each service
for service_info in "${services[@]}"; do
# Parse service information
IFS=: read -r name path tag <<< "$service_info"

write_phase "Processing $name Service"

# Check if directory exists
if [ ! -d "$path" ]; then
write_warning "Directory $path does not exist. Skipping $name service."
continue
fi

# Check if Dockerfile exists
if [ ! -f "$path/Dockerfile" ]; then
write_warning "Dockerfile not found in $path. Skipping $name service."
continue
fi

# Build the image
write_step "Building image for $name..."
write_progress "Running docker build in $path"

pushd "$path" 2>/dev/null
if [ $? -ne 0 ]; then
write_error "Failed to change directory to $path"
continue
fi

if docker build -t "$name:$tag" .; then
write_success "Built $name:$tag"

# Tag the image for local registry
write_step "Tagging image for local registry..."
registry_image="$registry_url/$name:$tag"
docker tag "$name:$tag" "$registry_image"
write_success "Tagged as $registry_image"

# Push to local registry
write_step "Pushing to local registry..."
if docker push "$registry_image"; then
write_success "Successfully pushed $registry_image"
else
write_warning "Failed to push $name: Docker push failed"
fi
else
write_warning "Failed to build $name: Docker build failed"
fi

# Return to original directory
popd 2>/dev/null
done

write_phase "Build and Push Summary"
write_success "All services have been processed"
echo -e "\nNext steps:"
echo "1. You can verify images in the registry using: docker images"
echo "2. To see pushed images: curl http://$registry_url/v2/_catalog"
183 changes: 183 additions & 0 deletions .devpilot-scripts/devspace-pipelines.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
version: v2beta1
name: common-scripts

vars:
REGISTRY:
default: "image.registry.local:5001"
AZURE_REGISTRY:
default: "kubecondemo.azurecr.io"
IMAGE_TAG:
default: "latest"
# Use sanitized username as default namespace
NAMESPACE:
command: "echo $USER | tr '.' '-'"
# Base directory for Kubernetes manifests
K8S_DIR:
default: ".."

# Generic images template - will be inherited by services
images:
app:
image: ${REGISTRY}/${SERVICE_NAME}
dockerfile: ./Dockerfile
tags:
- ${IMAGE_TAG}

# Define reusable pipelines to reduce duplication
pipelines:
# Common pipeline to prepare manifests with namespace replacement
prepare-manifests:
run: |
# Create a temporary directory for the customized yaml
TEMP_DIR=$(mktemp -d)
echo "Creating temporary files in $TEMP_DIR"
echo "export TEMP_DIR=$TEMP_DIR" > ~/.devspace/vars/temp_dir.env

# Get the base directory
source ~/.devspace/vars/env_type.env
source ~/.devspace/vars/k8s_path.env
MANIFEST_PATH="${K8S_PATH}"
SERVICE_DIR=$(basename "${MANIFEST_PATH}")
BASE_DIR=$(dirname "${MANIFEST_PATH}")
BASE_DIR=$(dirname "$BASE_DIR")
BASE_DIR=$(dirname "$BASE_DIR")

# Copy the necessary files to the temp directory
mkdir -p $TEMP_DIR/base $TEMP_DIR/overlays/$ENV_TYPE
cp -r ${BASE_DIR}/base/* $TEMP_DIR/base/
cp -r ${BASE_DIR}/overlays/$ENV_TYPE/* $TEMP_DIR/overlays/$ENV_TYPE/

# Save paths for later steps
echo "export SERVICE_DIR=$SERVICE_DIR" >> ~/.devspace/vars/temp_dir.env
echo "export BASE_DIR=$BASE_DIR" >> ~/.devspace/vars/temp_dir.env

# Replace in all yaml files
find $TEMP_DIR -type f -name "*.yaml" -exec sed -i "s/NAMESPACE_PLACEHOLDER/${NAMESPACE}/g" {} \;

# Create the namespace if it doesn't exist
kubectl create namespace ${NAMESPACE} --dry-run=client -o yaml | kubectl apply -f -

echo "Prepared Kubernetes manifests in $TEMP_DIR with namespace: ${NAMESPACE}"

# Apply the prepared manifests
apply-manifests:
run: |
source ~/.devspace/vars/temp_dir.env
source ~/.devspace/vars/env_type.env
kubectl apply -k $TEMP_DIR/overlays/$ENV_TYPE/$SERVICE_DIR

# Handle Istio Gateway for Azure environment
if [[ "$ENV_TYPE" == "azure" ]]; then
# Check if the Istio Gateway exists in the aks-istio-ingress namespace
GATEWAY_EXISTS=$(kubectl get gateway -n aks-istio-ingress store-ui-gateway -o name --ignore-not-found)

if [ -z "$GATEWAY_EXISTS" ]; then
echo "Creating Istio Gateway in aks-istio-ingress namespace"
# Apply the Gateway configuration separately since it's in a different namespace
GATEWAY_FILE="${BASE_DIR}/overlays/azure/store-ui/store-ui-gateway.yaml"
if [ -f "$GATEWAY_FILE" ]; then
kubectl apply -f "$GATEWAY_FILE"
fi
else
echo "Istio Gateway already exists in aks-istio-ingress namespace"
fi
fi

# Delete the prepared manifests
delete-manifests:
run: |
source ~/.devspace/vars/temp_dir.env
source ~/.devspace/vars/env_type.env
kubectl delete -k $TEMP_DIR/overlays/$ENV_TYPE/$SERVICE_DIR --ignore-not-found

# Clean up the temporary directory
cleanup:
run: |
source ~/.devspace/vars/temp_dir.env
rm -rf $TEMP_DIR
echo "Cleaned up temporary directory"

# Standardized commands for consistency across all microservices
commands:
# Development commands
dev:
command: devspace use namespace ${NAMESPACE} && devspace dev --skip-build --skip-deploy
description: "Start development mode with hot reload"

# Core deployment commands
deploy:
command: |
mkdir -p ~/.devspace/vars
# Set environment variables for pipelines
echo "export ENV_TYPE=local" > ~/.devspace/vars/env_type.env
echo "export K8S_PATH=${K8S_MANIFEST_PATH_LOCAL}" > ~/.devspace/vars/k8s_path.env

# Run pipelines
devspace run-pipeline prepare-manifests
devspace run-pipeline apply-manifests
devspace run-pipeline cleanup
description: "Deploy to local environment with dynamic namespace"

build:
command: devspace build
description: "Build image for local registry"

purge:
command: |
mkdir -p ~/.devspace/vars
# Set environment variables for pipelines
echo "export ENV_TYPE=local" > ~/.devspace/vars/env_type.env
echo "export K8S_PATH=${K8S_MANIFEST_PATH_LOCAL}" > ~/.devspace/vars/k8s_path.env

# Run pipelines
devspace run-pipeline prepare-manifests
devspace run-pipeline delete-manifests
devspace run-pipeline cleanup
description: "Remove deployment from cluster"

# Azure profile commands
deploy-azure:
command: |
mkdir -p ~/.devspace/vars
# Set environment variables for pipelines
echo "export ENV_TYPE=azure" > ~/.devspace/vars/env_type.env
echo "export K8S_PATH=${K8S_MANIFEST_PATH_AZURE}" > ~/.devspace/vars/k8s_path.env

# Run pipelines
devspace run-pipeline prepare-manifests
devspace run-pipeline apply-manifests
devspace run-pipeline cleanup
description: "Deploy to Azure with dynamic namespace"

build-azure:
command: devspace build --profile azure
description: "Build image for Azure ACR"

dev-azure:
command: devspace use namespace ${NAMESPACE} && devspace dev --skip-build --skip-deploy --profile azure
description: "Start development mode with Azure profile"

purge-azure:
command: |
mkdir -p ~/.devspace/vars
# Set environment variables for pipelines
echo "export ENV_TYPE=azure" > ~/.devspace/vars/env_type.env
echo "export K8S_PATH=${K8S_MANIFEST_PATH_AZURE}" > ~/.devspace/vars/k8s_path.env

# Run pipelines
devspace run-pipeline prepare-manifests
devspace run-pipeline delete-manifests
devspace run-pipeline cleanup
description: "Remove Azure deployment from cluster"

# Azure ACR profile for Kubernetes
profiles:
- name: azure
description: "Azure ACR for Kubernetes deployment"
patches:
- op: replace
path: vars.REGISTRY
value: ${AZURE_REGISTRY}
activation:
- vars:
DEVSPACE_PROFILE: "azure"
Loading