Loading ci_cd_test/run_full_capif_sdk.sh 0 → 100755 +139 −0 Original line number Diff line number Diff line #!/bin/bash set -e # === CONFIGURATION === CAPIF_REPO_URL="https://labs.etsi.org/rep/ocf/capif.git" CAPIF_DIR="/tmp/capif" NETWORK_NAME="capif-network" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SDK_SCRIPT="$SCRIPT_DIR/test_sdk.sh" LOG_FILE="/tmp/capif_setup.log" echo "🚀 [1/5] Preparing temporary environment for CAPIF at $CAPIF_DIR..." rm -rf "$CAPIF_DIR" git clone "$CAPIF_REPO_URL" "$CAPIF_DIR" > "$LOG_FILE" 2>&1 cd "$CAPIF_DIR/services" echo "🧱 [2/5] Launching CAPIF with ./run.sh (this may take several minutes)..." ./run.sh > "$LOG_FILE" 2>&1 & # === Wait until all services are up === echo "⏳ [3/5] Waiting for all CAPIF services to be running..." # Expected CAPIF containers (names as shown in docker ps) EXPECTED_CONTAINERS=( services-mock-server-1 services-register-1 services-mongo_register_express-1 services-mongo_register-1 services-api-provider-management-1 services-api-invoker-management-1 services-capif-security-1 helper services-access-control-policy-1 services-nginx-1 services-celery_worker-1 services-api-invocation-logs-1 services-service-apis-1 services-mongo-express-1 services-capif-events-1 services-published-apis-1 services-logs-1 services-celery_beat-1 services-mongo-1 services-redis-1 services-capif-routing-info-1 services-vault-1 ) TIMEOUT=1200 # 20 minutes INTERVAL=15 ELAPSED=0 while true; do # Get list of containers with status "Up" RUNNING_CONTAINERS=$(docker ps --format "{{.Names}}" | sort) # Find missing containers MISSING_CONTAINERS=() for c in "${EXPECTED_CONTAINERS[@]}"; do if ! echo "$RUNNING_CONTAINERS" | grep -q "^${c}$"; then MISSING_CONTAINERS+=("$c") fi done if [ ${#MISSING_CONTAINERS[@]} -eq 0 ]; then echo "✅ All CAPIF services are running." break else ELAPSED=$((ELAPSED + INTERVAL)) if [ "$ELAPSED" -ge "$TIMEOUT" ]; then echo "❌ Some services did not start after $TIMEOUT seconds:" printf ' - %s\n' "${MISSING_CONTAINERS[@]}" docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}' exit 1 fi echo " ... waiting for all services to become active ($ELAPSED s)" echo " Missing: ${MISSING_CONTAINERS[*]}" sleep $INTERVAL fi done # === Visual check (optional) === echo "" docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | grep capif || true # === Install jq === echo "📦 Installing jq..." apt-get update && apt-get install -y jq echo $? # === Create CAPIF user once the system is up === echo "" echo "👤 [3.1] Authenticating against CAPIF Register to create user..." # Login to Register service (Basic Auth admin:password123) LOGIN_RESPONSE=$(curl -sk --location --request POST "https://localhost:8084/login" \ --header "Authorization: Basic $(echo -n 'admin:password123' | base64)") # Extract access_token from the JSON response ACCESS_TOKEN=$(echo "$LOGIN_RESPONSE" | jq -r '.access_token') if [ -z "$ACCESS_TOKEN" ]; then echo "❌ Failed to obtain access_token from login response:" echo "$LOGIN_RESPONSE" exit 1 fi echo "✅ Login successful. Access token retrieved." # Create user with the obtained token echo "" echo "👤 [3.2] Creating user custom_user in CAPIF..." CREATE_RESPONSE=$(curl -sk --location "https://localhost:8084/createUser" \ --header "Content-Type: application/json" \ --header "Authorization: Bearer $ACCESS_TOKEN" \ --data-raw '{ "username": "custom_user", "password": "user_pass", "enterprise": "ETSI", "country": "Spain", "email": "example@gmail.com", "purpose": "Use OpenCAPIF", "phone_number": "+123456789", "company_web": "www.etsi.com", "description": "UserDescription" }') echo "$CREATE_RESPONSE" # === Run SDK === echo "" echo "🚀 [4/5] Running SDK (test_sdk.sh)..." bash "$SDK_SCRIPT" # === Final Result === echo "🏁 [5/5] SDK completed successfully." Loading
ci_cd_test/run_full_capif_sdk.sh 0 → 100755 +139 −0 Original line number Diff line number Diff line #!/bin/bash set -e # === CONFIGURATION === CAPIF_REPO_URL="https://labs.etsi.org/rep/ocf/capif.git" CAPIF_DIR="/tmp/capif" NETWORK_NAME="capif-network" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SDK_SCRIPT="$SCRIPT_DIR/test_sdk.sh" LOG_FILE="/tmp/capif_setup.log" echo "🚀 [1/5] Preparing temporary environment for CAPIF at $CAPIF_DIR..." rm -rf "$CAPIF_DIR" git clone "$CAPIF_REPO_URL" "$CAPIF_DIR" > "$LOG_FILE" 2>&1 cd "$CAPIF_DIR/services" echo "🧱 [2/5] Launching CAPIF with ./run.sh (this may take several minutes)..." ./run.sh > "$LOG_FILE" 2>&1 & # === Wait until all services are up === echo "⏳ [3/5] Waiting for all CAPIF services to be running..." # Expected CAPIF containers (names as shown in docker ps) EXPECTED_CONTAINERS=( services-mock-server-1 services-register-1 services-mongo_register_express-1 services-mongo_register-1 services-api-provider-management-1 services-api-invoker-management-1 services-capif-security-1 helper services-access-control-policy-1 services-nginx-1 services-celery_worker-1 services-api-invocation-logs-1 services-service-apis-1 services-mongo-express-1 services-capif-events-1 services-published-apis-1 services-logs-1 services-celery_beat-1 services-mongo-1 services-redis-1 services-capif-routing-info-1 services-vault-1 ) TIMEOUT=1200 # 20 minutes INTERVAL=15 ELAPSED=0 while true; do # Get list of containers with status "Up" RUNNING_CONTAINERS=$(docker ps --format "{{.Names}}" | sort) # Find missing containers MISSING_CONTAINERS=() for c in "${EXPECTED_CONTAINERS[@]}"; do if ! echo "$RUNNING_CONTAINERS" | grep -q "^${c}$"; then MISSING_CONTAINERS+=("$c") fi done if [ ${#MISSING_CONTAINERS[@]} -eq 0 ]; then echo "✅ All CAPIF services are running." break else ELAPSED=$((ELAPSED + INTERVAL)) if [ "$ELAPSED" -ge "$TIMEOUT" ]; then echo "❌ Some services did not start after $TIMEOUT seconds:" printf ' - %s\n' "${MISSING_CONTAINERS[@]}" docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}' exit 1 fi echo " ... waiting for all services to become active ($ELAPSED s)" echo " Missing: ${MISSING_CONTAINERS[*]}" sleep $INTERVAL fi done # === Visual check (optional) === echo "" docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | grep capif || true # === Install jq === echo "📦 Installing jq..." apt-get update && apt-get install -y jq echo $? # === Create CAPIF user once the system is up === echo "" echo "👤 [3.1] Authenticating against CAPIF Register to create user..." # Login to Register service (Basic Auth admin:password123) LOGIN_RESPONSE=$(curl -sk --location --request POST "https://localhost:8084/login" \ --header "Authorization: Basic $(echo -n 'admin:password123' | base64)") # Extract access_token from the JSON response ACCESS_TOKEN=$(echo "$LOGIN_RESPONSE" | jq -r '.access_token') if [ -z "$ACCESS_TOKEN" ]; then echo "❌ Failed to obtain access_token from login response:" echo "$LOGIN_RESPONSE" exit 1 fi echo "✅ Login successful. Access token retrieved." # Create user with the obtained token echo "" echo "👤 [3.2] Creating user custom_user in CAPIF..." CREATE_RESPONSE=$(curl -sk --location "https://localhost:8084/createUser" \ --header "Content-Type: application/json" \ --header "Authorization: Bearer $ACCESS_TOKEN" \ --data-raw '{ "username": "custom_user", "password": "user_pass", "enterprise": "ETSI", "country": "Spain", "email": "example@gmail.com", "purpose": "Use OpenCAPIF", "phone_number": "+123456789", "company_web": "www.etsi.com", "description": "UserDescription" }') echo "$CREATE_RESPONSE" # === Run SDK === echo "" echo "🚀 [4/5] Running SDK (test_sdk.sh)..." bash "$SDK_SCRIPT" # === Final Result === echo "🏁 [5/5] SDK completed successfully."