From cf0ffafa4a13773bbffe9dc78881a46923b3f294 Mon Sep 17 00:00:00 2001 From: bodymindarts Date: Mon, 23 Oct 2023 15:35:33 +0200 Subject: [PATCH] chore: initial Tiltfile --- .github/workflows/tilt.yml | 14 +++ dev/.env | 0 dev/Tiltfile | 29 ++++-- dev/bin/helpers.sh | 15 ++++ dev/bin/init-onchain.sh | 24 +++++ dev/config/bitcoind/bitcoin.conf | 19 ++++ .../bitcoind/bitcoind_signer_descriptors.json | 1 + dev/config/bria.yml | 8 ++ dev/config/fulcrum/fulcrum.conf | 7 ++ dev/config/fulcrum/tls.cert | 19 ++++ dev/config/fulcrum/tls.key | 28 ++++++ dev/config/otel-agent-config.yaml | 68 ++++++++++++++ dev/docker-compose.deps.yml | 89 +++++++++++++++++++ flake.nix | 1 + typos.toml | 1 + 15 files changed, 318 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/tilt.yml create mode 100644 dev/.env create mode 100644 dev/bin/helpers.sh create mode 100755 dev/bin/init-onchain.sh create mode 100644 dev/config/bitcoind/bitcoin.conf create mode 100644 dev/config/bitcoind/bitcoind_signer_descriptors.json create mode 100644 dev/config/bria.yml create mode 100644 dev/config/fulcrum/fulcrum.conf create mode 100644 dev/config/fulcrum/tls.cert create mode 100644 dev/config/fulcrum/tls.key create mode 100644 dev/config/otel-agent-config.yaml create mode 100644 dev/docker-compose.deps.yml diff --git a/.github/workflows/tilt.yml b/.github/workflows/tilt.yml new file mode 100644 index 00000000000..4f23f5d6e53 --- /dev/null +++ b/.github/workflows/tilt.yml @@ -0,0 +1,14 @@ +name: "Tilt CI" +on: + pull_request: + branches: [ main ] +jobs: + tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: cachix/install-nix-action@v22 + with: + github_access_token: ${{ secrets.GITHUB_TOKEN }} + - name: Tilt CI + run: nix develop -c bash -c "cd dev && tilt ci" diff --git a/dev/.env b/dev/.env new file mode 100644 index 00000000000..e69de29bb2d diff --git a/dev/Tiltfile b/dev/Tiltfile index 5de71ffe419..5872ea51b4a 100644 --- a/dev/Tiltfile +++ b/dev/Tiltfile @@ -1,7 +1,26 @@ -api_target = "//core/api:api" +docker_compose("./docker-compose.deps.yml", ".env","galoy-dev") + +groups = { + "bitcoin": [ + "bitcoind", + "bitcoind-signer", + "postgres-bria", + "fulcrum", + "bria", + ], + "tracing": [ + "otel-agent", + ], +} +for service in groups["bitcoin"]: + dc_resource(service, labels = ["bitcoin"]) + local_resource( - "api", - labels = ["frontend"], - cmd = "buck2 build {}".format(api_target), - serve_cmd = "buck2 run {}".format(api_target), + name='init-onchain', + labels = ['bitcoin'], + cmd='bin/init-onchain.sh', + resource_deps = [ + "bitcoind", + "bria", + ] ) diff --git a/dev/bin/helpers.sh b/dev/bin/helpers.sh new file mode 100644 index 00000000000..f5d069497d8 --- /dev/null +++ b/dev/bin/helpers.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +COMPOSE_PROJECT_NAME="${COMPOSE_PROJECT_NAME:-quickstart}" + +bitcoin_cli() { + docker exec "${COMPOSE_PROJECT_NAME}-bitcoind-1" bitcoin-cli "$@" +} + +bitcoin_signer_cli() { + docker exec "${COMPOSE_PROJECT_NAME}-bitcoind-signer-1" bitcoin-cli "$@" +} + +bria_cli() { + docker exec "${COMPOSE_PROJECT_NAME}-bria-1" bria "$@" +} diff --git a/dev/bin/init-onchain.sh b/dev/bin/init-onchain.sh new file mode 100755 index 00000000000..cfe1d99d677 --- /dev/null +++ b/dev/bin/init-onchain.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +set -e + +DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" +source "${DIR}/helpers.sh" + +echo "Seeding some regtest blocks..." + +bitcoin_cli createwallet "outside" || true +bitcoin_cli -generate 200 > /dev/null 2>&1 + +bitcoin_signer_cli createwallet "dev" || true +bitcoin_signer_cli -rpcwallet=dev importdescriptors "$(cat ./config/bitcoind/bitcoind_signer_descriptors.json)" + +echo "Checking that bria is running..." + +for _ in {1..20}; do + bria_cli wallet-balance -w dev-wallet && break + sleep 1 +done +bria_cli wallet-balance -w dev-wallet || exit 1 + +echo "DONE" diff --git a/dev/config/bitcoind/bitcoin.conf b/dev/config/bitcoind/bitcoin.conf new file mode 100644 index 00000000000..d04fb1b4174 --- /dev/null +++ b/dev/config/bitcoind/bitcoin.conf @@ -0,0 +1,19 @@ +rpcuser=rpcuser +rpcpassword=rpcpassword +debug=mempool +debug=rpc +server=1 +txindex=1 +printtoconsole=1 +zmqpubrawtx=tcp://0.0.0.0:28333 +zmqpubrawblock=tcp://0.0.0.0:28332 +blockfilterindex=1 +bind=0.0.0.0 +fallbackfee=0.0002 +rpcallowip=0.0.0.0/0 +regtest=1 +[regtest] +bind=0.0.0.0 +fallbackfee=0.0002 +rpcallowip=0.0.0.0/0 +rpcbind=0.0.0.0 diff --git a/dev/config/bitcoind/bitcoind_signer_descriptors.json b/dev/config/bitcoind/bitcoind_signer_descriptors.json new file mode 100644 index 00000000000..fc0a17989bd --- /dev/null +++ b/dev/config/bitcoind/bitcoind_signer_descriptors.json @@ -0,0 +1 @@ +[{"active":true,"desc":"wpkh([6f2fa1b2/84'/0'/0']tprv8gXB88g1VCScmqPp8WcetpJPRxix24fRJJ6FniYCcCUEFMREDrCfwd34zWXPiY5MW2xp8e1Z6EeBrh74zMSgfQQmTorWtE1zyBtv7yxdcoa/0/*)#88k4937c","timestamp":0},{"active":true,"desc":"wpkh([6f2fa1b2/84'/0'/0']tprv8gXB88g1VCScmqPp8WcetpJPRxix24fRJJ6FniYCcCUEFMREDrCfwd34zWXPiY5MW2xp8e1Z6EeBrh74zMSgfQQmTorWtE1zyBtv7yxdcoa/1/*)#knn5cywq","internal":true,"timestamp":0}] diff --git a/dev/config/bria.yml b/dev/config/bria.yml new file mode 100644 index 00000000000..25c27d310a6 --- /dev/null +++ b/dev/config/bria.yml @@ -0,0 +1,8 @@ +app: + blockchain: + network: regtest + electrum_url: fulcrum:50001 +tracing: + host: "otel-agent" + port: 4318 + service_name: "bria-dev" diff --git a/dev/config/fulcrum/fulcrum.conf b/dev/config/fulcrum/fulcrum.conf new file mode 100644 index 00000000000..86972588652 --- /dev/null +++ b/dev/config/fulcrum/fulcrum.conf @@ -0,0 +1,7 @@ +bitcoind = bitcoind:18443 +rpcuser = rpcuser +rpcpassword = rpcpassword +peering = false +announce = false +tcp = 0.0.0.0:50001 +ssl = 0.0.0.0:50002 diff --git a/dev/config/fulcrum/tls.cert b/dev/config/fulcrum/tls.cert new file mode 100644 index 00000000000..82f5259186f --- /dev/null +++ b/dev/config/fulcrum/tls.cert @@ -0,0 +1,19 @@ +-----BEGIN CERTIFICATE----- +MIIDBTCCAe2gAwIBAgIUKCSR4otDtA4+ow5z5zL9zc1CI10wDQYJKoZIhvcNAQEL +BQAwEjEQMA4GA1UECgwHRnVsY3J1bTAeFw0yMjExMjkxMDUzNDFaFw0zMjExMjYx +MDUzNDFaMBIxEDAOBgNVBAoMB0Z1bGNydW0wggEiMA0GCSqGSIb3DQEBAQUAA4IB +DwAwggEKAoIBAQDasNdsbz47BDEjzKLeG4RxOqMikrBY6fQd0+8pt8Fh/qSaF2lG +NpLbADDcszyddb0GD5tYQe7YBIyrexp9Q1gvejj1zuagXwlSYfrSkiDB3nBYreSl +wq4i87VjCMX5Fr270S3mHfptg5zbPgQvvTvnD0Y7Ur9lriNydWp9Qz6TLWWYVhui +yxLrtsxv6hRDndlkIxDbZt9kr6yzLroBtXFEFSCeROb1sE2ouVXC89eAlcpvWZF6 +MMnlAkECRS5m3QtKyYtTQ0FTGBrAN2xUnirR9z+wpAOu3S/AjEt4AC1ome75tiJv +rtCIaf438QhNerb/sQmyHXIpjw6KZxADKS3RAgMBAAGjUzBRMB0GA1UdDgQWBBS0 +xHEskJjxCg8F1YYT0NkzBVFsTDAfBgNVHSMEGDAWgBS0xHEskJjxCg8F1YYT0Nkz +BVFsTDAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQCwxhxRCfa1 +DXfFP+BM9OwDldNC9B66d/6hueaY26YJxcLvuKcAm+0MwciNFnWhb9yiY2wnWaZ6 +zA6VKuxCrVU7egg5gG2+lZYjAiQOkFtVNHGEIjVTow4GJAkJGjH/B9J2teHKR1a6 +XDJ5xKLAIM7hnKVjIM7cA/Y3Q/AsR/uzp4GOccqHX3g/AKKLFahLCkVv5CeIrl+y +kPv/3jXbP71iJPhG2j74EVPLeQ0qKAb03vz2Y2HaSBripGQEwnx7MoQnbRhYx00Y ++LG1WGYeNOEXfT8trewl+gfsoLenlDTLukIfjjvQ5dRDA9pD1ij+1+jz/XCyQ7w5 +LzhYnJBwIGpt +-----END CERTIFICATE----- diff --git a/dev/config/fulcrum/tls.key b/dev/config/fulcrum/tls.key new file mode 100644 index 00000000000..d2d9c6affd6 --- /dev/null +++ b/dev/config/fulcrum/tls.key @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDasNdsbz47BDEj +zKLeG4RxOqMikrBY6fQd0+8pt8Fh/qSaF2lGNpLbADDcszyddb0GD5tYQe7YBIyr +exp9Q1gvejj1zuagXwlSYfrSkiDB3nBYreSlwq4i87VjCMX5Fr270S3mHfptg5zb +PgQvvTvnD0Y7Ur9lriNydWp9Qz6TLWWYVhuiyxLrtsxv6hRDndlkIxDbZt9kr6yz +LroBtXFEFSCeROb1sE2ouVXC89eAlcpvWZF6MMnlAkECRS5m3QtKyYtTQ0FTGBrA +N2xUnirR9z+wpAOu3S/AjEt4AC1ome75tiJvrtCIaf438QhNerb/sQmyHXIpjw6K +ZxADKS3RAgMBAAECggEBAJB5g9f/Jf2XJ1+fMXnKdBTZyCxu/FHBPaT2/mlxHDDB +Kb0i+kmIhDxqQ92KC+F6hwYaCWalKEVNvCENktJuSzQSas75gSMxpdbnI+043Ks3 +aMEtIIDhvGka2Bo1EZUdkPsjlk8QPwFakaXFsr5XJdvgG2XVpNxnzsMvDsryQcS4 +X+foFXR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otel-agent-config.yaml b/dev/config/otel-agent-config.yaml new file mode 100644 index 00000000000..ed63c329778 --- /dev/null +++ b/dev/config/otel-agent-config.yaml @@ -0,0 +1,68 @@ +receivers: + jaeger: + protocols: + thrift_compact: # on port 6831 + thrift_binary: # on port 6832 + otlp: + protocols: + http: # on port 4318 + +processors: + filter/ottl: + error_mode: ignore + traces: + span: + - 'resource.attributes["service.name"] == "stablesats-dev"' + - 'resource.attributes["service.name"] == "bria-dev"' + - 'name == "grpc.lnrpc.State/GetState"' + - 'name == "app.prices.getCurrentSatPrice"' + - 'name == "app.prices.getCurrentUsdCentPrice"' + - 'name == "grpc.PriceFeed/GetPrice"' + - 'name == "grpc.PriceFeed/ListCurrencies"' + - 'name == "services.cache.local.set"' + - 'name == "services.cache.local.get"' + - 'name == "app.prices.listCurrencies"' + - 'name == "services.cache.local.getOrSet"' + batch: + attributes: + actions: + - key: graphql.variables.input.code + action: update + value: "" + - key: code.function.params.code + action: update + value: "" + - key: code.function.params.authToken + action: update + value: "" + - key: code.function.params.totpCode + action: update + value: "" + - key: graphql.variables.input.totpCode + action: update + value: "" + - key: graphql.variables.input.authToken + action: update + value: "" + +exporters: + logging: + loglevel: debug + otlp: + endpoint: "api.honeycomb.io:443" + headers: + "x-honeycomb-team": ${HONEYCOMB_API_KEY} + "x-honeycomb-dataset": ${HONEYCOMB_DATASET} + +extensions: + health_check: + pprof: + zpages: + +service: + extensions: [health_check, pprof, zpages] + pipelines: + traces: + receivers: [jaeger, otlp] + processors: [filter/ottl, attributes, batch] + exporters: [otlp, logging] diff --git a/dev/docker-compose.deps.yml b/dev/docker-compose.deps.yml new file mode 100644 index 00000000000..9d1f8e58c58 --- /dev/null +++ b/dev/docker-compose.deps.yml @@ -0,0 +1,89 @@ +--- +version: "3" +services: + mongodb: + image: mongo:7.0.2 + ports: + - "27017:27017" + environment: + - MONGO_INITDB_DATABASE=galoy + bria: + image: us.gcr.io/galoy-org/bria:latest + ports: + - "2743:2743" + - "2742:2742" + environment: + - PG_CON=postgres://user:password@postgres-bria:5432/pg + - BITCOIND_SIGNER_ENDPOINT=https://bitcoind-signer:18443 + command: + - bria + - daemon + - --config + - /bria.yml + - dev + - -x + - tpubDDDDGYiFda8HfJRc2AHFJDxVzzEtBPrKsbh35EaW2UGd5qfzrF2G87ewAgeeRyHEz4iB3kvhAYW1sH6dpLepTkFUzAktumBN8AXeXWE9nd1 + - -d + - m/84h/0h/0h + volumes: + - ${HOST_PROJECT_PATH:-.}/config/bria.yml:/bria.yml + depends_on: + bitcoind-signer: + condition: service_started + otel-agent: + condition: service_started + fulcrum: + condition: service_started + postgres-bria: + condition: service_healthy + postgres-bria: + image: postgres:14.1 + environment: + - POSTGRES_USER=user + - POSTGRES_PASSWORD=password + - POSTGRES_DB=pg + healthcheck: + test: ["CMD-SHELL", "pg_isready"] + interval: 5s + timeout: 30s + retries: 5 + fulcrum: + image: cculianu/fulcrum:latest + ports: + - "50001:50001" + depends_on: [bitcoind] + volumes: + - ${HOST_PROJECT_PATH:-.}/config/fulcrum/fulcrum.conf:/fulcrum.conf + - ${HOST_PROJECT_PATH:-.}/config/fulcrum/tls.key:/tls.key + - ${HOST_PROJECT_PATH:-.}/config/fulcrum/tls.cert:/tls.cert + environment: + - DATA_DIR=/db + - SSL_CERTFILE=/tls.cert + - SSL_KEYFILE=/tls.key + command: ["Fulcrum", "/fulcrum.conf"] + bitcoind: + image: lncm/bitcoind:v24.0.1 + ports: + - "18443:18443" + volumes: + - ${HOST_PROJECT_PATH:-.}/config/bitcoind/bitcoin.conf:/data/.bitcoin/bitcoin.conf + bitcoind-signer: + image: lncm/bitcoind:v24.0.1 + ports: [] + volumes: + - ${HOST_PROJECT_PATH:-.}/config/bitcoind/bitcoin.conf:/data/.bitcoin/bitcoin.conf + depends_on: [bitcoind] + entrypoint: ["/bin/sh", "-c"] + command: + - | + bitcoind -connect=bitcoind:18444 + otel-agent: + ports: + - "4318:4318" #! http receiver + image: otel/opentelemetry-collector-contrib:0.84.0 + command: ["--config=/etc/otel-agent-config.yaml"] + environment: + - HONEYCOMB_DATASET=${HONEYCOMB_DATASET} + - HONEYCOMB_API_KEY=${HONEYCOMB_API_KEY} + volumes: + - ${HOST_PROJECT_PATH:-.}/config/otel-agent-config.yaml:/etc/otel-agent-config.yaml diff --git a/flake.nix b/flake.nix index de89dba6630..fb87c3a649b 100644 --- a/flake.nix +++ b/flake.nix @@ -168,6 +168,7 @@ devShells.default = mkShell { inherit nativeBuildInputs; BUCK2_VERSION = buck2Version; + COMPOSE_PROJECT_NAME = "galoy-dev"; }; formatter = alejandra; diff --git a/typos.toml b/typos.toml index f342bab6b00..55de1a6a23c 100644 --- a/typos.toml +++ b/typos.toml @@ -1,4 +1,5 @@ files.extend-exclude = [ + "dev/config", "core/api/dev", "core/api/src/domain/users/languages.ts", "core/api/src/services/loopd/protos",