-
Notifications
You must be signed in to change notification settings - Fork 6
setup cdk dev mint and keycloak with devenv #591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gudnuf
wants to merge
1
commit into
alpha
Choose a base branch
from
setup-cdk-dev-mint
base: alpha
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,3 +33,6 @@ node_modules | |
|
|
||
| # Local SSL certificates | ||
| /certs/ | ||
|
|
||
| # CDK mint data directory | ||
| /.cdk-mint/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Default number of lines to show | ||
| DEFAULT_LINES=50 | ||
|
|
||
| # Parse command line arguments | ||
| LINES=${1:-$DEFAULT_LINES} | ||
|
|
||
| # Validate that LINES is a number | ||
| if ! [[ "$LINES" =~ ^[0-9]+$ ]]; then | ||
| echo "❌ Invalid number of lines: $LINES" | ||
| echo "Usage: cdk-logs [number_of_lines]" | ||
| echo "Example: cdk-logs 100" | ||
| echo "Default: $DEFAULT_LINES lines" | ||
| exit 1 | ||
| fi | ||
|
|
||
| LOGS_DIR="$DEVENV_ROOT/.cdk-mint/logs" | ||
|
|
||
| # Check if logs directory exists | ||
| if [ ! -d "$LOGS_DIR" ]; then | ||
| echo "❌ No logs directory found. Start the mint first with 'cdk-mint'" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Find the latest log file (format: cdk-mintd.log.YYYY-MM-DD) | ||
| LATEST_LOG=$(ls -t "$LOGS_DIR"/cdk-mintd.log.* 2>/dev/null | head -n 1) | ||
|
|
||
| if [ -n "$LATEST_LOG" ] && [ -f "$LATEST_LOG" ]; then | ||
| echo "📖 Showing latest CDK mint logs from $(basename "$LATEST_LOG") (last $LINES lines):" | ||
| echo "📁 $LATEST_LOG" | ||
| echo "" | ||
|
|
||
| tail -n "$LINES" -f "$LATEST_LOG" | ||
| else | ||
| echo "❌ No CDK mint log files found in $LOGS_DIR" | ||
| echo "📁 Available files:" | ||
| ls -la "$LOGS_DIR/" 2>/dev/null || echo " (directory is empty)" | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # see https://github.com/cashubtc/cdk/blob/main/crates/cdk-mintd/example.config.toml for more options | ||
|
|
||
| [info] | ||
| url = "http://127.0.0.1:8085/" | ||
| listen_host = "127.0.0.1" | ||
| listen_port = 8085 | ||
| mnemonic = "solar decline pole link deposit coconut region race flame truck correct yard" | ||
| enable_swagger_ui = true | ||
|
|
||
| [mint_management_rpc] | ||
| enabled = false | ||
|
|
||
| [info.http_cache] | ||
| backend = "memory" | ||
| ttl = 60 | ||
| tti = 60 | ||
|
|
||
|
|
||
| [info.logging] | ||
| # Where to output logs: "stdout", "file", or "both" (default: "both") | ||
| # Note: "stdout" actually outputs to stderr (standard error stream) | ||
| # output = "both" | ||
| # Log level for console output (default: "info") | ||
| # console_level = "info" | ||
| # Log level for file output (default: "debug") | ||
| # file_level = "debug" | ||
|
|
||
| [mint_info] | ||
| name = "Agicash local mint" | ||
| description = "Local development mint for testing!" | ||
| description_long = "" | ||
| motd = "" | ||
|
|
||
| [database] | ||
| engine = "sqlite" | ||
|
|
||
| [ln] | ||
| ln_backend = "fakewallet" | ||
| min_mint = 1 | ||
| max_mint = 500000 | ||
| min_melt = 1 | ||
| max_melt = 500000 | ||
|
|
||
| [fake_wallet] | ||
| supported_units = ["sat"] | ||
| fee_percent = 0.02 | ||
| reserve_fee_min = 1 | ||
| min_delay_time = 1 | ||
| max_delay_time = 3 | ||
|
|
||
| [auth] | ||
| auth_enabled = false | ||
| openid_discovery = "http://127.0.0.1:8080/realms/cdk-test-realm/.well-known/openid-configuration" | ||
| openid_client_id = "cashu-client" | ||
| mint_max_bat=50 | ||
|
|
||
| # Authentication settings for endpoints | ||
| # Options: "clear", "blind", "none" (none = disabled) | ||
| mint = "blind" | ||
| get_mint_quote = "none" | ||
| check_mint_quote = "none" | ||
|
|
||
| melt = "none" | ||
| get_melt_quote = "none" | ||
| check_melt_quote = "none" | ||
|
|
||
| swap = "blind" | ||
| restore = "blind" | ||
| check_proof_state = "none" | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| #!/bin/bash | ||
|
|
||
| echo "🪙 Starting CDK Mint..." | ||
|
|
||
| # Fallback to main if not set | ||
| CDK_REF="${CDK_REF:-main}" | ||
| echo "📍 Using CDK reference: $CDK_REF" | ||
|
|
||
| ensure_docker_compose() { | ||
| command -v docker &> /dev/null || { | ||
| echo "❌ Docker not found. Install Docker to use Keycloak authentication" | ||
| return 1 | ||
| } | ||
| docker compose version &> /dev/null || { | ||
| echo "❌ Docker Compose not available" | ||
| return 1 | ||
| } | ||
| } | ||
|
|
||
| # Function to check if auth is enabled in config | ||
| check_auth_enabled() { | ||
| local config_file="$DEVENV_ROOT/tools/devenv/cdk/cdk-mint.config.toml" | ||
| [ -f "$config_file" ] && grep -q "^auth_enabled = true" "$config_file" | ||
| } | ||
|
|
||
| start_keycloak() { | ||
| local cdk_dir="$1" | ||
| local keycloak_compose="$cdk_dir/misc/keycloak/docker-compose-recover.yml" | ||
| local keycloak_export="$cdk_dir/misc/keycloak/keycloak-export" | ||
|
|
||
| ensure_docker_compose || return 1 | ||
|
|
||
| [ -f "$keycloak_compose" ] && [ -d "$keycloak_export" ] || { | ||
| echo "❌ Keycloak files not found:" | ||
| echo " Expected: $keycloak_compose" | ||
| echo " Expected: $keycloak_export" | ||
| return 1 | ||
| } | ||
|
|
||
| echo "🔐 Starting Keycloak..." | ||
| cd "$cdk_dir/misc/keycloak" | ||
| docker compose -f docker-compose-recover.yml up -d || { | ||
| echo "❌ Failed to start Keycloak" | ||
| return 1 | ||
| } | ||
|
|
||
| sleep 2 | ||
| echo "📋 Monitoring Keycloak logs..." | ||
| docker compose -f docker-compose-recover.yml logs -f & | ||
| echo $! > "$DEVENV_ROOT/.cdk-mint/keycloak-logs.pid" | ||
|
|
||
| echo "✅ Keycloak started at http://127.0.0.1:8080" | ||
| } | ||
|
|
||
| cleanup() { | ||
| echo "🧹 Cleaning up..." | ||
|
|
||
| # Kill Keycloak logs if running | ||
| if [ -f "$DEVENV_ROOT/.cdk-mint/keycloak-logs.pid" ]; then | ||
| local logs_pid=$(cat "$DEVENV_ROOT/.cdk-mint/keycloak-logs.pid") | ||
| kill -0 "$logs_pid" 2>/dev/null && kill "$logs_pid" 2>/dev/null | ||
| rm -f "$DEVENV_ROOT/.cdk-mint/keycloak-logs.pid" | ||
| fi | ||
|
|
||
| # Stop Keycloak if it was started | ||
| if [ -f "$DEVENV_ROOT/.cdk-mint/keycloak-started" ]; then | ||
| echo "🔐 Stopping Keycloak..." | ||
| cd "$CDK_DIR/misc/keycloak" 2>/dev/null && docker compose -f docker-compose-recover.yml down | ||
| rm -f "$DEVENV_ROOT/.cdk-mint/keycloak-started" | ||
| fi | ||
|
|
||
| exit 0 | ||
| } | ||
|
|
||
| # Set up signal handlers for cleanup | ||
| trap cleanup SIGINT SIGTERM | ||
|
|
||
| mkdir -p "$DEVENV_ROOT/.cdk-mint" | ||
| CDK_DIR="$DEVENV_ROOT/.cdk-mint/cdk-source" | ||
|
|
||
| # Function to extract GitHub org/user from URL | ||
| get_github_remote_name() { | ||
| local url="$1" | ||
| # Extract org/user from GitHub URL (handles both https and git formats) | ||
| echo "$url" | sed -E 's|.*github\.com[:/]([^/]+)/.*|\1|' | ||
| } | ||
|
|
||
| # Check if we need to clone or update the repository | ||
| if [ ! -d "$CDK_DIR" ]; then | ||
| echo "📦 Cloning CDK repository..." | ||
| git clone "$CDK_REPO" "$CDK_DIR" | ||
| cd "$CDK_DIR" | ||
| git checkout "$CDK_REF" | ||
| else | ||
| cd "$CDK_DIR" | ||
|
|
||
| # Get the remote name based on GitHub org/user | ||
| remote_name=$(get_github_remote_name "$CDK_REPO") | ||
| current_origin=$(git remote get-url origin 2>/dev/null || echo "") | ||
|
|
||
| if [ "$current_origin" != "$CDK_REPO" ]; then | ||
| echo "🔄 Switching from $(get_github_remote_name "$current_origin") to $remote_name" | ||
|
|
||
| # Check if we already have this remote | ||
| if git remote get-url "$remote_name" &>/dev/null; then | ||
| echo "📡 Remote '$remote_name' already exists, updating URL..." | ||
| git remote set-url "$remote_name" "$CDK_REPO" | ||
| else | ||
| echo "📡 Adding new remote '$remote_name'..." | ||
| git remote add "$remote_name" "$CDK_REPO" | ||
| fi | ||
|
|
||
| # Fetch from the new remote | ||
| echo "📥 Fetching from $remote_name..." | ||
| git fetch "$remote_name" --tags | ||
|
|
||
| # Set the new remote as origin | ||
| git remote set-url origin "$CDK_REPO" | ||
|
|
||
| # Try to checkout the ref from the new remote | ||
| echo "🔄 Switching to $CDK_REF from $remote_name..." | ||
| git checkout "$CDK_REF" 2>/dev/null || { | ||
| # If the ref doesn't exist locally, try to create it from the remote | ||
| git checkout -b "$CDK_REF" "$remote_name/$CDK_REF" 2>/dev/null || { | ||
| # If it's a tag or commit, just checkout directly | ||
| git fetch "$remote_name" "$CDK_REF:$CDK_REF" 2>/dev/null || true | ||
| git checkout "$CDK_REF" | ||
| } | ||
| } | ||
| else | ||
| echo "🔄 Updating CDK repository from $remote_name..." | ||
| git fetch --all --tags | ||
| git checkout "$CDK_REF" | ||
| if git show-ref --verify --quiet "refs/heads/$CDK_REF" || git show-ref --verify --quiet "refs/remotes/origin/$CDK_REF"; then | ||
| git pull origin "$CDK_REF" 2>/dev/null || true | ||
| fi | ||
| fi | ||
| fi | ||
|
|
||
| cd "$CDK_DIR" | ||
|
|
||
| # Check if auth is enabled and start Keycloak if needed | ||
| if check_auth_enabled; then start_keycloak "$CDK_DIR" || { | ||
| echo "❌ Failed to start Keycloak. Cannot start CDK mint with auth enabled." | ||
| exit 1 | ||
| } | ||
| touch "$DEVENV_ROOT/.cdk-mint/keycloak-started" | ||
| FEATURES="auth,fakewallet" | ||
| else | ||
| FEATURES="fakewallet" | ||
| fi | ||
|
|
||
| echo "🚀 Starting CDK mint with features: $FEATURES" | ||
|
|
||
| cargo run --package cdk-mintd --features "$FEATURES" -- \ | ||
| --config "$DEVENV_ROOT/tools/devenv/cdk/cdk-mint.config.toml" \ | ||
| --work-dir "$DEVENV_ROOT/.cdk-mint" \ | ||
| 2>&1 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there has been a warning for a while that pre-commit was renamed to git-hooks