Bullet Train Documentation

repository·main·Indexed 23 days ago

https://github.com/bullet-train-co/bullet_train

An application template for jumpstarting production-ready Ruby on Rails applications. It provides a pre-configured environment including database, cache, and background job setups, along with utilities for local development, Docker integration, and deployment to Render or Heroku.

Tokens
4.5K
Snippets
7
Records
32
Agent score
82%

What's inside Bullet Train

  1. Provision a Bullet Train application on Heroku

    main

    You can use the Heroku deploy button to automatically provision demo-grade infrastructure and services for a new Bullet Train application.

    Note: This process will incur costs of approximately $22/month for the provisioned services.

    After the automated provisioning is complete, you must follow the manual steps outlined in the official Deploying to Heroku documentation to finalize your setup.

    https://www.heroku.com/deploy?template=https://github.com/bullet-train-co/bullet_train
  2. Deploy Bullet Train to Render

    main

    You can provision production-grade infrastructure for your Bullet Train application on Render using the deploy button. This process will cost approximately $30/month.

    After the deployment is complete, you must manually configure the BASE_URL environment variable to ensure the application functions correctly.

    https://render.com/deploy?repo=https://github.com/bullet-train-co/bullet_train
  3. Contribute to Bullet Train

    main

    To contribute to the project, follow the standard fork-and-pull model:

    1. Fork the repository on GitHub.
    2. Clone your fork using SSH:
      git clone git@github.com:your-account/bullet_train.git
      cd bullet_train
    3. Setup the environment:
      bin/setup
    4. Start the application:
      bin/dev

    Optional: Using ngrok If you have ngrok installed, you can expose your local server to a public domain:

    1. Uncomment ngrok: ngrok http 3000 in Procfile.dev.
    2. Run bin/set-ngrok-url to update the BASE_URL environment variable.
    3. Re-run bin/set-ngrok-url whenever you restart ngrok to update the URL.
    git clone git@github.com:your-account/bullet_train.git
    cd bullet_train
    bin/setup
    bin/dev
  4. Configure nvm, rbenv, PostgreSQL, and Redis on macOS

    main

    If you installed dependencies via brew bundle on macOS, you must manually complete these configuration steps:

    nvm configuration

    Create the nvm directory and update your ~/.zshrc with the following lines:

    mkdir ~/.nvm
    touch ~/.zshrc
    open ~/.zshrc

    Paste these lines into ~/.zshrc:

    export NVM_DIR="$HOME/.nvm"
    [ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh"
    [ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm"

    rbenv configuration

    Initialize rbenv and install the required Ruby version:

    rbenv init
    rbenv install `cat .ruby-version`

    (Open a new shell/tab after this step)

    PostgreSQL configuration

    Start the PostgreSQL service:

    brew services start postgresql@14

    Redis configuration

    Start the Redis service:

    brew services start redis
  5. Install and run a Bullet Train application

    main

    To get a Bullet Train application running locally, ensure you have the required dependencies installed, run the setup script, and then start the development server.

    Prerequisites

    Ensure the following are installed on your system:

    • Ruby: Version specified in .ruby-version (typically Ruby 3).
    • Node.js: Version specified in .nvmrc (typically Node 19).
    • PostgreSQL: Version 14.
    • Redis: Version 6.2.
    • Chrome: Required for headless browser tests.

    Note: If you are having trouble with local installations, you can use rails.new to assist with the process.

    Setup and Execution

    1. Run the setup script to prepare the database and dependencies:
      bin/setup
    2. Start the application in development mode:
      bin/dev
    3. Access the application at http://localhost:3000.
    bin/setup
    bin/dev
  6. Build a new application with Bullet Train

    main

    To start a new project, do not fork the repository. Instead, clone the template repository into a new directory and follow these steps:

    1. Clone the template:

      git clone https://github.com/bullet-train-co/bullet_train.git your_new_project_name
      cd your_new_project_name
    2. Install dependencies (macOS only): If you are on macOS, use Homebrew to install dependencies:

      brew bundle

      Note: If using brew bundle, you must manually perform the additional configuration steps for nvm, rbenv, PostgreSQL, and Redis listed below.

    3. Configure Node.js: Ensure Node.js is set up by running:

      source ~/.zshrc
      nvm install
      corepack enable

      (Open a new shell/tab after this step)

    4. Run setup scripts:

      bundle install
      bin/configure
      bin/setup
    5. Boot the application:

      bin/dev

      The application will be available at http://localhost:3000.

    git clone https://github.com/bullet-train-co/bullet_train.git your_new_project_name
    cd your_new_project_name
    brew bundle
    # ... follow additional config steps ...
    bin/configure
    bin/setup
    bin/dev
  7. Initialize Active Record encryption keys

    main
    The bin/secrets script automates the process of adding encrypted keys for Active Record Encryption to your environment-specific credentials. This is done by piping the output of bin/rails db:encryption:init into the bin/rails credentials:edit command for the target environment.
  8. Edit encrypted credentials for a specific environment

    main

    To edit the encrypted credentials for a specific environment, use the bin/rails credentials:edit command with the --environment flag. You can specify the EDITOR environment variable to choose your preferred text editor (e.g., code --wait for VS Code).

    Usage Patterns:

    • Development: EDITOR='code --wait' bin/rails credentials:edit --environment development
    • Test: EDITOR='code --wait' bin/rails credentials:edit --environment test
    • Production: EDITOR='code --wait' bin/rails credentials:edit --environment production
    • Global: EDITOR='code --wait' bin/rails credentials:edit (edits the global credentials used across all environments)
  9. Manage application secrets with bin/secrets

    main

    The bin/secrets script is a utility used to initialize and manage encrypted credentials for different environments (development, test, production, and global). It automates the generation of master keys and the setup of environment-specific credential files, including keys for Active Record encrypted attributes.

    Important Security Note: The generated .key files (e.g., config/credentials/development.key, config/master.key) contain sensitive information and must not be committed to your version control system. They should be added to .gitignore and shared only with trusted team members.