From 5af911aaf0d76e4053a02723766c75fd2a822f69 Mon Sep 17 00:00:00 2001 From: DJ Mountney Date: Wed, 14 Jan 2026 12:03:38 -0800 Subject: [PATCH 01/13] chore: add additional tests --- .github/workflows/smoke-test-services.yml | 108 ++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 .github/workflows/smoke-test-services.yml diff --git a/.github/workflows/smoke-test-services.yml b/.github/workflows/smoke-test-services.yml new file mode 100644 index 0000000..d941327 --- /dev/null +++ b/.github/workflows/smoke-test-services.yml @@ -0,0 +1,108 @@ +name: Smoke Test Services + +on: + push: + branches: + - main + paths: + - 'on-prem/docker-compose.full.yml' + - 'on-prem/templates/**' + pull_request: + paths: + - 'on-prem/docker-compose.full.yml' + - 'on-prem/templates/**' + workflow_dispatch: + +jobs: + smoke-test: + name: Smoke Test (Redis + MongoDB) + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Create minimal .env + working-directory: on-prem + run: | + cat > .env << 'EOF' + # Minimal env for smoke testing Redis and MongoDB + MONGODB_USERNAME=testuser + MONGODB_PASSWORD=testpassword + CLICKHOUSE_CURRENTS_PASSWORD=placeholder + TRAEFIK_DOMAIN=example.com + EOF + + - name: Start Redis and MongoDB + working-directory: on-prem + run: | + docker compose -f docker-compose.full.yml up -d redis mongodb + echo "Waiting for services to start..." + + - name: Wait for Redis + working-directory: on-prem + run: | + echo "Waiting for Redis to be ready..." + for i in {1..30}; do + if docker compose -f docker-compose.full.yml exec -T redis redis-cli ping | grep -q PONG; then + echo "✅ Redis is ready" + exit 0 + fi + echo "Attempt $i/30 - Redis not ready yet..." + sleep 2 + done + echo "❌ Redis failed to start" + docker compose -f docker-compose.full.yml logs redis + exit 1 + + - name: Wait for MongoDB + working-directory: on-prem + run: | + echo "Waiting for MongoDB to be healthy..." + for i in {1..60}; do + if docker compose -f docker-compose.full.yml exec -T mongodb mongosh --quiet --eval "db.runCommand('ping').ok" localhost:27017 2>/dev/null | grep -q 1; then + echo "✅ MongoDB is ready" + exit 0 + fi + echo "Attempt $i/60 - MongoDB not ready yet..." + sleep 2 + done + echo "❌ MongoDB failed to start" + docker compose -f docker-compose.full.yml logs mongodb + exit 1 + + - name: Test Redis connectivity + working-directory: on-prem + run: | + echo "Testing Redis SET/GET..." + docker compose -f docker-compose.full.yml exec -T redis redis-cli SET smoke_test "hello" + RESULT=$(docker compose -f docker-compose.full.yml exec -T redis redis-cli GET smoke_test) + if [ "$RESULT" = "hello" ]; then + echo "✅ Redis SET/GET working" + else + echo "❌ Redis SET/GET failed: got '$RESULT'" + exit 1 + fi + + - name: Test MongoDB connectivity + working-directory: on-prem + run: | + echo "Testing MongoDB insert/find..." + docker compose -f docker-compose.full.yml exec -T mongodb mongosh \ + -u testuser -p testpassword --authenticationDatabase admin \ + --quiet --eval ' + db = db.getSiblingDB("smoke_test"); + db.test.insertOne({name: "smoke_test", timestamp: new Date()}); + const doc = db.test.findOne({name: "smoke_test"}); + if (doc) { + print("✅ MongoDB insert/find working"); + } else { + print("❌ MongoDB insert/find failed"); + quit(1); + } + ' + + - name: Cleanup + if: always() + working-directory: on-prem + run: | + docker compose -f docker-compose.full.yml down -v --remove-orphans From 1042217ec026c54643d68941a01b7c9bfdd389fd Mon Sep 17 00:00:00 2001 From: DJ Mountney Date: Wed, 14 Jan 2026 12:59:55 -0800 Subject: [PATCH 02/13] chore: Add login to the test registry --- .github/workflows/smoke-test-services.yml | 12 ++++++++++++ on-prem/docs/container-images.md | 13 ++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/.github/workflows/smoke-test-services.yml b/.github/workflows/smoke-test-services.yml index d941327..2d8a024 100644 --- a/.github/workflows/smoke-test-services.yml +++ b/.github/workflows/smoke-test-services.yml @@ -17,10 +17,22 @@ jobs: smoke-test: name: Smoke Test (Redis + MongoDB) runs-on: ubuntu-latest + permissions: + id-token: write # Required for OIDC + contents: read # Required for checkout steps: - name: Checkout uses: actions/checkout@v4 + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: arn:aws:iam::761136292957:role/GitHubActions-CurrentsDevDocker-ECRPull + aws-region: us-east-1 + + - name: Login to Amazon ECR + uses: aws-actions/amazon-ecr-login@v2 + - name: Create minimal .env working-directory: on-prem run: | diff --git a/on-prem/docs/container-images.md b/on-prem/docs/container-images.md index 3b186cf..cafaaef 100644 --- a/on-prem/docs/container-images.md +++ b/on-prem/docs/container-images.md @@ -25,7 +25,18 @@ Create an IAM role in your AWS account with the following policy: "ecr:GetDownloadUrlForLayer" ], "Resource": [ - "arn:aws:ecr:us-east-1:513558712013:repository/currents/on-prem/*" + "arn:aws:ecr:us-east-1:513558712013:currents/on-prem/api/*", + "arn:aws:ecr:us-east-1:513558712013:repository/currents/on-prem/api", + "arn:aws:ecr:us-east-1:513558712013:currents/on-prem/change-streams/*", + "arn:aws:ecr:us-east-1:513558712013:repository/currents/on-prem/change-streams", + "arn:aws:ecr:us-east-1:513558712013:currents/on-prem/director/*", + "arn:aws:ecr:us-east-1:513558712013:repository/currents/on-prem/director", + "arn:aws:ecr:us-east-1:513558712013:currents/on-prem/scheduler/*", + "arn:aws:ecr:us-east-1:513558712013:repository/currents/on-prem/scheduler", + "arn:aws:ecr:us-east-1:513558712013:currents/on-prem/writer/*", + "arn:aws:ecr:us-east-1:513558712013:repository/currents/on-prem/writer", + "arn:aws:ecr:us-east-1:513558712013:currents/on-prem/webhooks/*", + "arn:aws:ecr:us-east-1:513558712013:repository/currents/on-prem/webhooks" ] } ] From 2c437ea46b8d5213110b1ae5e9344f805f908b71 Mon Sep 17 00:00:00 2001 From: DJ Mountney Date: Wed, 14 Jan 2026 13:03:56 -0800 Subject: [PATCH 03/13] chore: run the tests once --- .github/workflows/smoke-test-services.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/smoke-test-services.yml b/.github/workflows/smoke-test-services.yml index 2d8a024..c23d249 100644 --- a/.github/workflows/smoke-test-services.yml +++ b/.github/workflows/smoke-test-services.yml @@ -8,9 +8,6 @@ on: - 'on-prem/docker-compose.full.yml' - 'on-prem/templates/**' pull_request: - paths: - - 'on-prem/docker-compose.full.yml' - - 'on-prem/templates/**' workflow_dispatch: jobs: From 8c1dd021fa4f3d1ad13c088b7eb18538b3d972df Mon Sep 17 00:00:00 2001 From: DJ Mountney Date: Wed, 14 Jan 2026 14:40:58 -0800 Subject: [PATCH 04/13] chore: test image pull --- .github/workflows/smoke-test-services.yml | 20 +++--- on-prem/scripts/setup.sh | 76 +++++++++++++++++++---- 2 files changed, 75 insertions(+), 21 deletions(-) diff --git a/.github/workflows/smoke-test-services.yml b/.github/workflows/smoke-test-services.yml index c23d249..887532d 100644 --- a/.github/workflows/smoke-test-services.yml +++ b/.github/workflows/smoke-test-services.yml @@ -30,16 +30,16 @@ jobs: - name: Login to Amazon ECR uses: aws-actions/amazon-ecr-login@v2 - - name: Create minimal .env + - name: Setup environment + working-directory: on-prem + run: ./scripts/setup.sh --env-only --force + + - name: Pull Currents images working-directory: on-prem run: | - cat > .env << 'EOF' - # Minimal env for smoke testing Redis and MongoDB - MONGODB_USERNAME=testuser - MONGODB_PASSWORD=testpassword - CLICKHOUSE_CURRENTS_PASSWORD=placeholder - TRAEFIK_DOMAIN=example.com - EOF + echo "Pulling all Currents service images from ECR..." + docker compose -f docker-compose.full.yml pull director api changestreams-worker write-worker scheduler webhooks + echo "✅ All Currents images pulled successfully" - name: Start Redis and MongoDB working-directory: on-prem @@ -95,9 +95,11 @@ jobs: - name: Test MongoDB connectivity working-directory: on-prem run: | + # Source credentials from generated .env + source .env echo "Testing MongoDB insert/find..." docker compose -f docker-compose.full.yml exec -T mongodb mongosh \ - -u testuser -p testpassword --authenticationDatabase admin \ + -u "$MONGODB_USERNAME" -p "$MONGODB_PASSWORD" --authenticationDatabase admin \ --quiet --eval ' db = db.getSiblingDB("smoke_test"); db.test.insertOne({name: "smoke_test", timestamp: new Date()}); diff --git a/on-prem/scripts/setup.sh b/on-prem/scripts/setup.sh index 8ccabb3..7b08770 100755 --- a/on-prem/scripts/setup.sh +++ b/on-prem/scripts/setup.sh @@ -3,6 +3,10 @@ # Interactive setup script for Currents on-prem # Generates a docker-compose file based on your infrastructure choices # and sets it as the default docker-compose.yml +# +# Usage: +# ./setup.sh # Interactive setup (profile selection + env generation) +# ./setup.sh --env-only # Only generate .env file with secrets (non-interactive) set -e @@ -16,27 +20,56 @@ BLUE='\033[0;34m' YELLOW='\033[1;33m' NC='\033[0m' # No Color -echo -e "${BLUE}" -echo "╔═══════════════════════════════════════════════════════════╗" -echo "║ Currents On-Prem Setup ║" -echo "╚═══════════════════════════════════════════════════════════╝" -echo -e "${NC}" - -echo "This script will help you generate a docker-compose configuration" -echo "based on which services you want to run locally vs externally." -echo "" +# Parse arguments +ENV_ONLY=false +FORCE_REGEN=false +while [[ $# -gt 0 ]]; do + case $1 in + --env-only) + ENV_ONLY=true + shift + ;; + --force) + FORCE_REGEN=true + shift + ;; + -h|--help) + echo "Usage: $0 [OPTIONS]" + echo "" + echo "Options:" + echo " --env-only Only generate .env file with secrets (non-interactive)" + echo " --force Force regenerate secrets even if .env exists" + echo " -h, --help Show this help message" + exit 0 + ;; + *) + echo "Unknown option: $1" + echo "Use --help for usage information" + exit 1 + ;; + esac +done # ============================================================================= # Environment file setup # ============================================================================= +# Define setup_env_file function first (used by both modes) setup_env_file() { cd "$ON_PREM_DIR" if [ -f .env ]; then echo -e "${YELLOW}Found existing .env file${NC}" - read -p "Regenerate secrets in .env? [y/N]: " regen_secrets - if [[ ! $regen_secrets =~ ^[Yy] ]]; then + if [ "$FORCE_REGEN" = true ]; then + echo "Force regenerating secrets..." + elif [ "$ENV_ONLY" = true ]; then + # Non-interactive mode: skip if .env exists and --force not set + echo "Using existing .env file (use --force to regenerate secrets)" return + else + read -p "Regenerate secrets in .env? [y/N]: " regen_secrets + if [[ ! $regen_secrets =~ ^[Yy] ]]; then + return + fi fi ENV_FILE=".env" else @@ -106,8 +139,27 @@ setup_env_file() { } # ============================================================================= -# Profile selection +# Handle --env-only mode # ============================================================================= +if [ "$ENV_ONLY" = true ]; then + setup_env_file + echo -e "${GREEN}✓ Environment setup complete!${NC}" + exit 0 +fi + +# ============================================================================= +# Interactive mode: Profile selection +# ============================================================================= +echo -e "${BLUE}" +echo "╔═══════════════════════════════════════════════════════════╗" +echo "║ Currents On-Prem Setup ║" +echo "╚═══════════════════════════════════════════════════════════╝" +echo -e "${NC}" + +echo "This script will help you generate a docker-compose configuration" +echo "based on which services you want to run locally vs externally." +echo "" + echo -e "${YELLOW}Select a configuration profile:${NC}" echo "" echo " 1) full - All services (redis, mongodb, clickhouse, rustfs)" From 05e0c4dc83dbbfa31f33ea611badb8d797add511 Mon Sep 17 00:00:00 2001 From: DJ Mountney Date: Wed, 14 Jan 2026 14:43:35 -0800 Subject: [PATCH 05/13] chore: login to the correct repo --- .github/workflows/smoke-test-services.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/smoke-test-services.yml b/.github/workflows/smoke-test-services.yml index 887532d..bbd63e8 100644 --- a/.github/workflows/smoke-test-services.yml +++ b/.github/workflows/smoke-test-services.yml @@ -27,8 +27,10 @@ jobs: role-to-assume: arn:aws:iam::761136292957:role/GitHubActions-CurrentsDevDocker-ECRPull aws-region: us-east-1 - - name: Login to Amazon ECR + - name: Login to Currents ECR uses: aws-actions/amazon-ecr-login@v2 + with: + registries: "513558712013" - name: Setup environment working-directory: on-prem From 4ceaba28f2f544676dbaa481932cd079d032daa1 Mon Sep 17 00:00:00 2001 From: DJ Mountney Date: Wed, 14 Jan 2026 15:32:48 -0800 Subject: [PATCH 06/13] chore: add api smoke test --- .github/workflows/smoke-test-services.yml | 85 ++++++---- on-prem/scripts/smoke-test/api-test.sh | 143 +++++++++++++++++ on-prem/scripts/smoke-test/seed-database.sh | 166 ++++++++++++++++++++ 3 files changed, 365 insertions(+), 29 deletions(-) create mode 100755 on-prem/scripts/smoke-test/api-test.sh create mode 100755 on-prem/scripts/smoke-test/seed-database.sh diff --git a/.github/workflows/smoke-test-services.yml b/.github/workflows/smoke-test-services.yml index bbd63e8..2e48f2d 100644 --- a/.github/workflows/smoke-test-services.yml +++ b/.github/workflows/smoke-test-services.yml @@ -12,7 +12,7 @@ on: jobs: smoke-test: - name: Smoke Test (Redis + MongoDB) + name: API Smoke Test runs-on: ubuntu-latest permissions: id-token: write # Required for OIDC @@ -43,11 +43,12 @@ jobs: docker compose -f docker-compose.full.yml pull director api changestreams-worker write-worker scheduler webhooks echo "✅ All Currents images pulled successfully" - - name: Start Redis and MongoDB + - name: Start infrastructure services working-directory: on-prem run: | + echo "Starting Redis and MongoDB..." docker compose -f docker-compose.full.yml up -d redis mongodb - echo "Waiting for services to start..." + echo "Waiting for services to initialize..." - name: Wait for Redis working-directory: on-prem @@ -81,38 +82,64 @@ jobs: docker compose -f docker-compose.full.yml logs mongodb exit 1 - - name: Test Redis connectivity + - name: Start application services working-directory: on-prem run: | - echo "Testing Redis SET/GET..." - docker compose -f docker-compose.full.yml exec -T redis redis-cli SET smoke_test "hello" - RESULT=$(docker compose -f docker-compose.full.yml exec -T redis redis-cli GET smoke_test) - if [ "$RESULT" = "hello" ]; then - echo "✅ Redis SET/GET working" - else - echo "❌ Redis SET/GET failed: got '$RESULT'" - exit 1 - fi + echo "Starting Scheduler and API..." + docker compose -f docker-compose.full.yml up -d scheduler api + echo "Waiting for services to initialize..." - - name: Test MongoDB connectivity + - name: Wait for API + working-directory: on-prem + run: | + echo "Waiting for API to be ready..." + for i in {1..60}; do + if curl -sf http://localhost:4000/health > /dev/null 2>&1; then + echo "✅ API is ready" + exit 0 + fi + echo "Attempt $i/60 - API not ready yet..." + sleep 2 + done + echo "❌ API failed to start" + docker compose -f docker-compose.full.yml logs api + exit 1 + + - name: Wait for root user working-directory: on-prem run: | - # Source credentials from generated .env source .env - echo "Testing MongoDB insert/find..." - docker compose -f docker-compose.full.yml exec -T mongodb mongosh \ - -u "$MONGODB_USERNAME" -p "$MONGODB_PASSWORD" --authenticationDatabase admin \ - --quiet --eval ' - db = db.getSiblingDB("smoke_test"); - db.test.insertOne({name: "smoke_test", timestamp: new Date()}); - const doc = db.test.findOne({name: "smoke_test"}); - if (doc) { - print("✅ MongoDB insert/find working"); - } else { - print("❌ MongoDB insert/find failed"); - quit(1); - } - ' + echo "Waiting for root user to be created..." + for i in {1..30}; do + if docker compose -f docker-compose.full.yml exec -T mongodb mongosh \ + -u "$MONGODB_USERNAME" -p "$MONGODB_PASSWORD" --authenticationDatabase admin \ + --quiet --eval "db.getSiblingDB('currents').user.findOne({email: '${ON_PREM_EMAIL:-root@currents.local}'})" 2>/dev/null | grep -q "_id"; then + echo "✅ Root user exists" + exit 0 + fi + echo "Attempt $i/30 - Root user not created yet..." + sleep 2 + done + echo "❌ Root user was not created" + docker compose -f docker-compose.full.yml logs api scheduler + exit 1 + + - name: Seed database + id: seed + working-directory: on-prem + run: | + echo "Seeding database with test data..." + # Capture the KEY=VALUE output from seed script + eval $(./scripts/smoke-test/seed-database.sh) + # Export to GitHub Actions output + echo "api_key=${API_KEY}" >> $GITHUB_OUTPUT + echo "project_id=${PROJECT_ID}" >> $GITHUB_OUTPUT + + - name: Run API smoke test + working-directory: on-prem + run: | + echo "Running API smoke test..." + ./scripts/smoke-test/api-test.sh "${{ steps.seed.outputs.api_key }}" "${{ steps.seed.outputs.project_id }}" - name: Cleanup if: always() diff --git a/on-prem/scripts/smoke-test/api-test.sh b/on-prem/scripts/smoke-test/api-test.sh new file mode 100755 index 0000000..c3064ac --- /dev/null +++ b/on-prem/scripts/smoke-test/api-test.sh @@ -0,0 +1,143 @@ +#!/bin/bash +# +# API smoke test - verify the Currents API is working +# Creates an action via the API and verifies it can be retrieved +# +# Usage: ./api-test.sh +# +# Based on Currents API: https://api.currents.dev/v1/docs/ + +set -e + +API_KEY="${1:-}" +PROJECT_ID="${2:-}" +API_BASE_URL="${API_BASE_URL:-http://localhost:4000/v1}" + +if [ -z "$API_KEY" ]; then + echo "❌ Error: API key is required" + echo "Usage: $0 " + exit 1 +fi + +if [ -z "$PROJECT_ID" ]; then + echo "❌ Error: Project ID is required" + echo "Usage: $0 " + exit 1 +fi + +echo "Running API smoke test..." +echo "API URL: $API_BASE_URL" +echo "Project ID: $PROJECT_ID" +echo "" + +# Generate unique name for this test run +TEST_NAME="smoke-test-action-$(date +%s)" + +# ============================================================================= +# Step 1: Create an action +# ============================================================================= +echo "Step 1: Creating test action..." + +CREATE_RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "${API_BASE_URL}/actions?projectId=${PROJECT_ID}" \ + -H "Authorization: Bearer ${API_KEY}" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "'"${TEST_NAME}"'", + "description": "Smoke test action - safe to delete", + "action": [{"op": "skip"}], + "matcher": { + "op": "AND", + "cond": [ + { + "type": "title", + "op": "eq", + "value": "smoke-test-placeholder" + } + ] + } + }') + +HTTP_CODE=$(echo "$CREATE_RESPONSE" | tail -n1) +RESPONSE_BODY=$(echo "$CREATE_RESPONSE" | sed '$d') + +if [ "$HTTP_CODE" != "201" ]; then + echo "❌ Failed to create action (HTTP $HTTP_CODE)" + echo "Response: $RESPONSE_BODY" + exit 1 +fi + +ACTION_ID=$(echo "$RESPONSE_BODY" | jq -r '.data.actionId') + +if [ -z "$ACTION_ID" ] || [ "$ACTION_ID" = "null" ]; then + echo "❌ Failed to extract actionId from response" + echo "Response: $RESPONSE_BODY" + exit 1 +fi + +echo "✅ Created action: $ACTION_ID" + +# ============================================================================= +# Step 2: Fetch the action back +# ============================================================================= +echo "" +echo "Step 2: Fetching action..." + +GET_RESPONSE=$(curl -s -w "\n%{http_code}" "${API_BASE_URL}/actions/${ACTION_ID}" \ + -H "Authorization: Bearer ${API_KEY}") + +HTTP_CODE=$(echo "$GET_RESPONSE" | tail -n1) +RESPONSE_BODY=$(echo "$GET_RESPONSE" | sed '$d') + +if [ "$HTTP_CODE" != "200" ]; then + echo "❌ Failed to fetch action (HTTP $HTTP_CODE)" + echo "Response: $RESPONSE_BODY" + exit 1 +fi + +FETCHED_NAME=$(echo "$RESPONSE_BODY" | jq -r '.data.name') +FETCHED_STATUS=$(echo "$RESPONSE_BODY" | jq -r '.data.status') + +if [ "$FETCHED_NAME" != "$TEST_NAME" ]; then + echo "❌ Action name mismatch" + echo "Expected: $TEST_NAME" + echo "Got: $FETCHED_NAME" + exit 1 +fi + +echo "✅ Fetched action successfully" +echo " Name: $FETCHED_NAME" +echo " Status: $FETCHED_STATUS" + +# ============================================================================= +# Step 3: Clean up - delete the action +# ============================================================================= +echo "" +echo "Step 3: Cleaning up (deleting action)..." + +DELETE_RESPONSE=$(curl -s -w "\n%{http_code}" -X DELETE "${API_BASE_URL}/actions/${ACTION_ID}" \ + -H "Authorization: Bearer ${API_KEY}") + +HTTP_CODE=$(echo "$DELETE_RESPONSE" | tail -n1) +RESPONSE_BODY=$(echo "$DELETE_RESPONSE" | sed '$d') + +if [ "$HTTP_CODE" != "200" ]; then + echo "⚠️ Warning: Failed to delete action (HTTP $HTTP_CODE)" + echo "Response: $RESPONSE_BODY" + # Don't fail the test for cleanup issues +else + echo "✅ Action deleted (archived)" +fi + +# ============================================================================= +# Summary +# ============================================================================= +echo "" +echo "==========================================" +echo "✅ API smoke test passed!" +echo "==========================================" +echo "" +echo "Verified:" +echo " - POST /actions (create)" +echo " - GET /actions/{actionId} (read)" +echo " - DELETE /actions/{actionId} (delete)" +echo "" diff --git a/on-prem/scripts/smoke-test/seed-database.sh b/on-prem/scripts/smoke-test/seed-database.sh new file mode 100755 index 0000000..fc05fef --- /dev/null +++ b/on-prem/scripts/smoke-test/seed-database.sh @@ -0,0 +1,166 @@ +#!/bin/bash +# +# Seed the database with test data for smoke testing +# Creates: organization, project, and API key +# +# Prerequisites: +# - MongoDB must be running and healthy +# - API must have created the root user (from ON_PREM_EMAIL in .env) +# +# Usage: ./seed-database.sh +# Outputs: API_KEY and PROJECT_ID to stdout (can be eval'd) +# +# Example: +# eval $(./seed-database.sh) +# echo $API_KEY $PROJECT_ID + +set -e + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ON_PREM_DIR="$SCRIPT_DIR/../.." + +cd "$ON_PREM_DIR" + +# Source environment variables +source .env + +echo "Seeding database with test data..." >&2 + +# Generate a random 6-character project ID (alphanumeric) +generate_project_id() { + cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 6 | head -n 1 +} + +# Generate a 64-character API key +generate_api_key() { + cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 64 | head -n 1 +} + +PROJECT_ID=$(generate_project_id) +API_KEY=$(generate_api_key) + +# Run MongoDB commands to seed the database +docker compose -f docker-compose.full.yml exec -T mongodb mongosh \ + -u "$MONGODB_USERNAME" -p "$MONGODB_PASSWORD" --authenticationDatabase admin \ + --quiet <&2 + exit 1 +fi + +# Output variables that can be eval'd by the caller +echo "API_KEY=${API_KEY}" +echo "PROJECT_ID=${PROJECT_ID}" + +echo "✅ Database seeded successfully" >&2 +echo " Project ID: ${PROJECT_ID}" >&2 +echo " API Key: ${API_KEY:0:8}..." >&2 From 383848fd0ff33681949ec6dbd67eede7e9697b66 Mon Sep 17 00:00:00 2001 From: DJ Mountney Date: Wed, 14 Jan 2026 15:38:51 -0800 Subject: [PATCH 07/13] chore: fix hanging seed --- on-prem/scripts/smoke-test/seed-database.sh | 25 +++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/on-prem/scripts/smoke-test/seed-database.sh b/on-prem/scripts/smoke-test/seed-database.sh index fc05fef..e6f100d 100755 --- a/on-prem/scripts/smoke-test/seed-database.sh +++ b/on-prem/scripts/smoke-test/seed-database.sh @@ -11,7 +11,7 @@ # Outputs: API_KEY and PROJECT_ID to stdout (can be eval'd) # # Example: -# eval $(./seed-database.sh) +# eval $(./scripts/smoke-test/seed-database.sh) # echo $API_KEY $PROJECT_ID set -e @@ -38,17 +38,15 @@ generate_api_key() { PROJECT_ID=$(generate_project_id) API_KEY=$(generate_api_key) +ROOT_EMAIL="${ON_PREM_EMAIL:-root@currents.local}" -# Run MongoDB commands to seed the database -docker compose -f docker-compose.full.yml exec -T mongodb mongosh \ - -u "$MONGODB_USERNAME" -p "$MONGODB_PASSWORD" --authenticationDatabase admin \ - --quiet <&2 +RESULT=$(docker compose -f docker-compose.full.yml exec -T mongodb mongosh \ + -u "$MONGODB_USERNAME" -p "$MONGODB_PASSWORD" --authenticationDatabase admin \ + --quiet --eval "$SEED_SCRIPT" 2>&1) + +echo "$RESULT" >&2 # Check if MongoDB commands succeeded -if [ $? -ne 0 ]; then +if ! echo "$RESULT" | grep -q "SUCCESS"; then echo "❌ Failed to seed database" >&2 exit 1 fi From 660c0d105028b9e038ee711c55ebe2e1e7c3c876 Mon Sep 17 00:00:00 2001 From: DJ Mountney Date: Wed, 14 Jan 2026 15:46:23 -0800 Subject: [PATCH 08/13] chore: debug seed script --- .github/workflows/smoke-test-services.yml | 7 ---- on-prem/scripts/smoke-test/seed-database.sh | 45 +++++++++++++++++---- on-prem/templates/compose.clickhouse.yml | 24 ----------- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/.github/workflows/smoke-test-services.yml b/.github/workflows/smoke-test-services.yml index 2e48f2d..6b55a40 100644 --- a/.github/workflows/smoke-test-services.yml +++ b/.github/workflows/smoke-test-services.yml @@ -36,13 +36,6 @@ jobs: working-directory: on-prem run: ./scripts/setup.sh --env-only --force - - name: Pull Currents images - working-directory: on-prem - run: | - echo "Pulling all Currents service images from ECR..." - docker compose -f docker-compose.full.yml pull director api changestreams-worker write-worker scheduler webhooks - echo "✅ All Currents images pulled successfully" - - name: Start infrastructure services working-directory: on-prem run: | diff --git a/on-prem/scripts/smoke-test/seed-database.sh b/on-prem/scripts/smoke-test/seed-database.sh index e6f100d..1bcf3c7 100755 --- a/on-prem/scripts/smoke-test/seed-database.sh +++ b/on-prem/scripts/smoke-test/seed-database.sh @@ -22,6 +22,7 @@ ON_PREM_DIR="$SCRIPT_DIR/../.." cd "$ON_PREM_DIR" # Source environment variables +echo "[DEBUG] Sourcing .env file..." >&2 source .env echo "Seeding database with test data..." >&2 @@ -36,12 +37,25 @@ generate_api_key() { cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 64 | head -n 1 } +echo "[DEBUG] Generating project ID..." >&2 PROJECT_ID=$(generate_project_id) +echo "[DEBUG] Project ID: $PROJECT_ID" >&2 + +echo "[DEBUG] Generating API key..." >&2 API_KEY=$(generate_api_key) +echo "[DEBUG] API key generated" >&2 + ROOT_EMAIL="${ON_PREM_EMAIL:-root@currents.local}" +echo "[DEBUG] Root email: $ROOT_EMAIL" >&2 + +# Create temp file for the MongoDB script +echo "[DEBUG] Creating temp file..." >&2 +TEMP_SCRIPT=$(mktemp) +trap "rm -f $TEMP_SCRIPT" EXIT +echo "[DEBUG] Temp file: $TEMP_SCRIPT" >&2 -# Create the MongoDB seed script -SEED_SCRIPT=$(cat <&2 +cat > "$TEMP_SCRIPT" <&2 -RESULT=$(docker compose -f docker-compose.full.yml exec -T mongodb mongosh \ +echo "[DEBUG] MongoDB script written" >&2 + +# Get the container name +echo "[DEBUG] Getting MongoDB container ID..." >&2 +CONTAINER=$(docker compose -f docker-compose.full.yml ps -q mongodb) +echo "[DEBUG] Container ID: $CONTAINER" >&2 + +if [ -z "$CONTAINER" ]; then + echo "❌ MongoDB container not found" >&2 + exit 1 +fi + +# Copy script into container +echo "[DEBUG] Copying seed script to container..." >&2 +docker cp "$TEMP_SCRIPT" "$CONTAINER:/tmp/seed.js" +echo "[DEBUG] Script copied" >&2 + +# Run the script +echo "[DEBUG] Running MongoDB seed script..." >&2 +RESULT=$(docker exec "$CONTAINER" mongosh \ -u "$MONGODB_USERNAME" -p "$MONGODB_PASSWORD" --authenticationDatabase admin \ - --quiet --eval "$SEED_SCRIPT" 2>&1) + --quiet --file /tmp/seed.js 2>&1) +echo "[DEBUG] Script execution completed" >&2 echo "$RESULT" >&2 # Check if MongoDB commands succeeded diff --git a/on-prem/templates/compose.clickhouse.yml b/on-prem/templates/compose.clickhouse.yml index 5b1080f..d725ff9 100644 --- a/on-prem/templates/compose.clickhouse.yml +++ b/on-prem/templates/compose.clickhouse.yml @@ -58,38 +58,14 @@ services: - ${DC_CLICKHOUSE_VOLUME:-./data/clickhouse}:/var/lib/clickhouse # Currents services depend on clickhouse - director: - depends_on: - clickhouse: - condition: service_healthy - required: false - api: depends_on: clickhouse: condition: service_healthy required: false - changestreams-worker: - depends_on: - clickhouse: - condition: service_healthy - required: false - write-worker: depends_on: clickhouse: condition: service_healthy required: false - - scheduler: - depends_on: - clickhouse: - condition: service_healthy - required: false - - webhooks: - depends_on: - clickhouse: - condition: service_healthy - required: false From 0531eac44a56b8dc5426068d7c6302934364104c Mon Sep 17 00:00:00 2001 From: DJ Mountney Date: Wed, 14 Jan 2026 15:51:47 -0800 Subject: [PATCH 09/13] chore: use faster randomness --- on-prem/docker-compose.database.yml | 16 +--------------- on-prem/docker-compose.full.yml | 16 +--------------- on-prem/scripts/smoke-test/seed-database.sh | 4 ++-- on-prem/templates/compose.clickhouse.yml | 6 ------ 4 files changed, 4 insertions(+), 38 deletions(-) diff --git a/on-prem/docker-compose.database.yml b/on-prem/docker-compose.database.yml index 398be59..1b47ef9 100644 --- a/on-prem/docker-compose.database.yml +++ b/on-prem/docker-compose.database.yml @@ -26,9 +26,6 @@ services: CURRENTS_ENV: onprem EMAIL_TRANSPORTER: smtp depends_on: - clickhouse: - condition: service_healthy - required: false mongodb: condition: service_healthy required: false @@ -52,9 +49,6 @@ services: CLICKHOUSE_PASSWORD: ${CLICKHOUSE_CURRENTS_PASSWORD} EMAIL_TRANSPORTER: smtp depends_on: - clickhouse: - condition: service_healthy - required: false mongodb: condition: service_healthy required: false @@ -73,15 +67,13 @@ services: CLICKHOUSE_PASSWORD: ${CLICKHOUSE_CURRENTS_PASSWORD} EMAIL_TRANSPORTER: smtp depends_on: - clickhouse: - condition: service_healthy - required: false mongodb: condition: service_healthy required: false redis: condition: service_started required: false + # Currents services depend on clickhouse write-worker: image: ${DC_CURRENTS_IMAGE_REPOSITORY:-currents-}writer:${DC_CURRENTS_IMAGE_TAG:-staging} restart: unless-stopped @@ -118,9 +110,6 @@ services: volumes: - ${DC_SCHEDULER_STARTUP_VOLUME:-./data/startup}:/app/packages/scheduler/dist/.startup depends_on: - clickhouse: - condition: service_healthy - required: false mongodb: condition: service_healthy required: false @@ -138,9 +127,6 @@ services: CURRENTS_ENV: onprem EMAIL_TRANSPORTER: smtp depends_on: - clickhouse: - condition: service_healthy - required: false mongodb: condition: service_healthy required: false diff --git a/on-prem/docker-compose.full.yml b/on-prem/docker-compose.full.yml index f5c3c34..522c22e 100644 --- a/on-prem/docker-compose.full.yml +++ b/on-prem/docker-compose.full.yml @@ -27,9 +27,6 @@ services: EMAIL_TRANSPORTER: smtp FILE_STORAGE_FORCE_PATH_STYLE: "true" depends_on: - clickhouse: - condition: service_healthy - required: false mongodb: condition: service_healthy required: false @@ -54,9 +51,6 @@ services: EMAIL_TRANSPORTER: smtp FILE_STORAGE_FORCE_PATH_STYLE: "true" depends_on: - clickhouse: - condition: service_healthy - required: false mongodb: condition: service_healthy required: false @@ -76,15 +70,13 @@ services: EMAIL_TRANSPORTER: smtp FILE_STORAGE_FORCE_PATH_STYLE: "true" depends_on: - clickhouse: - condition: service_healthy - required: false mongodb: condition: service_healthy required: false redis: condition: service_started required: false + # Currents services depend on clickhouse write-worker: image: ${DC_CURRENTS_IMAGE_REPOSITORY:-currents-}writer:${DC_CURRENTS_IMAGE_TAG:-staging} restart: unless-stopped @@ -123,9 +115,6 @@ services: volumes: - ${DC_SCHEDULER_STARTUP_VOLUME:-./data/startup}:/app/packages/scheduler/dist/.startup depends_on: - clickhouse: - condition: service_healthy - required: false mongodb: condition: service_healthy required: false @@ -144,9 +133,6 @@ services: EMAIL_TRANSPORTER: smtp FILE_STORAGE_FORCE_PATH_STYLE: "true" depends_on: - clickhouse: - condition: service_healthy - required: false mongodb: condition: service_healthy required: false diff --git a/on-prem/scripts/smoke-test/seed-database.sh b/on-prem/scripts/smoke-test/seed-database.sh index 1bcf3c7..ade1ae5 100755 --- a/on-prem/scripts/smoke-test/seed-database.sh +++ b/on-prem/scripts/smoke-test/seed-database.sh @@ -29,12 +29,12 @@ echo "Seeding database with test data..." >&2 # Generate a random 6-character project ID (alphanumeric) generate_project_id() { - cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 6 | head -n 1 + openssl rand -base64 12 | tr -dc 'a-zA-Z0-9' | head -c 6 } # Generate a 64-character API key generate_api_key() { - cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 64 | head -n 1 + openssl rand -base64 96 | tr -dc 'a-zA-Z0-9' | head -c 64 } echo "[DEBUG] Generating project ID..." >&2 diff --git a/on-prem/templates/compose.clickhouse.yml b/on-prem/templates/compose.clickhouse.yml index d725ff9..a109f4d 100644 --- a/on-prem/templates/compose.clickhouse.yml +++ b/on-prem/templates/compose.clickhouse.yml @@ -58,12 +58,6 @@ services: - ${DC_CLICKHOUSE_VOLUME:-./data/clickhouse}:/var/lib/clickhouse # Currents services depend on clickhouse - api: - depends_on: - clickhouse: - condition: service_healthy - required: false - write-worker: depends_on: clickhouse: From 02c0f61f7cebc8e5e3acf39bb9bd8c56a41891ac Mon Sep 17 00:00:00 2001 From: DJ Mountney Date: Wed, 14 Jan 2026 16:01:01 -0800 Subject: [PATCH 10/13] chore: point at correct api endpoint --- on-prem/scripts/smoke-test/api-test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/on-prem/scripts/smoke-test/api-test.sh b/on-prem/scripts/smoke-test/api-test.sh index c3064ac..3ff6af9 100755 --- a/on-prem/scripts/smoke-test/api-test.sh +++ b/on-prem/scripts/smoke-test/api-test.sh @@ -11,7 +11,7 @@ set -e API_KEY="${1:-}" PROJECT_ID="${2:-}" -API_BASE_URL="${API_BASE_URL:-http://localhost:4000/v1}" +API_BASE_URL="${API_BASE_URL:-http://localhost:4000/api/v1}" if [ -z "$API_KEY" ]; then echo "❌ Error: API key is required" From ff1f5bedf300a18e8399dc3d2403bb61aa93e3e1 Mon Sep 17 00:00:00 2001 From: DJ Mountney Date: Wed, 14 Jan 2026 16:08:02 -0800 Subject: [PATCH 11/13] chore: debug auth failure --- on-prem/scripts/smoke-test/api-test.sh | 18 ++++++++++++++++++ on-prem/scripts/smoke-test/seed-database.sh | 20 +++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/on-prem/scripts/smoke-test/api-test.sh b/on-prem/scripts/smoke-test/api-test.sh index 3ff6af9..53d1289 100755 --- a/on-prem/scripts/smoke-test/api-test.sh +++ b/on-prem/scripts/smoke-test/api-test.sh @@ -9,10 +9,24 @@ set -e +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ON_PREM_DIR="$SCRIPT_DIR/../.." + API_KEY="${1:-}" PROJECT_ID="${2:-}" API_BASE_URL="${API_BASE_URL:-http://localhost:4000/api/v1}" +# Function to show logs on failure +show_logs_on_failure() { + echo "" + echo "==========================================" + echo "API container logs (last 100 lines):" + echo "==========================================" + cd "$ON_PREM_DIR" + docker compose -f docker-compose.full.yml logs --tail=100 api + echo "==========================================" +} + if [ -z "$API_KEY" ]; then echo "❌ Error: API key is required" echo "Usage: $0 " @@ -63,6 +77,7 @@ RESPONSE_BODY=$(echo "$CREATE_RESPONSE" | sed '$d') if [ "$HTTP_CODE" != "201" ]; then echo "❌ Failed to create action (HTTP $HTTP_CODE)" echo "Response: $RESPONSE_BODY" + show_logs_on_failure exit 1 fi @@ -71,6 +86,7 @@ ACTION_ID=$(echo "$RESPONSE_BODY" | jq -r '.data.actionId') if [ -z "$ACTION_ID" ] || [ "$ACTION_ID" = "null" ]; then echo "❌ Failed to extract actionId from response" echo "Response: $RESPONSE_BODY" + show_logs_on_failure exit 1 fi @@ -91,6 +107,7 @@ RESPONSE_BODY=$(echo "$GET_RESPONSE" | sed '$d') if [ "$HTTP_CODE" != "200" ]; then echo "❌ Failed to fetch action (HTTP $HTTP_CODE)" echo "Response: $RESPONSE_BODY" + show_logs_on_failure exit 1 fi @@ -101,6 +118,7 @@ if [ "$FETCHED_NAME" != "$TEST_NAME" ]; then echo "❌ Action name mismatch" echo "Expected: $TEST_NAME" echo "Got: $FETCHED_NAME" + show_logs_on_failure exit 1 fi diff --git a/on-prem/scripts/smoke-test/seed-database.sh b/on-prem/scripts/smoke-test/seed-database.sh index ade1ae5..6fec434 100755 --- a/on-prem/scripts/smoke-test/seed-database.sh +++ b/on-prem/scripts/smoke-test/seed-database.sh @@ -158,7 +158,25 @@ if (!apiKeyResult.acknowledged) { print("ERROR: Failed to create API key"); quit(1); } -print("Created API key"); +print("Created API key: " + apiKey.substring(0, 8) + "..."); + +// Verify the API key was inserted +const verifyKey = db.apiKeys.findOne({ key: apiKey }); +if (verifyKey) { + print("Verified API key exists in database"); + print("API key orgId: " + verifyKey.orgId); +} else { + print("WARNING: Could not verify API key in database"); +} + +// Verify project exists +const verifyProject = db.projects.findOne({ projectId: projectId }); +if (verifyProject) { + print("Verified project exists: " + verifyProject.projectId); + print("Project orgId: " + verifyProject.orgId); +} else { + print("WARNING: Could not verify project in database"); +} print("SUCCESS"); MONGOSCRIPT From 2a4b544d8a6873856cceb8b0b8a44d6286526bfb Mon Sep 17 00:00:00 2001 From: DJ Mountney Date: Wed, 14 Jan 2026 16:18:00 -0800 Subject: [PATCH 12/13] chore: swap back to proper api endpoint --- on-prem/scripts/smoke-test/api-test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/on-prem/scripts/smoke-test/api-test.sh b/on-prem/scripts/smoke-test/api-test.sh index 53d1289..1b0c42f 100755 --- a/on-prem/scripts/smoke-test/api-test.sh +++ b/on-prem/scripts/smoke-test/api-test.sh @@ -14,7 +14,7 @@ ON_PREM_DIR="$SCRIPT_DIR/../.." API_KEY="${1:-}" PROJECT_ID="${2:-}" -API_BASE_URL="${API_BASE_URL:-http://localhost:4000/api/v1}" +API_BASE_URL="${API_BASE_URL:-http://localhost:4000/v1}" # Function to show logs on failure show_logs_on_failure() { From 5a502e141bdf80866bdd4be976622b1b1535d05a Mon Sep 17 00:00:00 2001 From: DJ Mountney Date: Thu, 15 Jan 2026 09:03:16 -0800 Subject: [PATCH 13/13] chore: Add test paths --- .github/workflows/smoke-test-services.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/smoke-test-services.yml b/.github/workflows/smoke-test-services.yml index 6b55a40..810e6c8 100644 --- a/.github/workflows/smoke-test-services.yml +++ b/.github/workflows/smoke-test-services.yml @@ -5,9 +5,16 @@ on: branches: - main paths: - - 'on-prem/docker-compose.full.yml' + - 'on-prem/docker-compose.*.yml' - 'on-prem/templates/**' + - 'on-prem/scripts/**' + - '.env.example' pull_request: + paths: + - 'on-prem/docker-compose.*.yml' + - 'on-prem/templates/**' + - 'on-prem/scripts/**' + - '.env.example' workflow_dispatch: jobs: