8000 feat: auto-stack compatible with upgraded node by outerlook · Pull Request #907 · trufnetwork/node · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: auto-stack compatible with upgraded node #907

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

Merged
merged 34 commits into from
May 2, 2025

Conversation

outerlook
Copy link
Contributor
@outerlook outerlook commented Apr 28, 2025

Summary of Infrastructure Refactoring

I apologize for the size of this PR, but some of those changes were hard to test individually, but with this I could get to a working state

Many of these files being changed are about renames: tsn -> tn which was all over infrastructure

This PR introduces a major refactoring of the infrastructure deployment (deployments/infra), focusing on abstraction, improved configuration management, and updated tooling alignment.

Key Changes:

  1. Abstraction & Reusability: Introduced higher-level CDK constructs (ValidatorSet, KwilCluster, Fronting, GoAsset, Renderer) for better maintainability. The heavy lifting done here should simplify future development, particularly for the TN-From-Config-Stack.
  2. Configuration Management:
    • Migrated from CloudFormation parameters to CDK context variables (e.g., stage, devPrefix, frontingType) to be more transparent to manage.
    • Implemented Go templating (scripts/renderer) for EC2 user-data and kwild config files, replacing hardcoded scripts/logic, addressing maintainability pain points.
    • Updated kwil-network utilities to generate peer info and a single genesis asset, aligning with templated node configuration.
  3. Fronting Mechanism: Abstracted the edge proxy layer (Fronting construct).
    • The previous CloudFront setup primarily provided TLS termination without leveraging caching benefits. It was also very slow to deploy and iterate on.
    • The abstraction makes it easier to switch to alternatives like ALB (for high, steady throughput) or CloudFront (for global caching) if needed later. But now we default to HTTP API Gateway that scales to zero.
  4. Binary Handling: KGW/Indexer binaries are now expected externally (e.g., S3 assets) instead of being downloaded during their respective Docker image builds. The GoAsset construct bundles Go application binaries.
  5. Kwil Network Generation: Aligned key generation (kwild key gen) and genesis creation (kwild setup init) with kwild v0.10.2, including db_owner and leader fields.
  6. Observer Integration: Refactored observer attachment (lib/observer) using templates and integrating with new constructs.
  7. General: Renamed components "TSN" to "TN". Updated dependencies, tests, ignore files, Taskfile.yml, compose.yaml, and documentation. Added helper utilities (lib/utils). Removed outdated code/constructs related to previous deployment methods. Updated SQL migration (003-primitive-insertion.sql). Updated binary download script (scripts/download-binaries.sh).

Related Problem

How Has This Been Tested?

  • Added new unit tests for the renderer package, config/node, config/domain, Go asset bundling, and fronting kind parsing.
  • Updated integration tests for kwil-network utilities (node key generation, genesis file generation).
  • Manually deployed the TN-DB-Auto-dev-Stack using the command:
    CHAIN_ID=trufnetwork-dev DB_OWNER="0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf" SESSION_SECRET=abab CDK_DOCKER="./buildx.sh
    10000
    " KWILD_CLI_PATH=$(which kwild) INCLUDE_OBSERVER=false cdk deploy TN-DB-Auto-dev-Stack TN-Cert-dev-Stack --profile truflation-gh --exclusively --context numOfNodes=2 --context stage=dev --context devPrefix=dev --context stackSuffix=dev --context frontingType=api
  • Verified successful stack deployment and instance startup.
  • Executed a basic migration against the deployed API Gateway endpoint using task action-migrate-dev.
  • Known Issue: Encountered a "no cookies found" error when testing SDK interactions against the deployed gateway, requiring further investigation in a subsequent effort. The core infrastructure deployment and migration functionality appear correct.

This commit updates various files to replace references from TSN to TN, reflecting the new naming convention. Changes include modifications in the CDK setup, README.md, and benchmark documentation. Additionally, new constructs for TN have been introduced, and existing configurations have been refined for clarity and consistency. The changes aim to ensure a cohesive transition to the TN naming scheme across the codebase.
…figuration

This commit modifies the CDK context file to update hosted zone configurations, reflecting changes in domain names. Additionally, it adjusts asset paths in various Go files to ensure correct directory structures for building and deploying assets. The changes aim to enhance clarity and maintainability in the deployment setup.
This commit updates the CDK context file by removing the entry for the hosted zone associated with the domain `tsn.test.truflation.com`. The change aims to streamline the configuration and reflect the current deployment setup accurately.
…Taskfile.yml

This commit introduces the `DB_OWNER` environment variable in the `compose` and `compose:down` tasks for improved configuration consistency. Additionally, it adds a new task `action-migrate-dev` to run SQL migrations in the development environment, enhancing the deployment workflow.
@outerlook outerlook changed the base branch from main to refactor/node-2.0 April 28, 2025 18:43
This commit introduces a new fronting mechanism for API routing and TLS termination using AWS API Gateway. It includes the implementation of the `ApiGatewayFronting` construct, which provisions an HTTP API and integrates it with the existing KGW and Indexer services. Additionally, it adds support for regional ACM certificates, enhancing the deployment flexibility. The README.md is updated to reflect the new fronting options and usage instructions, ensuring clarity for developers on how to configure and deploy the new fronting setup.
This commit adds a new `FrontingSelector` construct that dynamically determines the desired fronting type (API, CloudFront, or ALB) based on a CloudFormation parameter. It enhances the existing deployment logic in `cdk_main.go` by replacing hardcoded fronting type checks with a more flexible approach. Additionally, it updates the `AttachRoutes` methods in the ALB and CloudFront constructs to return a `FrontingResult`, indicating unimplemented features. New tests for the `ParseKind` function ensure robust validation of fronting types.
This commit refactors the `cdk_main.go` file to create the `CertStack` unconditionally, allowing stacks to utilize it based on their internal logic. It also updates the `FrontingSelector` to directly return the fronting kind without additional validation steps. Furthermore, it introduces a new `kwild-config.tmpl` file for configuration management and adds tests for the rendering of this template. The `go.mod` and `go.sum` files are updated to include new dependencies and versions, ensuring compatibility and improved functionality across the codebase.
… certificate management

This commit introduces several enhancements across the fronting constructs. It updates the `fronting_selector.go` to utilize `ParseKind` for validating fronting types, ensuring robust error handling. The `domain_config.go` file adds a new method for generating fully-qualified subdomains. The `default_provider.go` now supports additional Subject Alternative Names (SANs) for certificates, improving flexibility in domain management. Furthermore, the `cert_manager.go` introduces a shared certificate management utility, allowing multiple services to share a single certificate efficiently. The `api_gateway.go` and `kwil_cluster.go` files are updated to reflect these changes, ensuring seamless integration of the new features. Additionally, the `ingress_rules` logic is centralized in a new utility, enhancing maintainability and clarity in security group configurations.
… S3 assets

This commit adds the `goasset` package, which provides a standardized way to bundle Go applications and test binaries into AWS CDK S3 assets using local Go build commands. It includes the `Bundle` and `BundleDir` functions for flexible asset creation, along with comprehensive validation and logging features. Additionally, a test suite is introduced to ensure the functionality of the bundling process, covering various scenarios including successful builds, syntax error handling, and validation of input options. The README.md is also added to document usage and configuration options for developers.
This commit refines the startup scripts for the Kwil Gateway and Indexer by implementing error handling for Docker installation and configuration scripts. It introduces a new `WrapAsFile` utility to encapsulate script content into executable files, improving maintainability. Additionally, it integrates template rendering for various scripts, ensuring a more structured and readable approach to generating shell commands. The `go.mod` and `go.sum` files are updated to include new dependencies for template rendering, enhancing the overall functionality and robustness of the deployment scripts.
This commit introduces a new approach for managing the fronting type in the CDK setup. It adds the "frontingType" parameter to the CDK context, allowing for dynamic selection of fronting types (defaulting to "api"). The `GetFrontingKind` function is implemented to read and validate this parameter, enhancing error handling. Additionally, the `TnAutoStack` and `TnFromConfigStack` files are updated to utilize the new context helper for retrieving the selected fronting kind, streamlining the stack configuration process.
…eneration

This commit introduces the `DbOwner` field to the `AutoStackEnvironmentVariables` and `GenerateGenesisFileInput` structures, ensuring that the database owner can be specified during genesis file generation. It updates the `GenerateGenesisFile` function to include the `DbOwner` parameter in the command execution for the kwild CLI. Additionally, a new test file is added to validate the genesis file generation process, along with a corresponding golden file for snapshot testing. The `KwilNetworkConfigAssetsFromNumberOfNodes` function is also updated to handle the new `DbOwner` and `GenesisFilePath` inputs, improving the overall configuration flexibility in the network setup.
This commit introduces the `SessionSecret` field to the `MainEnvironmentVariables` structure, improving the management of environment variables. It also refactors the `NewNode` function to accept a `NewNodeInput` struct, consolidating parameters for better readability and maintainability. Additionally, the `BuildTNAssets` function is updated to adjust the directory structure for Docker image assets, ensuring correct asset packaging. The changes enhance the overall configuration flexibility and clarity in the deployment process.
This commit updates the deployment configuration to read the `stage` and `devPrefix` values from the CDK context instead of CloudFormation parameters. It introduces new functions `GetStage` and `GetDevPrefix` for retrieving these values, enhancing type safety and validation. The changes streamline the deployment process and improve the overall clarity of the configuration management across various stacks and constructs.
This commit refactors the `KwilAssetOptions` structure to improve clarity by renaming fields for better understanding. It updates the `BuildKwilAssets` function to utilize the new field names. Additionally, it enhances the `NodeKeys` struct to reflect changes in key generation, including renaming and removing unnecessary fields. The integration tests for node key generation are introduced to validate the updated structure and functionality. Furthermore, various test files are updated to align with the new field names, ensuring consistency across the codebase.
This commit introduces automatic provisioning of EC2 instances for the Kwil Gateway and Indexer within the `TnAutoStack`, improving deployment efficiency. It also updates the `README.md` to clarify the deployment process, specifying the automatic provisioning behavior for different stacks. Additionally, a new context variable `stackSuffix` is added to enhance stack naming flexibility, and the `indexer_startup_scripts.go` file is refactored to remove unnecessary environment variable references, streamlining the configuration. These changes enhance clarity and maintainability across the deployment infrastructure.
This commit updates the `GetSharedCertProps` function in `cert_manager.go` to accept fully qualified domain names (FQDNs) instead of simple record names, improving clarity and error handling. It adds validation to ensure the input FQDNs end with the expected zone suffix. Additionally, it modifies the Docker configuration in `tn_startup_scripts.go` to correct the data root path and refines the template rendering in `configure_docker.sh.tmpl` for better formatting. The `validator_set.go` file is updated to grant pull access to the TN Docker image repository, enhancing asset management. These changes improve the overall robustness and maintainability of the deployment infrastructure.
…ndering

This commit enhances the `AutoStackEnvironmentVariables` structure by adding comments to clarify the purpose of the `IncludeObserver` and `DbOwner` fields. Additionally, it modifies the `tn_db_startup.sh.tmpl` and `TestGoldenTnScript.golden` files to prevent quoting of environment variable values, ensuring compatibility with Docker Compose. These changes improve the clarity and functionality of the deployment scripts and environment variable management.
…ialization

This commit modifies the `kwild-config.tmpl` file to streamline the configuration structure by removing redundant sections and adding a new P2P and consensus configuration block. It also introduces a temporary directory for initialization files in the `tn_instance.go` file, ensuring that configuration and genesis files are handled more effectively during the EC2 instance setup. These changes improve the clarity and organization of the deployment configuration, enhancing overall maintainability.
This commit introduces a new structure for managing node keys, allowing for the inclusion of private key hex and key type in the `NewNodeInput` struct. It updates the `newNode` function to generate a `nodekey.json` file containing these details, ensuring secure handling of node keys during EC2 instance initialization. Additionally, the genesis file generation process is improved by modifying the validator structure to include the key type, enhancing the overall configuration and security of the network setup. These changes streamline the deployment process and improve maintainability.
This commit modifies the `gateway-compose.yaml` file to change the build context and Dockerfile path for the gateway service, enhancing the deployment structure. It also adds a new volume binding for the `KGW_BINARY_PATH`, ensuring that the binary is correctly mapped to the container. These changes improve the clarity and maintainability of the Docker configuration.
… and indexer services

This commit modifies the `dev-gateway-compose.yaml` and `dev-indexer-compose.yaml` files to change the build context and Dockerfile paths, enhancing the deployment structure. It also adds volume bindings for `KGW_BINARY_PATH` and `INDEXER_BINARY_PATH`, ensuring that the binaries are correctly mapped to the containers. Additionally, the `gateway.dockerfile` and `indexer.dockerfile` files are updated to remove unnecessary build stages, streamlining the Docker image creation process. These changes improve the clarity and maintainability of the deployment configuration.
< 10000 div data-view-component="true" class="TimelineItem-badge">
…ml instead of nodekey.json

This commit modifies the configuration script in the Dockerfile to check for the existence of `config.toml` instead of `nodekey.json`. This change ensures that the correct configuration file is referenced during the initialization process, improving the accuracy of the deployment setup.
This commit modifies the `KGWInstance` and `IndexerInstance` structs to replace the `InstanceDnsName` field with `GatewayFqdn` and `IndexerFqdn`, respectively. It updates the A record creation logic to reflect these changes, ensuring that fully qualified domain names are used for the gateway and indexer instances. Additionally, the endpoint settings in the `tn_auto_stack.go` and `tn_from_config_stack.go` files are updated to utilize the new FQDN fields, enhancing clarity and maintainability in the deployment configuration.
This commit modifies the `dev-gateway-compose.yaml` file to change the source path for the `kgw-config.pkl` volume binding and updates the build context and Dockerfile path. These changes enhance the deployment structure and ensure that the correct configuration file is referenced, improving the clarity and maintainability of the Docker setup.
…y group

This commit modifies the API Gateway integration in `api_gateway.go` to include parameter mapping for the request path, improving the routing capabilities. Additionally, it updates the security group name and description in `kgw_instance.go` to better reflect its purpose as the KGW instance security group. These changes enhance the clarity and maintainability of the deployment configuration.
…se configuration

This commit updates the `.dockerignore` and `.gitignore` files to include additional patterns for ignoring environment files and IDE configurations. It also modifies the `compose.yaml` file to change the default value for the `DB_OWNER` environment variable and updates the port mapping for the TN RPC service, enhancing the clarity and maintainability of the Docker setup. Additionally, the `Taskfile.yml` is updated to include a new `PROVIDER` environment variable for migration tasks.
@outerlook outerlook self-assigned this May 1, 2025
outerlook added 2 commits May 1, 2025 18:41
This commit updates the README.md file to correct references from TSN-DB to TN-DB, ensuring consistency in documentation. Additionally, it modifies the migrate.sh script to include synchronization and private key parameters when executing SQL files, enhancing the migration process's security and functionality.
@outerlook outerlook marked this pull request as ready for review May 1, 2025 21:42
outerlook added 4 commits May 1, 2025 18:48
This commit removes the TODO comments regarding field adjustments and the inclusion of the Stage field in the `ValidatorSetProps` struct within `validator_set.go`. This change enhances code clarity by eliminating unnecessary placeholders.
This commit removes unnecessary comment sections from the `GenerateGenesisFile` function in `generate_genesis.go`, enhancing code clarity by eliminating redundant annotations. The changes streamline the function's readability without altering its functionality.
@outerlook outerlook requested a review from MicBun May 2, 2025 06:12
Copy link
pr-time-tracker bot commented May 2, 2025

Time Submission Status

Member Status Time Action Last Update
outerlook ✅ Submitted 15h Update time May 2, 2025, 6:15 AM
MicBun ✅ Submitted 45min Update time May 3, 2025, 1:39 AM

@MicBun MicBun merged commit 376da27 into refactor/node-2.0 May 2, 2025
3 of 5 checks passed
@MicBun MicBun deleted the feat/auto-stack branch May 2, 2025 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problem: TsnAutoStack CDK incompatible with v0.10
2 participants
0