Skip to content

A Rust-powered command-line tool for declaratively verifying testing environment prerequisites.

Notifications You must be signed in to change notification settings

m0nirul/Preflight

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Preflight

Rust

A Rust-powered command-line tool for declaratively verifying testing environment prerequisites.

Preflight helps ensure your development, testing, or deployment environments meet all necessary conditions before you run your application or tests. Define your checks in a simple YAML or TOML file, and Preflight will report any discrepancies, providing clear and actionable diagnostics.

Features

  • Declarative Configuration: Define all your environment checks in easy-to-read YAML or TOML files.
  • HTTP/TCP Health Checks: Verify external service availability and responsiveness.
  • File/Directory Validation: Ensure critical files or directories exist, have correct permissions, or match specific content.
  • Environment Variable Validation: Check for required environment variables, their values, or patterns.
  • Custom Scripts: Integrate custom shell scripts or commands for complex pre-checks.
  • Clear Diagnostics: Get immediate, actionable feedback on what failed and why.

Installation

Preflight can be installed via cargo:

cargo install preflight

Alternatively, you can build from source:

git clone https://github.com/your-org/preflight.git
cd preflight
cargo build --release
# The executable will be found at ./target/release/preflight

Usage

To run Preflight, simply provide the path to your configuration file:

preflight --config path/to/your-config.yaml

If the configuration file is named preflight.yaml or preflight.toml and is in the current directory, you can often run it without specifying the --config flag:

preflight

Preflight will execute all defined checks. If all checks pass, it will exit with a success code (0). If any check fails, it will report the failures and exit with a non-zero status code.

Configuration Example

Preflight uses a simple YAML or TOML format for defining checks. Here's an example preflight.yaml:

# preflight.yaml

environment:
  # --- File System Checks ---
  - type: file_exists
    path: ./config/app-settings.yml
    message: "Application settings file must exist."

  - type: directory_writable
    path: ./data/logs
    message: "Log directory must be writable."

  - type: file_contains
    path: /etc/hosts
    pattern: "localhost"
    message: "/etc/hosts should contain a localhost entry."

  # --- Environment Variable Checks ---
  - type: env_var_exists
    name: DATABASE_URL
    message: "DATABASE_URL environment variable is required."

  - type: env_var_matches
    name: APP_ENV
    pattern: "^(development|staging|production)$"
    message: "APP_ENV must be one of development, staging, or production."

  # --- Network Checks ---
  - type: http_get
    url: http://localhost:8080/health
    expected_status: 200
    timeout_ms: 5000
    message: "Backend API health endpoint must be reachable."

  - type: tcp_port_open
    host: database.example.com
    port: 5432
    timeout_ms: 2000
    message: "PostgreSQL database server must be reachable."

  # --- Custom Command Check ---
  - type: custom_command
    command: "docker ps -q -f 'name=my_service_db'"
    expected_exit_code: 0
    message: "Docker container 'my_service_db' must be running."

Each item under environment defines a check. The type field specifies the kind of check, and other fields provide the necessary parameters for that check, along with an optional message to provide more context for failures.

Contributing

We welcome contributions! Please see our CONTRIBUTING.md (coming soon) for details on how to get started.

License

This project is licensed under the MIT License - see the LICENSE (coming soon) file for details.

About

A Rust-powered command-line tool for declaratively verifying testing environment prerequisites.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages