### Install Local Dev Tools on Windows Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/README.md Command to install necessary tools (hugo, nodejs, golang, jq) on Windows using Chocolatey for setting up the local documentation development environment. Go-Swagger requires separate installation. ```Shell choco install hugo nodejs golang jq ``` -------------------------------- ### Running GitHub Installations Helper (Node.js) Source: https://github.com/habitat-sh/habitat/blob/main/tools/project_create/README.md Example command to run the `installations.js` helper script. This script lists GitHub installation IDs and names for a given App ID using the PEM file for authentication. Requires Node.js installed. ```Node.js node installations.js 5629 builder-github-app.pem ``` -------------------------------- ### Loading Habitat Service in Studio (Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/get_started.md Loads and starts a Habitat service within the Studio environment. It takes the package identifier (ORIGIN_NAME/sample-node-app) as an argument. This makes the application available to run. ```Bash hab svc load ORIGIN_NAME/sample-node-app ``` -------------------------------- ### Entering Habitat Studio (Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/get_started.md Enters the Habitat Studio environment, a cleanroom build environment necessary for developing and interacting with Habitat packages and services. ```bash hab studio enter ``` -------------------------------- ### Running GitHub Repositories Helper (Node.js) Source: https://github.com/habitat-sh/habitat/blob/main/tools/project_create/README.md Example command to run the `repos.js` helper script. This script lists repository IDs and names for a specific GitHub installation ID using the App ID and PEM file for authentication. Requires Node.js installed. ```Node.js node repos.js 5629 56940 builder-github-app.pem ``` -------------------------------- ### Serve Habitat Docs Locally (Make) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/README.md Make command to clone chef-web-docs, configure it to build Habitat documentation locally, and start a Hugo server with live reloading for previewing changes. ```Shell make serve ``` -------------------------------- ### Installing Git Dependency (Shell) Source: https://github.com/habitat-sh/habitat/blob/main/BUILDING.md Installs the `git` package using `apt-get` with recommended options for a minimal installation, which is required to clone the Habitat repository. ```Shell sudo -E apt-get install -y --no-install-recommends git ``` -------------------------------- ### Running GitHub App Info Helper (Node.js) Source: https://github.com/habitat-sh/habitat/blob/main/tools/project_create/README.md Example command to run the `app.js` helper script. This script retrieves basic information about a GitHub App using its ID and PEM file for authentication. Requires Node.js installed. ```Node.js node app.js 5629 builder-github-app.pem ``` -------------------------------- ### Installing Docker for Integration Tests (Shell) Source: https://github.com/habitat-sh/habitat/blob/main/BUILDING.md Runs an additional setup script to install Docker, which is required if you plan to run the BATS-based integration tests for the project. ```Shell sh support/linux/install_dev_8_docker.sh ``` -------------------------------- ### Loading Habitat Service with At-Once Strategy (Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/get_started.md Loads the specified Habitat service into the Supervisor using the 'at-once' update strategy, which immediately updates the service to the latest available version upon loading. ```bash hab svc load ORIGIN_NAME/sample-node-app --strategy at-once ``` -------------------------------- ### Install Node.js on Linux (Snap) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/README.md Command to install Node.js version 12 using Snap on Linux distributions that support it. ```Shell snap install node --classic --channel=12 ``` -------------------------------- ### Setup Ubuntu 14.04+ Docker Test Environment Source: https://github.com/habitat-sh/habitat/blob/main/BUILDING.md Creates and enters a Docker container based on Ubuntu 14.04 (trusty) to provide a clean environment for testing the setup instructions. It installs necessary tools like sudo and git, creates a non-root user with sudo privileges, sets their password, and switches to that user. ```bash docker run --rm -it ubuntu:trusty bash apt-get update && apt-get install -y sudo git-core useradd -m -s /bin/bash -G sudo jdoe echo jdoe:1234 | chpasswd sudo su - jdoe ``` -------------------------------- ### Install Hugo on Linux (Snap) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/README.md Command to install the extended version of Hugo using Snap on Linux distributions that support it. ```Shell snap install hugo --channel=extended ``` -------------------------------- ### Setup Arch Linux Docker Test Environment Source: https://github.com/habitat-sh/habitat/blob/main/BUILDING.md Creates and enters a Docker container based on a greyltc/archlinux image to provide a clean environment for testing the setup instructions. It updates package lists, installs necessary tools like sudo and git, configures sudo for the wheel group, creates a non-root user in the wheel group, sets their password, and switches to that user. ```bash docker run --rm -it greyltc/archlinux bash pacman -Syy --noconfirm pacman -S --noconfirm sudo git echo "%wheel ALL=(ALL) ALL" > /etc/sudoers.d/01_wheel useradd -m -s /bin/bash -G wheel jdoe echo jdoe:1234 | chpasswd sudo su - jdoe ``` -------------------------------- ### Building Habitat Package in Studio (Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/get_started.md Executes the build process defined in the plan.sh file within the Habitat Studio. This command compiles the application and its dependencies into a Habitat package (.hart file). ```Bash build ``` -------------------------------- ### Install Local Dev Tools on macOS Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/README.md Command to install necessary tools (go-swagger, hugo, node, go, jq) on macOS using Homebrew for setting up the local documentation development environment. ```Shell brew tap go-swagger/go-swagger && brew install go-swagger hugo node go jq ``` -------------------------------- ### Run Chef Habitat CLI Setup Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/hab_setup.md Execute this command to initiate the interactive setup process for the Chef Habitat CLI. It will guide you through creating a new origin, generating origin keys, and optionally configuring access to the Habitat Builder depot and Supervisor remote control. ```shell hab cli setup ``` -------------------------------- ### Entering Habitat Studio (macOS Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/get_started.md Enters the Habitat Studio environment on macOS. The Studio is an isolated shell used for building and managing Habitat packages. ```Bash hab studio enter ``` -------------------------------- ### Install jq on Linux (APT) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/README.md Command to install the jq command-line JSON processor on Debian/Ubuntu-based Linux distributions using APT. ```Shell sudo apt-get install jq ``` -------------------------------- ### Exiting Habitat Studio (Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/get_started.md Exits the current Habitat Studio session, returning to the host operating system's terminal. ```Bash exit ``` -------------------------------- ### Install Build Essentials on Linux (APT) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/README.md Command to install essential build tools on Debian/Ubuntu-based Linux distributions using APT, often required for compiling dependencies. ```Shell apt install -y build-essential ``` -------------------------------- ### Installing Rustfmt (Shell) Source: https://github.com/habitat-sh/habitat/blob/main/BUILDING.md Executes a provided script to install the specific nightly version of `rustfmt` required by the project for code formatting. ```Shell ./support/rustfmt_nightly.sh ``` -------------------------------- ### Example DCO Signoff for Contribution Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/README.md Provides an example format for the Developer Certification of Origin (DCO) signoff required in pull request comments for contributions. ```Text Signed-off-by: Julia Child ``` -------------------------------- ### Get Package Path (plan.sh) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/build_helpers.md Illustrates how to use the `pkg_path_for` helper function in a plan.sh to retrieve the installation path of a package dependency listed in `pkg_deps` or `pkg_build_deps`. This example gets the path for the `core/perl` package and appends the path to its binary. ```bash _perl_path="$(pkg_path_for core/perl)/bin/perl" ``` -------------------------------- ### Initialize Habitat Plan in Project Root (Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/plan_quickstart.md This command sequence navigates to the root of a project repository and runs `hab plan init`. The command creates a `habitat` subdirectory containing the initial `plan.sh` (or `plan.ps1`), `default.toml`, `config`, and `hooks` directories, setting the `pkg_name` based on the parent directory name. ```bash cd /path/to/\nhab plan init ``` -------------------------------- ### Reference Build Script (CI) Source: https://github.com/habitat-sh/habitat/blob/main/components/hab/habitat/x86_64-darwin/README.md Provides a reference to the build script used in CI for installing prerequisites, except for Xcode. This script serves as a guide for the manual steps. ```sh ./.buildkite/scripts/build_mac_release.sh ``` -------------------------------- ### Viewing Habitat Supervisor Log (Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/get_started.md Displays the log output from the Habitat Supervisor, useful for monitoring service status, updates, and debugging. ```bash sup-log ``` -------------------------------- ### Setup Centos 7 Docker Test Environment Source: https://github.com/habitat-sh/habitat/blob/main/BUILDING.md Creates and enters a Docker container based on Centos 7 to provide a clean environment for testing the setup instructions. It installs necessary tools like sudo and git, creates a non-root user with wheel group privileges (for sudo), sets their password, and switches to that user. ```bash docker run --rm -it centos:7 bash yum install -y sudo git useradd -m -s /bin/bash -G wheel jdoe echo jdoe:1234 | chpasswd sudo su - jdoe ``` -------------------------------- ### Install Habitat via Chocolatey - Windows Source: https://github.com/habitat-sh/habitat/blob/main/README.md Installs the Habitat package using the Chocolatey package manager on Windows. ```Powershell C:\> choco install habitat ``` -------------------------------- ### Setup Habitat Development Environment on Ubuntu 14.04+ Source: https://github.com/habitat-sh/habitat/blob/main/BUILDING.md Runs the necessary system preparation scripts for Ubuntu 14.04+, sources the user's profile, and then attempts to compile the project using make. This setup is suitable for older Ubuntu versions where certain libraries might not be readily available. ```bash sh support/linux/install_dev_0_ubuntu_14.04.sh sh support/linux/install_dev_9_linux.sh . ~/.profile make ``` -------------------------------- ### Entering a Specific Habitat Studio Version (Shell) Source: https://github.com/habitat-sh/habitat/blob/main/components/studio/README.md Demonstrates how to directly invoke a specific installed version of the `hab` binary to enter a Habitat studio. This is useful for testing or using a particular version after installation. ```Shell /hab/pkgs/core/hab/0.22.0-dev/20170407021836/bin/hab studio enter ``` -------------------------------- ### Setup Habitat Development Environment on Arch Linux Source: https://github.com/habitat-sh/habitat/blob/main/BUILDING.md Runs the necessary system preparation scripts for Arch Linux, sources the user's profile, and then attempts to compile the project using make. This prepares an Arch Linux system for building Habitat components. ```bash sh support/linux/install_dev_0_arch.sh sh support/linux/install_dev_9_linux.sh . ~/.profile make ``` -------------------------------- ### Starting Vagrant VM for Habitat Development (Shell) Source: https://github.com/habitat-sh/habitat/blob/main/BUILDING.md This command starts the Vagrant virtual machine defined by the Vagrantfile in the project root. It specifies the 'virtualbox' provider. Other providers may be available as configured in the Vagrantfile. ```Shell vagrant up --provider virtualbox ``` -------------------------------- ### Starting Habitat Service from Exported Tarball (Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/builder_origin_packages.md Instructs the Habitat Supervisor to start a service package that was previously extracted from an exported tarball. May require downloading Supervisor dependencies and setting up 'hab' user/group on a clean server. ```bash $ /hab/bin/hab svc start core/nginx ``` -------------------------------- ### Install Habitat via install.sh script - Bash Source: https://github.com/habitat-sh/habitat/blob/main/README.md Downloads and executes the official Habitat install.sh script using curl and bash, typically requiring sudo for system-wide installation. ```Bash $ curl https://raw.githubusercontent.com/habitat-sh/habitat/main/components/hab/install.sh | sudo bash ``` -------------------------------- ### Running Cargo Commands in Component (Shell) Source: https://github.com/habitat-sh/habitat/blob/main/BUILDING.md Demonstrates how to navigate into a specific component directory (`components/sup`) and use `cargo run` to execute or get help for that component's binary. ```Shell cd components/sup cargo run -- --help cargo run -- status ``` -------------------------------- ### Checking Habitat Service Status (Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/get_started.md Displays the current status of services loaded within the Habitat Studio. This command is used to verify that a service, such as the sample-node-app, is running correctly. ```Bash hab svc status ``` -------------------------------- ### Starting Chef Habitat Supervisor with Package - Bash Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/sup_run.md Starts the Chef Habitat Supervisor and immediately loads and starts the specified package (e.g., `core/redis`). This method is primarily intended for container entry-point workflows or simple local testing, as it mixes Supervisor and service options and may start other previously loaded services. ```bash hab sup run ``` -------------------------------- ### Install `hab` Binary Source: https://github.com/habitat-sh/habitat/blob/main/components/hab/habitat/x86_64-darwin/README.md Installs the Habitat `hab` binary using the standard `curl|bash` method from the official GitHub repository. This provides the necessary `hab` command for subsequent steps. ```sh curl https://raw.githubusercontent.com/habitat-sh/habitat/master/components/hab/install.sh | sudo bash ``` -------------------------------- ### Running Habitat Bulk Project Creation Tool (Ruby) Source: https://github.com/habitat-sh/habitat/blob/main/tools/project_create/README.md Command to execute the `project_create.rb` script. It requires the path to the core-plans directory, the projects API URL, the GitHub installation ID, and optionally a GitHub auth token (or uses HAB_AUTH_TOKEN env var). Requires a recent Ruby installation. ```Ruby ruby project_create.rb [] ``` -------------------------------- ### Running Core Setup Scripts (Shell) Source: https://github.com/habitat-sh/habitat/blob/main/BUILDING.md Executes the primary Linux development setup scripts provided in the `support/linux` directory to prepare the environment with necessary tools and configurations. ```Shell sh support/linux/install_dev_0_ubuntu_latest.sh sh support/linux/install_dev_9_linux.sh ``` -------------------------------- ### Install Habitat via Homebrew - macOS Source: https://github.com/habitat-sh/habitat/blob/main/README.md Taps the official Habitat Homebrew repository and installs the `hab` command-line tool on macOS. ```Shell $ brew tap habitat-sh/habitat $ brew install hab ``` -------------------------------- ### Run Documentation Spellcheck (Make) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/README.md Make command to execute the optional spellcheck task using cspell, which requires cspell to be installed globally. ```Shell make spellcheck ``` -------------------------------- ### Loading Habitat Service from Builder (Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/builder_origin_packages.md Starts the Habitat Supervisor and loads a service package from Builder. If the package is not cached locally, the Supervisor downloads it, verifies its integrity, and starts it. Requires HAB_AUTH_TOKEN environment variable for private packages. ```bash $ hab sup run $ hab svc load core/postgresql ``` -------------------------------- ### Entering Habitat Studio (Linux Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/get_started.md Enters the Habitat Studio environment on Linux. The -D flag is typically used on Linux to enter the Studio using Docker. The Studio is an isolated shell used for building and managing Habitat packages. ```Bash hab studio enter -D ``` -------------------------------- ### Install specific version of hab using curl-bash (Shell) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/install_faq.md This command downloads the Chef Habitat installation script from the official GitHub repository using `curl` and pipes it directly to `sudo bash` for execution. The `-s -- -v 0.56.0` arguments passed to bash tell the script to install version `0.56.0` of the `hab` binary. ```Shell curl https://raw.githubusercontent.com/habitat-sh/habitat/main/components/hab/install.sh \ | sudo bash -s -- -v 0.56.0 ``` -------------------------------- ### Setup Habitat Development Environment on Centos 7 Source: https://github.com/habitat-sh/habitat/blob/main/BUILDING.md Runs the necessary system preparation scripts for Centos 7, sources the user's profile, and then attempts to compile the project using make. This prepares a Centos 7 system for building Habitat components. ```bash sh support/linux/install_dev_0_centos_7.sh sh support/linux/install_dev_9_linux.sh . ~/.profile make ``` -------------------------------- ### Checking Cargo Installation (Shell) Source: https://github.com/habitat-sh/habitat/blob/main/BUILDING.md Runs the `cargo --version` command to verify that the Rust `cargo` toolchain is correctly installed and accessible in the system's `$PATH`. ```Shell cargo --version ``` -------------------------------- ### Install Xcode Command Line Tools Source: https://github.com/habitat-sh/habitat/blob/main/components/hab/habitat/x86_64-darwin/README.md Installs the basic developer tooling required for compiling and building software on macOS, which is a necessary prerequisite. ```sh xcode-select --install ``` -------------------------------- ### Setup Habitat Development Environment on macOS Source: https://github.com/habitat-sh/habitat/blob/main/BUILDING.md Runs the necessary system preparation scripts for macOS development, sources the user's profile, sets environment variables required for finding OpenSSL libraries and disabling Docker-based builds, and then attempts to compile the project using make. ```bash cp components/hab/install.sh /tmp/ sh support/mac/install_dev_0_mac_latest.sh sh support/mac/install_dev_9_mac.sh . ~/.profile export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig:/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH" export IN_DOCKER=false make ``` -------------------------------- ### Starting Habitat Supervisor A Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/service_groups.md Starts the first Habitat Supervisor instance on a specific host (172.18.0.2). This Supervisor will act as the initial peer for other Supervisors joining the network. ```bash hab sup run # on 172.18.0.2 (Supervisor A) ``` -------------------------------- ### Querying Services via HTTP API with Curl Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/monitor_services.md Demonstrates a basic GET request to the Supervisor's /services endpoint using `curl` to retrieve a list of running services. This example assumes no authentication is required. ```bash curl http://172.17.0.2:9631/services ``` -------------------------------- ### Installing Habitat CLI via hab pkg install (Linux) Source: https://github.com/habitat-sh/habitat/blob/main/RELEASE.md Uses the existing 'hab' command to install or upgrade the 'core/hab' package from the 'staging' channel, creating a binlink and forcing the installation. ```sh sudo hab pkg install core/hab --binlink --force --channel=staging ``` -------------------------------- ### Installing Habitat Windows Service (bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/windows-service/README.md Installs the `core/windows-service` Habitat package, which includes an install hook to register the service with the Windows Service Control Manager (SCM). ```bash hab pkg install core/windows-service ``` -------------------------------- ### Exposing Docker Port for Habitat Studio (Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/get_started.md Sets an environment variable HAB_DOCKER_OPTS to configure the Docker container used by the Habitat Studio. This specific command exposes port 8000 from the container to the host, allowing access to the running Node.js application from a browser. ```Bash export HAB_DOCKER_OPTS="-p 8000:8000" ``` -------------------------------- ### Running Habitat Supervisor and Loading Service from Tarball Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/pkg_exports.md Commands to start the Chef Habitat Supervisor and load a specific service package using the `hab` binary included within the unpacked tarball. This initiates the running of the application. ```bash sudo /hab/bin/hab sup run sudo /hab/bin/hab svc load / ``` -------------------------------- ### Install Homebrew Prerequisite (wget) Source: https://github.com/habitat-sh/habitat/blob/main/components/hab/habitat/x86_64-darwin/README.md Installs the `wget` utility using Homebrew. This is currently the only extra Homebrew dependency required for the build process. ```sh brew install wget ``` -------------------------------- ### Running Habitat Supervisor with External Configuration (Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/sup_pkg_config.md Starts the Habitat Supervisor for a specified package, instructing it to load configuration and lifecycle hooks from a local directory instead of the built package artifact. This is useful for rapid development and testing of configuration and hooks without requiring a full package rebuild for each change. - `core/redis`: The name of the package to run. - `--config-from /src`: Specifies the local directory (`/src` in this example) from which the Supervisor should load the configuration and hooks. ```bash $ hab sup run core/redis --config-from /src ``` -------------------------------- ### Installing Habitat CLI via install.sh (Linux) Source: https://github.com/habitat-sh/habitat/blob/main/RELEASE.md Downloads and executes the Habitat install script from GitHub using curl and bash, installing the CLI from the specified 'staging' channel. ```sh curl https://raw.githubusercontent.com/habitat-sh/habitat/master/components/hab/install.sh \ | sudo bash -s -- -c staging ``` -------------------------------- ### Exposing Docker Port for Habitat Service (Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/get_started.md Sets the HAB_DOCKER_OPTS environment variable to expose port 8000 from the Docker container where the Habitat Supervisor is running, allowing external access to the service. ```bash export HAB_DOCKER_OPTS="-p 8000:8000" ``` -------------------------------- ### Verifying Habitat Service Stopped Status (Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/get_started.md Displays the current status of services loaded within the Habitat Studio. This command is used after attempting to stop a service to confirm that it is no longer running. ```Bash hab svc status ``` -------------------------------- ### Starting Habitat Supervisor with Authentication Token Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/monitor_services.md Shows how to start the Habitat Supervisor (`hab sup run`) while setting the `HAB_SUP_GATEWAY_AUTH_TOKEN` environment variable. This enables simple Bearer token authentication for the HTTP API gateway. ```bash $ HAB_SUP_GATEWAY_AUTH_TOKEN="sekret" hab sup run hab-sup(MR): Supervisor Member-ID e89b6616d2c040c8a82f475b00ba8c69 hab-sup(MR): Starting gossip-listener on 0.0.0.0:9638 hab-sup(MR): Starting ctl-gateway on 0.0.0.0:9632 hab-sup(MR): Starting http-gateway on 0.0.0.0:9631 ``` -------------------------------- ### Initialize Habitat Plan with Pre-populated Variables (Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/plan_quickstart.md This command demonstrates how to use the `env` command to set environment variables corresponding to `pkg_*` variables before running `hab plan init`. This allows you to pre-populate fields like `pkg_svc_user`, `pkg_deps`, `pkg_license`, `pkg_bin_dirs`, `pkg_version`, `pkg_description`, and `pkg_maintainer` during the plan initialization process. The plan context will be created in a directory named 'yourplan'. ```bash env pkg_svc_user=someuser pkg_deps="(core/make core/coreutils)" \\ pkg_license="('MIT' 'Apache-2.0')" pkg_bin_dirs="(bin sbin)" \\ pkg_version=1.0.0 pkg_description="foo" pkg_maintainer="you" \\ hab plan init yourplan ``` -------------------------------- ### Install Chef Habitat CLI via PowerShell Script on Windows Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/install_habitat.md This PowerShell script downloads and executes the official Chef Habitat installation script for Windows. It first bypasses the execution policy for the current process to allow the script to run, then downloads and executes the script using `iex` and `New-Object System.Net.WebClient`. Requires PowerShell and internet access. ```powershell Set-ExecutionPolicy Bypass -Scope Process -Force iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/habitat-sh/habitat/main/components/hab/install.ps1')) ``` -------------------------------- ### Install Chef Habitat CLI via Shell Script on Linux Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/install_habitat.md This snippet downloads and executes the official Chef Habitat installation script for Linux using `curl` and `sudo bash`. It's an alternative command-line method to install the `hab` CLI tool. Requires `curl` and `sudo` permissions. ```shell curl https://raw.githubusercontent.com/habitat-sh/habitat/main/components/hab/install.sh | sudo bash ``` -------------------------------- ### Install cspell Globally (NPM) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/README.md Command to install the cspell command-line spell checker globally using npm, required for running the optional spellcheck task. ```Shell npm install -g cspell ``` -------------------------------- ### Setting up Habitat Studio for Testing (Linux/macOS) Source: https://github.com/habitat-sh/habitat/blob/main/RELEASE.md Prepares a directory, clones the core-plans repository, sets necessary environment variables, cleans the Habitat Studio, and enters it for testing builds and services. ```sh mkdir testing cd testing git clone https://github.com/habitat-sh/core-plans export HAB_INTERNAL_BLDR_CHANNEL=staging export HAB_STUDIO_SECRET_HAB_INTERNAL_BLDR_CHANNEL=staging hab studio rm hab studio enter ``` -------------------------------- ### Install Omnibus Bootstrap Toolchain Package Source: https://github.com/habitat-sh/habitat/blob/main/components/hab/habitat/x86_64-darwin/README.md Installs a minimal set of binaries and static libraries using Chef's Omnibus tooling. This package effectively replaces Habitat build dependencies and is installed to `/opt/mac-bootstrapper`. ```sh sudo installer \ -pkg \ -target / ``` -------------------------------- ### Loading Another Chef Habitat Service (Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/sup_run.md Provides a simple example of loading an additional service (`core/redis`) into the same Supervisor using `hab svc load`. ```bash $ hab svc load core/redis ``` -------------------------------- ### Starting Habitat Supervisor Network with Custom Size (make) Source: https://github.com/habitat-sh/habitat/blob/main/tools/sup-network/README.md This command uses `make up` to start the simulated Habitat supervisor network. The `HAB_SUP_TEST_NETWORK_SIZE` variable is set to specify the desired number of peer nodes, overriding the default of 3. ```Shell make up HAB_SUP_TEST_NETWORK_SIZE=5 ``` -------------------------------- ### Running Chef Habitat Supervisor as Root (Linux) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/sup_run.md Demonstrates how to start the Chef Habitat Supervisor on a Linux host with root privileges, specifying the package to run. Intended for one-off evaluations, not production. ```bash $ sudo hab sup run yourorigin/yourname ``` -------------------------------- ### Install Habitat via install.ps1 script - Powershell Source: https://github.com/habitat-sh/habitat/blob/main/README.md Sets the execution policy to bypass for the current process and downloads and executes the official Habitat install.ps1 script using Powershell. ```Powershell C:\> Set-ExecutionPolicy Bypass -Scope Process -Force C:\> iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/habitat-sh/habitat/main/components/hab/install.ps1')) ``` -------------------------------- ### Powershell Example: Setting SSL_CERT_FILE Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/build_phase_callbacks.md This example demonstrates how to use `Set-RuntimeEnv` in a Powershell plan to set the `SSL_CERT_FILE` environment variable. It utilizes `Get-HabPackagePath` to locate a file within a dependency package and uses the `-IsPath` flag for portability. ```Powershell Set-RuntimeEnv SSL_CERT_FILE "$(Get-HabPackagePath cacerts)/ssl/cert.pem" ``` -------------------------------- ### Starting a Chef Habitat Supervisor and Peering to Bastion Ring - Shell Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/sup_networks.md Demonstrates how to start a standard Chef Habitat Supervisor (`D`) and peer it to the previously established bastion ring supervisors (`A`, `B`, `C`). This supervisor is intended to run services and should not be started as a permanent peer. The `--peer` flag is used to specify the bastion peers. ```sh hab sup run --peer=A --peer=B --peer=C ``` -------------------------------- ### Running Cargo Commands from Root (Shell) Source: https://github.com/habitat-sh/habitat/blob/main/BUILDING.md Shows how to execute specific Habitat binaries (`hab`, `hab sup`) directly from the repository root using `cargo run -p `, providing help or status information. ```Shell cargo run -p hab plan --help cargo run -p hab sup --help ``` -------------------------------- ### Serving Rust Crate Documentation Locally Source: https://github.com/habitat-sh/habitat/blob/main/CONTRIBUTING.md The make command used to start a small web server that serves the generated Rust documentation locally on port 9633. This allows browsing the documentation in a web browser. ```shell make serve-docs ``` -------------------------------- ### Setting up Test Environment for Supplemental Groups (Shell) Source: https://github.com/habitat-sh/habitat/blob/main/test-services/supplemental-group-tester/README.md This script performs the necessary setup steps for the supplemental group tester package. It creates the test file, adds a new group (`extra_group`), changes the file's group ownership and permissions so only the group can read it, and finally adds the 'hab' user to the new group. This allows the Habitat hook processes running as 'hab' to read the file via their supplementary group membership. ```Shell echo "Hello World" > //tmp/supplemental-group-tester-file sudo groupadd extra_group chgrp extra_group //tmp/supplemental-group-tester-file sudo chown 740 //tmp/supplemental-group-tester-file sudo usermod -G extra_group hab ``` -------------------------------- ### Installing Habitat CLI via install.sh (macOS) Source: https://github.com/habitat-sh/habitat/blob/main/RELEASE.md Downloads and executes the Habitat install script from GitHub using curl and bash, installing the CLI from the specified 'staging' channel on macOS. ```sh curl https://raw.githubusercontent.com/habitat-sh/habitat/master/components/hab/install.sh \ | sudo bash -s -- -c staging ``` -------------------------------- ### Install Chef Habitat CLI via Chocolatey on Windows Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/install_habitat.md This command uses the Chocolatey package manager to install the Chef Habitat CLI on Windows. It's the recommended method for Windows users. Requires Chocolatey installed on the system. ```powershell choco install habitat ``` -------------------------------- ### Enter Habitat Studio Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/pkg_build.md Executes the `hab studio enter` command to launch an interactive Chef Habitat studio session. This is the recommended environment for building and debugging plans. Requires the Habitat CLI installed. ```Bash hab studio enter ``` -------------------------------- ### Installing Habitat CLI via install.ps1 (Windows) Source: https://github.com/habitat-sh/habitat/blob/main/RELEASE.md Downloads and executes the Habitat install script using PowerShell's Invoke-RestMethod (irm) and executes it with the specified 'staging' channel. ```powershell iex "& { $(irm https://raw.githubusercontent.com/habitat-sh/habitat/master/components/hab/install.ps1) } -Channel staging" ``` -------------------------------- ### Installing Habitat Test Prerequisites (Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/rootless_studio/tests/README.md Installs the necessary tools (BATS, Expect, DejaGNU) for running automated tests on Ubuntu systems using the apt-get package manager. ```bash sudo apt-get install bats expect dejagnu ``` -------------------------------- ### Installing Habitat Package from Builder Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/pkg_exports.md Illustrates the command used to install a Chef Habitat package from Builder within a Habitat studio. This is a prerequisite step before exporting a package that is hosted on Builder. ```bash hab pkg install / ``` -------------------------------- ### Starting Subsequent Leader-Follower Supervisors (Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/service_group_topologies.md Command to start additional Supervisors in a leader-follower service group. It specifies the topology, group name, and the address of an existing peer in the ring to join the cluster. The service package is then loaded. ```bash hab sup run --topology leader --group production --peer 192.168.5.4 hab svc load / ``` -------------------------------- ### Example: Viewing Habitat Member RBAC Role (hab CLI) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/builder_origins.md Example command demonstrating how to view the RBAC role for a specific member (`bluewhale`) within a specific origin (`two-tier-app`) using `hab origin rbac show`. ```bash hab origin rbac show bluewhale --origin two-tier-app ``` -------------------------------- ### Example Supervisor Configuration File - TOML Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/sup_config.md An example of the generated `config.toml` file, showing various configuration settings for the Habitat Supervisor, such as listen addresses, peer settings, organization, and logging options. This file can be modified to customize Supervisor behavior according to specific requirements. ```toml ### The listen address for the Gossip Gateway listen_gossip = "0.0.0.0:9638" ### Start the supervisor in local mode local_gossip_mode = false ### The listen address for the HTTP Gateway listen_http = "0.0.0.0:9631" ### Disable the HTTP Gateway completely http_disable = false ### The listen address for the Control Gateway listen_ctl = "127.0.0.1:9632" ### The organization the Supervisor and its services are part of organization = "my-org" ### The listen address of one or more initial peers (IP[:PORT]) peer = ["1.1.1.1:9632", "2.2.2.2:9632", "3.3.3.3:9632"] ### Make this Supervisor a permanent peer permanent_peer = false ### Watch this file for connecting to the ring peer_watch_file = "/path/to/file" ### Cache for creating and searching for encryption keys cache_key_path = "/path/to/file" ### The name of the ring used by the Supervisor when running with wire encryption ring = "my-ring" ### Use the package config from this path rather than the package itself config_from = "/path/to/file" ### Enable automatic updates for the Supervisor itself auto_update = false ### The private key for HTTP Gateway TLS encryption ### ### Read the private key from KEY_FILE. This should be an RSA private key or PKCS8-encoded private key in PEM format. key_file = "/path/to/file" ### The server certificates for HTTP Gateway TLS encryption ### ### Read server certificates from CERT_FILE. This should contain PEM-format certificates in the right order. The first certificate should certify KEY_FILE. The last should be a root CA. cert_file = "/path/to/file" ### The CA certificate for HTTP Gateway TLS encryption ### ### Read the CA certificate from CA_CERT_FILE. This should contain PEM-format certificate that can be used to validate client requests ca_cert_file = "/path/to/file" ### Load a Habitat package as part of the Supervisor startup ### ### The package can be specified by a package identifier (ex: core/redis) or filepath to a Habitat artifact (ex: /home/core-redis-3.0.7-21120102031201-x86_64-linux.hart). pkg_ident_or_artifact = "core/redis" ### Verbose output showing file and line/column numbers verbose = false ### Turn ANSI color off no_color = false ### Use structured JSON logging for the Supervisor ### ### This option also sets NO_COLOR. json_logging = false ### The IPv4 address to use as the `sys.ip` template variable ### ### If this argument is not set, the supervisor tries to dynamically determine an IP address. If that fails, the supervisor defaults to using `127.0.0.1`. sys_ip_address = "1.2.3.4" ### The name of the application for event stream purposes ### ### This will be attached to all events generated by this Supervisor. event_stream_application = "my-app" ### The name of the environment for event stream purposes ### ### This will be attached to all events generated by this Supervisor. event_stream_environment = "my-env" ### Event stream connection timeout before exiting the Supervisor ### ### Set to '0' to immediately start the Supervisor and continue running regardless of the initial connection status. event_stream_connect_timeout = 60 ``` -------------------------------- ### Download File with Checksum (plan.sh) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/build_helpers.md Shows how to use the `download_file` helper function with an optional shasum argument. If a local file exists, its checksum is compared to the provided shasum. If they match, the download is skipped; otherwise, the local file is removed, and a new download is attempted. This example demonstrates the command format when providing a checksum. ```bash download_file http://example.com/file.tar.gz file.tar.gz expected_shasum ``` -------------------------------- ### Starting Supervisor as Permanent Peer (Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/service_group_topologies.md Command to start a Supervisor in a leader-follower service group and configure it as a permanent peer. Permanent peers help maintain quorum and recover from network partitions by providing a stable point of contact for other Supervisors. The service package is then loaded. ```bash hab sup run --topology leader --group production --permanent-peer hab svc load / ``` -------------------------------- ### Installing the Habitat Launcher Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/sup_launcher.md This command installs or updates the Chef Habitat Launcher package from the core origin. Updating the Launcher requires restarting the Supervisor process afterwards, which will also necessitate restarting any services managed by that Supervisor. ```bash hab pkg install core/hab-launcher ``` -------------------------------- ### Recording Build Session - Bash Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/build_helpers.md Example usage of the `record` function in a Habitat Plan (plan.sh). This function runs a command and appends its output, along with a timestamp, to a log file associated with a given session name. ```Bash # Usage: record [CMD [ARG ...]] record mysoftware build /src/mysoftware ``` -------------------------------- ### Example default.toml for pkg_exports Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/plan_settings.md This TOML snippet shows the corresponding `default.toml` structure required to provide the actual values for the keys defined in `pkg_exports`. The keys match the values specified in the `pkg_exports` associative array. ```toml [server] port = 80 host = "www.example.com" [ssl] port = 443 ``` -------------------------------- ### Example Output: Uploading Habitat Origin Secret (bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/builder_origins.md This is an example of the standard output when successfully uploading a secret using the `hab origin secret upload` command. It details the steps taken by the CLI, including key download, encryption, and upload confirmation. ```bash $ hab origin secret upload AWS_ACCESS_KEY_ID 1234567890EXAMPLE ↓ Downloading latest public encryption key 79 B / 79 B | [========================================] 100.00 % 120.23 KB/s ☑ Cached habicat-20200123456789.pub ☛ Encrypting value for key AWS_ACCESS_KEY_ID. ✓ Encrypted AWS_ACCESS_KEY_ID=[REDACTED]. ↑ Uploading secret for key AWS_ACCESS_KEY_ID. ✓ Uploaded secret for AWS_ACCESS_KEY_ID. ``` -------------------------------- ### Starting Stopped Chef Habitat Service (Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/sup_run.md Demonstrates how to resume a service that was previously stopped using `hab svc start`. This command only works for services that have already been loaded. ```bash $ hab svc start core/redis ``` -------------------------------- ### Download File Always (plan.sh) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/build_helpers.md Demonstrates using the `download_file` helper function in a Habitat plan.sh to download a file from a source URL to a local file. This specific example downloads the file every time the plan is built, regardless of whether a local file exists. ```bash download_file http://example.com/file.tar.gz file.tar.gz ``` -------------------------------- ### Running the TOML Creation Script (Shell) Source: https://github.com/habitat-sh/habitat/blob/main/tools/bldr_toml_create/README.md Execute the Ruby script `toml_create.rb` from the command line. Requires a recent Ruby installation. Takes the path to the core-plans directory and a destination directory as arguments. ```Shell ruby toml_create.rb ``` -------------------------------- ### Getting Required Rustfmt Version (Shell) Source: https://github.com/habitat-sh/habitat/blob/main/BUILDING.md Reads the content of the `RUSTFMT_VERSION` file at the repository root to determine the exact nightly version of `rustfmt` that should be used for formatting. ```Shell echo $(< RUSTFMT_VERSION) ``` -------------------------------- ### Starting Initial Leader-Follower Supervisor (Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/service_group_topologies.md Command to start the initial Supervisor for a service group using the leader-follower topology. It specifies the topology and group name, then loads the service package. This command will block until quorum is achieved. ```bash hab sup run --topology leader --group production hab svc load / ``` -------------------------------- ### Stopping Habitat Service in Studio (Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/get_started.md Stops a running Habitat service within the Studio environment. It requires the package identifier (ORIGIN_NAME/sample-node-app) of the service to be stopped. ```Bash hab svc stop ORIGIN_NAME/sample-node-app ``` -------------------------------- ### Initializing Habitat Plan with hab plan init (Advanced) - Bash Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/plan_writing.md Shows how to use environment variables to pre-populate `pkg_*` variables when running `hab plan init`. This allows setting package metadata like user, dependencies, license, version, description, and maintainer directly from the command line. ```bash env pkg_svc_user=someuser pkg_deps="(core/make core/coreutils)" \ pkg_license="('MIT' 'Apache-2.0')" pkg_bin_dirs="(bin sbin)" \ pkg_version=1.0.0 pkg_description="foo" pkg_maintainer="you" \ hab plan init yourplan ``` -------------------------------- ### Initializing Habitat Plan with hab plan init (Basic) - Bash Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/plan_writing.md Demonstrates the basic usage of the `hab plan init` command to create a new Habitat plan context within an existing project repository. It changes the directory to the project root and runs the command, creating a `habitat` subdirectory with a default `plan.sh` (or `plan.ps1`) and related directories/files. ```bash cd /path/to/ hab plan init ``` -------------------------------- ### Starting Supervisor with Ring Encryption (Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/sup_secure.md Starts the Habitat Supervisor and joins it to a named ring, enabling wire encryption using the specified ring key. Supervisors without the correct key will be rejected. This snippet also shows loading a service after startup. ```bash hab sup run --ring $ hab svc load / ``` -------------------------------- ### Chef Habitat Plan: Custom Bash Download with Git Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/plan_writing.md Example implementation of the `do_download()` callback in a Bash-based Chef Habitat plan. It demonstrates cloning a Git repository from GitHub using HTTPS, checking out a specific version, creating a tarball, and calculating the SHA256 checksum. Requires `core/git` and `core/cacerts` build dependencies for SSL. ```Bash do_download() { export GIT_SSL_CAINFO="$(pkg_path_for core/cacerts)/ssl/certs/cacert.pem" git clone https://github.com/chef/chef pushd chef git checkout $pkg_version popd tar -cjvf $HAB_CACHE_SRC_PATH/${pkg_name}-${pkg_version}.tar.bz2 \ --transform "s,^\./chef,chef-${pkg_version}," ./chef \ --exclude chef/.git --exclude chef/spec pkg_shasum=$(trim $(sha256sum $HAB_CACHE_SRC_PATH/${pkg_filename} | cut -d " " -f 1)) } ``` -------------------------------- ### Starting Habitat Supervisor with Initial Peers (Shell) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/sup_networks.md Starts a Chef Habitat Supervisor instance and immediately attempts to peer with the specified IP addresses using the `--peer` flag. The Supervisor will use the gossip protocol to discover other Supervisors in the network known by the initial peers. This is the standard way to join an existing Habitat Supervisor network. ```sh hab sup run --peer=192.168.0.1 --peer=192.168.0.2 --peer=192.168.0.3 ``` -------------------------------- ### Configure Habitat Builder Builds with .bldr.toml Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/builder_origin_packages.md Example .bldr.toml file demonstrating how to define build configurations for multiple packages within a repository. It shows how to use 'plan_path' to locate the plan file and 'paths' with globs to specify additional files/directories that trigger a rebuild for a specific package. ```TOML # .bldr.toml [hab-launcher] plan_path = "components/launcher/habitat" paths = [ "components/launcher/*", "components/launcher-protocol/*", "support/ci/builder-base-plan.sh", ] [hab-studio] plan_path = "components/studio" [hab-sup] plan_path = "components/sup" paths = [ "components/sup/*", "components/eventsrv-client/*", "components/launcher-client/*", "components/butterfly/*", "components/core/*", "components/builder-depot-client/*", ] ``` -------------------------------- ### Creating New Documentation Page using Hugo Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/README.md Use this command from the `components/docs-chef-io` directory to generate a new Markdown file for Habitat documentation. Hugo will create the file with initial front matter, ready for content. ```Shell hugo new content/habitat/.md ``` -------------------------------- ### Show Origin Member RBAC Role Example - hab origin rbac - bash Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/origin_rbac.md Provides an example of using `hab origin rbac show` to display the RBAC role for the member 'bluewhale' in the origin 'two-tier-app'. ```bash hab origin rbac show bluewhale --origin two-tier-app ``` -------------------------------- ### TOML Table Example for Configuration Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/plan_helpers.md Shows how to define a section (table) in a TOML configuration file (`default.toml` or user TOML) to group related variables, such as replication settings. ```TOML [repl] backlog-size = 200 backlog-ttl = 100 disable-tcp-nodelay = no ``` -------------------------------- ### Example Rendered Consul Run Hook (Shell) Source: https://github.com/habitat-sh/habitat/blob/main/test/fixtures/render/README.md An example of the shell script output produced by `hab plan render` when rendering a Consul run hook. It demonstrates how configuration values are injected into the script. ```Shell #!/bin/sh exec 2>&1 SERVERMODE=true export CONSUL_UI_LEGACY=false CONSUL_OPTS="-dev" if [ "$SERVERMODE" = true ]; then CONSUL_OPTS=" -ui -server -bootstrap-expect 3 -config-file=/basic_config.json" fi exec consul agent ${CONSUL_OPTS} ``` -------------------------------- ### Download Builder Origin Keys Source: https://github.com/habitat-sh/habitat/blob/main/components/hab/habitat/x86_64-darwin/README.md Downloads the public and secret `core` origin keys required for signing Habitat packages. The secret key download requires a Builder authentication token and both are installed system-wide using `sudo`. ```sh sudo hab origin key download core sudo hab origin key download --secret --auth="${HAB_AUTH_TOKEN}" core ``` -------------------------------- ### Setting Service Run Command in Habitat Plan (Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/plan_settings.md Specifies the command that the Habitat Supervisor will execute to start the service. This requires `pkg_bin_dirs` to be set. For complex startup logic, a run hook is recommended instead. Omit this for packages not intended to be run directly by the Supervisor. This setting is optional. ```bash pkg_svc_run="haproxy -f $pkg_svc_config_path/haproxy.conf" ``` -------------------------------- ### Accessing VM, Cloning Repo, and Running Tests (Shell) Source: https://github.com/habitat-sh/habitat/blob/main/BUILDING.md These commands access the provisioned Vagrant VM via SSH, switch to the root user, clone the Habitat repository from GitHub, navigate to the builder-api component directory, and run the component's tests using Cargo. ```Shell vagrant ssh sudo su - git clone https://github.com/habitat-sh/habitat.git cd habitat/components/builder-api cargo test ``` -------------------------------- ### Starting Supervisor with Ring Key via Environment Variable (Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/sup_secure.md Starts the Habitat Supervisor using a ring key provided via the HAB_RING_KEY environment variable. This is an alternative method to the --ring flag for specifying the key. It also shows loading a service. ```bash env HAB_RING_KEY=$(cat /hab/cache/keys/ring-key-file) hab sup run $ hab svc load / ``` -------------------------------- ### Building the Habitat Client Package (Shell) Source: https://github.com/habitat-sh/habitat/blob/main/components/studio/README.md Navigates to the Habitat repository root and builds the core `hab` client package using the `hab pkg build` command. This is a prerequisite for building the studio package. ```Shell cd /habitat hab pkg build components/hab ``` -------------------------------- ### Starting Chef Habitat Supervisor (Foreground) - Bash Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/sup_run.md Starts the Chef Habitat Supervisor process in the foreground. If it's the first run, it waits for services to be loaded. If not, it restarts previously loaded services that were not explicitly stopped. This is the recommended method for most use cases, especially production. ```bash hab sup run ``` -------------------------------- ### Printing Build Output - Bash Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/build_helpers.md Example usage of the `build_line` function in a Habitat Plan (plan.sh). This function prints a standard line of output during the build process, typically used for informational messages. ```Bash build_line "Checksum verified - ${pkg_shasum}" ``` -------------------------------- ### Clone Habitat Repository Source: https://github.com/habitat-sh/habitat/blob/main/BUILDING.md Clones the Habitat source code repository from GitHub and changes the current directory to the newly cloned 'habitat' directory. This is the initial step for setting up the development environment on any supported platform. ```bash git clone https://github.com/habitat-sh/habitat.git cd habitat ``` -------------------------------- ### Overriding Build and Install Phases (Bash) Source: https://github.com/habitat-sh/habitat/blob/main/components/docs-chef-io/content/habitat/binary_wrapper.md Shows how to override the default `do_build` and `do_install` functions in a Habitat plan (`plan.sh`) when packaging a binary. The `do_build` phase is kept minimal, and the `do_install` phase copies the pre-built binary into the package's `bin` directory and makes it executable. ```Bash (...) do_build() { # relocate library dependencies here, if needed -- see next topic return 0 } do_install() { mkdir -p $pkg_prefix/bin cp $PLAN_CONTEXT/bin/hello_world $pkg_prefix/bin/hello_world chmod +x $pkg_prefix/bin/hello_world } ```