From 35a4be1429c46c54dbe1a495f5b8375cd90b6140 Mon Sep 17 00:00:00 2001 From: thesimplekid Date: Tue, 23 Sep 2025 14:23:06 +0100 Subject: [PATCH] feat(docker): add LDK Node mint service with dedicated Docker setup (#1108) * feat(docker): add LDK Node mint service with dedicated Docker setup - Add Dockerfile.ldk-node and Dockerfile.ldk-node.arm for LDK Node builds - Add GitHub Actions workflows for publishing LDK Node Docker images - Add docker-compose.ldk-node.yaml for standalone LDK Node deployment - Integrate LDK Node service into main docker-compose.yaml with profile - Update cdk-mintd README with LDK Node Docker configuration * feat: use docker tags --- .../workflows/docker-publish-ldk-node-arm.yml | 62 +++++++++ .github/workflows/docker-publish-ldk-node.yml | 62 +++++++++ Dockerfile | 2 +- Dockerfile.arm | 2 +- Dockerfile.ldk-node | 40 ++++++ Dockerfile.ldk-node.arm | 43 +++++++ crates/cdk-mintd/README.md | 47 +++++++ docker-compose.ldk-node.yaml | 118 ++++++++++++++++++ docker-compose.yaml | 39 ++++++ 9 files changed, 413 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/docker-publish-ldk-node-arm.yml create mode 100644 .github/workflows/docker-publish-ldk-node.yml create mode 100644 Dockerfile.ldk-node create mode 100644 Dockerfile.ldk-node.arm create mode 100644 docker-compose.ldk-node.yaml diff --git a/.github/workflows/docker-publish-ldk-node-arm.yml b/.github/workflows/docker-publish-ldk-node-arm.yml new file mode 100644 index 00000000..9b388108 --- /dev/null +++ b/.github/workflows/docker-publish-ldk-node-arm.yml @@ -0,0 +1,62 @@ +name: Publish Docker Image LDK Node ARM64 + +on: + release: + types: [published] + workflow_dispatch: + inputs: + tag: + description: 'Tag to build and publish' + required: true + default: 'latest' + +env: + REGISTRY: docker.io + IMAGE_NAME: cashubtc/mintd + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=ldk-node-arm64,enable=${{ github.event_name == 'release' }} + type=semver,pattern={{version}}-ldk-node-arm64 + type=semver,pattern={{major}}.{{minor}}-ldk-node-arm64 + type=ref,event=branch,suffix=-ldk-node-arm64 + type=ref,event=pr,suffix=-ldk-node-arm64 + type=sha,suffix=-ldk-node-arm64 + ${{ github.event.inputs.tag != '' && format('{0}-ldk-node-arm64', github.event.inputs.tag) || '' }} + + # Build and push ARM64 image with architecture suffix + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + platforms: linux/arm64 + file: ./Dockerfile.ldk-node.arm + tags: ${{ steps.meta.outputs.tags }}-arm64 + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/docker-publish-ldk-node.yml b/.github/workflows/docker-publish-ldk-node.yml new file mode 100644 index 00000000..7ef2b505 --- /dev/null +++ b/.github/workflows/docker-publish-ldk-node.yml @@ -0,0 +1,62 @@ +name: Publish Docker Image LDK Node AMD64 + +on: + release: + types: [published] + workflow_dispatch: + inputs: + tag: + description: 'Tag to build and publish' + required: true + default: 'latest' + +env: + REGISTRY: docker.io + IMAGE_NAME: cashubtc/mintd + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=ldk-node,enable=${{ github.event_name == 'release' }} + type=semver,pattern={{version}}-ldk-node + type=semver,pattern={{major}}.{{minor}}-ldk-node + type=ref,event=branch,suffix=-ldk-node + type=ref,event=pr,suffix=-ldk-node + type=sha,suffix=-ldk-node + ${{ github.event.inputs.tag != '' && format('{0}-ldk-node', github.event.inputs.tag) || '' }} + + # Build and push AMD64 image with architecture suffix + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile.ldk-node + push: true + platforms: linux/amd64 + tags: ${{ steps.meta.outputs.tags }}-amd64 + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile index b4359169..ed06de19 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ COPY Cargo.toml ./Cargo.toml COPY crates ./crates # Start the Nix daemon and develop the environment -RUN nix develop --extra-experimental-features nix-command --extra-experimental-features flakes --command cargo build --release --bin cdk-mintd --features redis --features prometheus +RUN nix develop --extra-experimental-features nix-command --extra-experimental-features flakes --command cargo build --release --bin cdk-mintd --features postgres --features prometheus # Create a runtime stage FROM debian:trixie-slim diff --git a/Dockerfile.arm b/Dockerfile.arm index 90100762..f256cf73 100644 --- a/Dockerfile.arm +++ b/Dockerfile.arm @@ -13,7 +13,7 @@ COPY crates ./crates RUN echo 'filter-syscalls = false' > /etc/nix/nix.conf # Start the Nix daemon and develop the environment -RUN nix develop --extra-platforms aarch64-linux --extra-experimental-features nix-command --extra-experimental-features flakes --command cargo build --release --bin cdk-mintd --features redis +RUN nix develop --extra-platforms aarch64-linux --extra-experimental-features nix-command --extra-experimental-features flakes --command cargo build --release --bin cdk-mintd --features postgres # Create a runtime stage FROM debian:trixie-slim diff --git a/Dockerfile.ldk-node b/Dockerfile.ldk-node new file mode 100644 index 00000000..dd825018 --- /dev/null +++ b/Dockerfile.ldk-node @@ -0,0 +1,40 @@ +# Use the official NixOS image as the base image +FROM nixos/nix:latest AS builder + +# Set the working directory +WORKDIR /usr/src/app + +# Copy workspace files and crates directory into the container +COPY flake.nix ./flake.nix +COPY Cargo.toml ./Cargo.toml +COPY crates ./crates + +# Start the Nix daemon and develop the environment +RUN nix develop --extra-experimental-features nix-command --extra-experimental-features flakes --command cargo build --release --bin cdk-mintd --features ldk-node --features prometheus --features postgres + +# Create a runtime stage +FROM debian:trixie-slim + +# Set the working directory +WORKDIR /usr/src/app + +# Install needed runtime dependencies (if any) +RUN apt-get update && \ + apt-get install -y --no-install-recommends patchelf && \ + rm -rf /var/lib/apt/lists/* + +# Copy the built application from the build stage +COPY --from=builder /usr/src/app/target/release/cdk-mintd /usr/local/bin/cdk-mintd + +# Detect the architecture and set the interpreter accordingly +RUN ARCH=$(uname -m) && \ + if [ "$ARCH" = "aarch64" ]; then \ + patchelf --set-interpreter /lib/ld-linux-aarch64.so.1 /usr/local/bin/cdk-mintd; \ + elif [ "$ARCH" = "x86_64" ]; then \ + patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 /usr/local/bin/cdk-mintd; \ + else \ + echo "Unsupported architecture: $ARCH"; exit 1; \ + fi + +# Set the entry point for the container +CMD ["cdk-mintd"] diff --git a/Dockerfile.ldk-node.arm b/Dockerfile.ldk-node.arm new file mode 100644 index 00000000..2cb42be7 --- /dev/null +++ b/Dockerfile.ldk-node.arm @@ -0,0 +1,43 @@ +# Use the official NixOS image as the base image +FROM nixos/nix:latest AS builder + +# Set the working directory +WORKDIR /usr/src/app + +# Copy workspace files and crates directory into the container +COPY flake.nix ./flake.nix +COPY Cargo.toml ./Cargo.toml +COPY crates ./crates + +# Create a nix config file to disable syscall filtering +RUN echo 'filter-syscalls = false' > /etc/nix/nix.conf + +# Start the Nix daemon and develop the environment +RUN nix develop --extra-platforms aarch64-linux --extra-experimental-features nix-command --extra-experimental-features flakes --command cargo build --release --bin cdk-mintd --features ldk-node --features prometheus --features postgres + +# Create a runtime stage +FROM debian:trixie-slim + +# Set the working directory +WORKDIR /usr/src/app + +# Install needed runtime dependencies (if any) +RUN apt-get update && \ + apt-get install -y --no-install-recommends patchelf && \ + rm -rf /var/lib/apt/lists/* + +# Copy the built application from the build stage +COPY --from=builder /usr/src/app/target/release/cdk-mintd /usr/local/bin/cdk-mintd + +# Detect the architecture and set the interpreter accordingly +RUN ARCH=$(uname -m) && \ + if [ "$ARCH" = "aarch64" ]; then \ + patchelf --set-interpreter /lib/ld-linux-aarch64.so.1 /usr/local/bin/cdk-mintd; \ + elif [ "$ARCH" = "x86_64" ]; then \ + patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 /usr/local/bin/cdk-mintd; \ + else \ + echo "Unsupported architecture: $ARCH"; exit 1; \ + fi + +# Set the entry point for the container +CMD ["cdk-mintd"] diff --git a/crates/cdk-mintd/README.md b/crates/cdk-mintd/README.md index e72149f1..fcb189c7 100644 --- a/crates/cdk-mintd/README.md +++ b/crates/cdk-mintd/README.md @@ -151,6 +151,53 @@ After setup and first run, your directory will look like: - Log directories and files - Lightning backend data directories +## Docker Usage + +CDK Mintd provides ready-to-use Docker images with multiple Lightning backend options. + +### Quick Start + +#### Standard mint with fakewallet backend (testing only): +```bash +docker-compose up +``` + +#### Mint with LDK Node backend: +```bash +# Option 1: Use dedicated ldk-node compose file +docker-compose -f docker-compose.ldk-node.yaml up + +# Option 2: Use main compose file with profile +docker-compose --profile ldk-node up +``` + +### Available Images + +- **`cashubtc/mintd:latest`** - Standard mint with default features +- **`cashubtc/mintd-ldk-node:latest`** - Mint with LDK Node support + +### Configuration via Environment Variables + +All configuration can be done through environment variables: + +```yaml +environment: + - CDK_MINTD_LN_BACKEND=ldk-node + - CDK_MINTD_DATABASE=sqlite + - CDK_MINTD_LISTEN_HOST=0.0.0.0 + - CDK_MINTD_LISTEN_PORT=8085 + - CDK_MINTD_LDK_NODE_NETWORK=testnet + - CDK_MINTD_LDK_NODE_ESPLORA_URL=https://blockstream.info/testnet/api +``` + +### Monitoring + +Both Prometheus metrics and Grafana dashboards are included: +- Prometheus: http://localhost:9090 +- Grafana: http://localhost:3011 (admin/admin) + +For detailed Docker documentation, see [README-ldk-node.md](../../README-ldk-node.md). + ## Testing Your Mint 1. **Verify the mint is running**: diff --git a/docker-compose.ldk-node.yaml b/docker-compose.ldk-node.yaml new file mode 100644 index 00000000..c46430a4 --- /dev/null +++ b/docker-compose.ldk-node.yaml @@ -0,0 +1,118 @@ +version: '3.8' + +services: + # CDK Mint service with LDK Node backend + + prometheus: + image: prom/prometheus:latest + ports: + - "9090:9090" + volumes: + - ./misc/provisioning/prometheus.yml:/etc/prometheus/prometheus.yml:ro + command: + - '--config.file=/etc/prometheus/prometheus.yml' + - '--storage.tsdb.path=/prometheus' + - '--web.console.libraries=/etc/prometheus/console_libraries' + - '--web.console.templates=/etc/prometheus/consoles' + - '--web.enable-lifecycle' + - '--enable-feature=otlp-write-receiver' + extra_hosts: + - "host.docker.internal:host-gateway" + networks: + - cdk + + # Grafana for visualization + grafana: + image: grafana/grafana:latest + ports: + - "3011:3000" + volumes: + - ./misc/provisioning/datasources:/etc/grafana/provisioning/datasources + - ./misc/provisioning/dashboards:/etc/grafana/provisioning/dashboards + environment: + - GF_DASHBOARDS_JSON_ENABLED=true + - GF_SECURITY_ADMIN_PASSWORD=admin + - GF_PROVISIONING_PATHS=/etc/grafana/provisioning + networks: + - cdk + + mintd-ldk-node: + # Use the ldk-node tagged image from the same repository + image: cashubtc/mintd:ldk-node-amd64 + # Alternatively, build locally: + # build: + # context: . + # dockerfile: Dockerfile.ldk-node + container_name: mint-ldk-node + ports: + - "8085:8085" + environment: + - CDK_MINTD_URL=https://example.com + - CDK_MINTD_LN_BACKEND=ldk-node + - CDK_MINTD_LISTEN_HOST=0.0.0.0 + - CDK_MINTD_LISTEN_PORT=8085 + - CDK_MINTD_MNEMONIC= + # Database configuration - choose one: + # Option 1: SQLite (embedded, no additional setup needed) + - CDK_MINTD_DATABASE=sqlite + # Option 2: ReDB (embedded, no additional setup needed) + # - CDK_MINTD_DATABASE=redb + # Option 3: PostgreSQL (requires postgres service, enable with: docker-compose --profile postgres up) + # - CDK_MINTD_DATABASE=postgres + # - CDK_MINTD_DATABASE_URL=postgresql://cdk_user:cdk_password@postgres:5432/cdk_mint + # Cache configuration + - CDK_MINTD_CACHE_BACKEND=memory + - CDK_MINTD_PROMETHEUS_ENABLED=true + - CDK_MINTD_PROMETHEUS_ADDRESS=0.0.0.0 + - CDK_MINTD_PROMETHEUS_PORT=9000 + # LDK Node specific configuration + - CDK_MINTD_LDK_NODE_NETWORK=testnet + - CDK_MINTD_LDK_NODE_ESPLORA_URL=https://blockstream.info/testnet/api + - CDK_MINTD_LDK_NODE_LISTENING_ADDRESSES=0.0.0.0:9735 + volumes: + # Persist LDK node data + - ldk_node_data:/usr/src/app/ldk_node_data + command: ["cdk-mintd"] + depends_on: + - prometheus + - grafana + networks: + - cdk + # Uncomment when using PostgreSQL: + # depends_on: + # - postgres + + # PostgreSQL database service + # Enable with: docker-compose --profile postgres up + postgres: + image: postgres:16-alpine + container_name: mint_postgres + restart: unless-stopped + profiles: + - postgres + environment: + - POSTGRES_USER=cdk_user + - POSTGRES_PASSWORD=cdk_password + - POSTGRES_DB=cdk_mint + - POSTGRES_INITDB_ARGS=--encoding=UTF-8 --lc-collate=C --lc-ctype=C + ports: + - "5432:5432" + volumes: + - postgres_data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U cdk_user -d cdk_mint"] + interval: 10s + timeout: 5s + retries: 5 + networks: + - cdk + +volumes: + postgres_data: + driver: local + ldk_node_data: + driver: local + +networks: + cdk: + driver: bridge diff --git a/docker-compose.yaml b/docker-compose.yaml index f405d984..9a976894 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -71,6 +71,43 @@ services: # depends_on: # - postgres + # LDK Node mint service - enable with: docker-compose --profile ldk-node up + mintd-ldk-node: + build: + context: . + dockerfile: Dockerfile.ldk-node + container_name: mint-ldk-node + profiles: + - ldk-node + ports: + - "8086:8085" # Different port to avoid conflict with main mint + environment: + - CDK_MINTD_URL=https://example.com + - CDK_MINTD_LN_BACKEND=ldk-node + - CDK_MINTD_LISTEN_HOST=0.0.0.0 + - CDK_MINTD_LISTEN_PORT=8085 + - CDK_MINTD_MNEMONIC= + # Database configuration + - CDK_MINTD_DATABASE=sqlite + # Cache configuration + - CDK_MINTD_CACHE_BACKEND=memory + - CDK_MINTD_PROMETHEUS_ENABLED=true + - CDK_MINTD_PROMETHEUS_ADDRESS=0.0.0.0 + - CDK_MINTD_PROMETHEUS_PORT=9000 + # LDK Node specific configuration + - CDK_MINTD_LDK_NODE_NETWORK=testnet + - CDK_MINTD_LDK_NODE_ESPLORA_URL=https://blockstream.info/testnet/api + - CDK_MINTD_LDK_NODE_LISTENING_ADDRESSES=0.0.0.0:9735 + volumes: + # Persist LDK node data + - ldk_node_data:/usr/src/app/ldk_node_data + command: ["cdk-mintd"] + depends_on: + - prometheus + - grafana + networks: + - cdk + # PostgreSQL database service # Enable with: docker-compose --profile postgres up # postgres: @@ -99,6 +136,8 @@ services: volumes: postgres_data: driver: local + ldk_node_data: + driver: local networks: cdk: