Skip to content
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

Re-organize Habitat filesystem paths, environment variables, Plan variables, and runtime templating data #374

Merged
merged 19 commits into from
Apr 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a1e64d2
[core] Fix unintended doc unit test which needed a text escape.
fnichol Apr 11, 2016
31c3cbc
Reduce the number of `/opt/bldr` path occurences.
fnichol Apr 10, 2016
1dd7758
Use `HAB_ROOT_PATH` for root of Habitat file system.
fnichol Apr 11, 2016
c35c753
Use `HAB_CACHE_SRC_PATH` for default src download, extract, & compile.
fnichol Apr 11, 2016
fe1688f
Use `HAB_CACHE_ARTIFACT_PATH` for download path of package artifacts.
fnichol Apr 11, 2016
f59622f
Use `HAB_PKG_PATH` for the root path containing all locally installed…
fnichol Apr 11, 2016
cae7ceb
Use `HAB_CACHE_KEY_PATH` for the default path where keys are stored.
fnichol Apr 11, 2016
f9f05ed
Use `HAB_CACHE_GPG_PATH` for the default path where gpg keys are stored.
fnichol Apr 11, 2016
d5abf73
Use `SVC_PATH`/`pkg_svc_path` for the root path with runtime data.
fnichol Apr 11, 2016
10c80e2
SERVICE_PATH -> SVC_PATH
fnichol Apr 11, 2016
af49ff9
Use `pkg_svc_config_path` for the path to the service config.
fnichol Apr 11, 2016
8b60806
Add `{{pkg.svc_config_path}}` to `ServiceConfig`.
fnichol Apr 11, 2016
c8921df
Use `pkg_svc_data_path` for the path to the service data.
fnichol Apr 11, 2016
abac38a
Use `pkg_svc_files_path` for the path to the gossiped config files.
fnichol Apr 11, 2016
e73b574
Use `pkg_svc_hooks_path` for the path to the service hooks.
fnichol Apr 11, 2016
93eb72d
Use `pkg_svc_static_path` for the path to the service static content.
fnichol Apr 11, 2016
168b134
Use `pkg_svc_var_path` for the path to the service variable state.
fnichol Apr 11, 2016
052ec51
Remove public `hcore::fs::SVC_PATH` in favor of `*_path()` functions.
fnichol Apr 11, 2016
307d049
Remove unneeded imports.
fnichol Apr 11, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 34 additions & 33 deletions components/bpm/bin/hab-bpm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# # Usage
#
# ```sh
# $ hab-bpm install chef/bldr-studio
# $ hab-bpm install chef/hab-studio
# $ hab-bpm exec chef/bash bash --version
# ```
#
Expand Down Expand Up @@ -52,7 +52,7 @@ print_help() {

$author

Bldr Package Manager
Habitat Package Manager

USAGE:
$program [COMMON_FLAGS] <SUBCOMMAND> [ARG ..]
Expand Down Expand Up @@ -85,7 +85,7 @@ print_binlink_help() {

$author

Bldr Package Manager - create a symlink for a package binary into a common
Habitat Package Manager - create a symlink for a package binary into a common
'PATH' location

USAGE:
Expand Down Expand Up @@ -116,7 +116,7 @@ print_exec_help() {

$author

Bldr Package Manager - execute a command using the 'PATH'
Habitat Package Manager - execute a command using the 'PATH'
context of an installed package

USAGE:
Expand All @@ -141,7 +141,7 @@ print_install_help() {

$author

Bldr Package Manager - installing packages
Habitat Package Manager - installing packages

USAGE:
$program [COMMON_FLAGS] install [FLAGS] [OPTIONS] <PKG_IDENT>
Expand All @@ -150,10 +150,10 @@ FLAGS:
-h Prints this message

OPTIONS:
-u <BLDR_REPO> Sets a Bldr repository URL
-u <BLDR_REPO> Sets a Habitat repository URL
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of BLDR_REPO, perhaps we should s/BLDR_REPO/HAB_REPO/ while we're in here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll deal with this one in another PR. I wanted to make sure that "repo" is no longer the correct word.


ENVIRONMENT VARIABLES:
BLDR_REPO Sets a Bldr repository (\`-u' option takes precedence)
BLDR_REPO Sets a Habitat repository URL (\`-u' option takes precedence)

EXAMPLES:

Expand All @@ -177,7 +177,7 @@ print_pkgpath_help() {

$author

Bldr Package Manager - print the path to an installed package
Habitat Package Manager - print the path to an installed package

USAGE:
$program [COMMON_FLAGS] pkgpath <PKG_IDENT>
Expand Down Expand Up @@ -411,7 +411,7 @@ subcommand_pkgpath() {
exit_with "Installed package could not be found for: $pkg_ident_arg" 6
fi

echo "$BLDR_PKG_ROOT/$pkg_ident"
echo "$HAB_PKG_PATH/$pkg_ident"
}


Expand Down Expand Up @@ -557,7 +557,7 @@ latest_remote_package() {
# explaining that no package was found.
latest_installed_package() {
local quietly="${2:-}"
if [ ! -d "$BLDR_PKG_ROOT/$1" ]; then
if [ ! -d "$HAB_PKG_PATH/$1" ]; then
if [ -z "$quietly" ]; then
warn "No installed packages of '$1' were found"
fi
Expand All @@ -570,14 +570,14 @@ latest_installed_package() {
local result
case $(trim $latest_package_flags) in
"3")
result="$BLDR_PKG_ROOT/$1"
result="$HAB_PKG_PATH/$1"
;;
"2")
result="$($bb find $BLDR_PKG_ROOT/$1 -maxdepth 1 -type d \
result="$($bb find $HAB_PKG_PATH/$1 -maxdepth 1 -type d \
| $cu --coreutils-prog=sort --version-sort -r | $bb head -n 1)"
;;
"1")
result="$($bb find $BLDR_PKG_ROOT/$1 -maxdepth 2 -type d \
result="$($bb find $HAB_PKG_PATH/$1 -maxdepth 2 -type d \
| $cu --coreutils-prog=sort --version-sort -r | $bb head -n 1)"
;;
esac
Expand All @@ -587,7 +587,7 @@ latest_installed_package() {
fi
return 1
else
echo "$result" | $bb sed "s,^$BLDR_PKG_ROOT/,,"
echo "$result" | $bb sed "s,^$HAB_PKG_PATH/,,"
return 0
fi
}
Expand All @@ -604,7 +604,7 @@ latest_installed_package() {
install_package() {
local pkg_ident=$1
local pkg_source="$BLDR_REPO/pkgs/$pkg_ident/download"
local pkg_filename="$BLDR_PKG_CACHE/$(echo $pkg_ident | $bb tr '/' '-').bldr"
local pkg_filename="$HAB_CACHE_ARTIFACT_PATH/$(echo $pkg_ident | $bb tr '/' '-').bldr"

if [ -n "$QUIET" ]; then
local v=
Expand All @@ -624,7 +624,7 @@ install_package() {
else
info "Installing $pkg_ident"

$bb mkdir -p $v $BLDR_PKG_CACHE
$bb mkdir -p $v $HAB_CACHE_ARTIFACT_PATH

# Add a trap to clean up any interrupted file downloads and failed
# extractions. These signal traps will be cleared once extraction is
Expand All @@ -635,7 +635,7 @@ install_package() {
$wget $pkg_source -O $pkg_filename $wui

info "Unpacking $($bb basename $pkg_filename)"
local gpg_cmd="$gpg --homedir $BLDR_GPG_CACHE --decrypt $pkg_filename"
local gpg_cmd="$gpg --homedir $HAB_CACHE_GPG_PATH --decrypt $pkg_filename"
if [ -n "$VERBOSE" ]; then $gpg_cmd; else $gpg_cmd 2>/dev/null; fi \
| $bb tar x -C $FS_ROOT/

Expand All @@ -658,8 +658,8 @@ install_package_tdeps() {

# Install each entry in the package's `TDEPS` file which constitute the
# entire set of runtime dependencies--direct and transitive.
if [ -f "$BLDR_PKG_ROOT/$pkg_ident/TDEPS" ]; then
for dep_ident in $($bb cat $BLDR_PKG_ROOT/$pkg_ident/TDEPS); do
if [ -f "$HAB_PKG_PATH/$pkg_ident/TDEPS" ]; then
for dep_ident in $($bb cat $HAB_PKG_PATH/$pkg_ident/TDEPS); do
install_package $dep_ident
done
fi
Expand All @@ -674,7 +674,7 @@ set_path() {
local path_parts
local dep_ident
local dep_path
local pkg_path="$BLDR_PKG_ROOT/$1"
local pkg_path="$HAB_PKG_PATH/$1"

# Start with the `PATH` entry from this package, if it exists
if [ -f "$pkg_path/PATH" ]; then
Expand All @@ -688,8 +688,8 @@ set_path() {
# Loop through each `DEPS` entry and add the `PATH` entry for each direct
# dependency (if it exists)
for dep_ident in $($bb cat $pkg_path/DEPS); do
if [ -f "$BLDR_PKG_ROOT/$dep_ident/PATH" ]; then
dep_path="$($bb cat $BLDR_PKG_ROOT/$dep_ident/PATH)"
if [ -f "$HAB_PKG_PATH/$dep_ident/PATH" ]; then
dep_path="$($bb cat $HAB_PKG_PATH/$dep_ident/PATH)"
if [ -z "$path_parts" ]; then
path_parts="$dep_path"
else
Expand All @@ -700,8 +700,8 @@ set_path() {
# Loop through each `TDEPS` entry and add the `PATH` entry for each
# dependency (if it exists). If the entry already exists, skip it
for dep_ident in $($bb cat $pkg_path/TDEPS); do
if [ -f "$BLDR_PKG_ROOT/$dep_ident/PATH" ]; then
dep_path="$($bb cat $BLDR_PKG_ROOT/$dep_ident/PATH)"
if [ -f "$HAB_PKG_PATH/$dep_ident/PATH" ]; then
dep_path="$($bb cat $HAB_PKG_PATH/$dep_ident/PATH)"
if [ -z "$path_parts" ]; then
path_parts="$dep_path"
else
Expand Down Expand Up @@ -849,15 +849,16 @@ shift "$((OPTIND - 1))"
# filesystem or chroot environment, this environment variable may need to be
# set.
: ${FS_ROOT:=}
# The root of the bldr tree. If `BLDR_ROOT` is set, this value is overridden,
# otherwise it defaults to `/opt/bldr`.
: ${BLDR_ROOT:=$FS_ROOT/opt/bldr}
# Location containing installed packages
BLDR_PKG_ROOT=$BLDR_ROOT/pkgs
# Location containing cached packages
BLDR_PKG_CACHE=$BLDR_ROOT/cache/pkgs
# Location containing cached gpg keys
BLDR_GPG_CACHE=$BLDR_ROOT/cache/gpg
# The root path of the Habitat file system. If the `$HAB_ROOT_PATH` environment
# variable is set, this value is overridden, otherwise it is set to its default
: ${HAB_ROOT_PATH:=$FS_ROOT/opt/bldr}
# The root path containing all locally installed packages
HAB_PKG_PATH=$HAB_ROOT_PATH/pkgs
# The default download root path for package artifacts, used on package
# installation
HAB_CACHE_ARTIFACT_PATH=$HAB_ROOT_PATH/cache/artifacts
# The default path where gpg keys are stored
HAB_CACHE_GPG_PATH=$HAB_ROOT_PATH/cache/gpg
# The default bldr package repository from where to download dependencies
: ${BLDR_REPO:=http://52.37.151.35:9632}
# Whether or not more verbose output has been requested. An unset or empty
Expand Down
8 changes: 4 additions & 4 deletions components/bpm/plan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ do_install() {

do_end() {
build_line "Creating slim tarball"
pushd $BLDR_SRC_CACHE > /dev/null
pushd $HAB_CACHE_SRC_PATH > /dev/null
dir="$(cat $pkg_prefix/IDENT | tr '/' '-')"
rm -rfv $dir
mkdir -pv $dir
cp -rpv $pkg_prefix/* $dir/
tar cpf $BLDR_PKG_CACHE/${dir}.tar $dir
xz -z -9 -T 0 --verbose $BLDR_PKG_CACHE/${dir}.tar
tar cpf $HAB_CACHE_ARTIFACT_PATH/${dir}.tar $dir
xz -z -9 -T 0 --verbose $HAB_CACHE_ARTIFACT_PATH/${dir}.tar
popd > /dev/null
build_line "Slim tarball: $BLDR_PKG_CACHE/${dir}.tar.xz"
build_line "Slim tarball: $HAB_CACHE_ARTIFACT_PATH/${dir}.tar.xz"
}

# Turn the remaining default phases into no-ops
Expand Down
24 changes: 13 additions & 11 deletions components/common/src/command/package/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
// the Software until such time that the Software is made available under an
// open source license such as the Apache 2.0 License.

//! Installs a bldr package from a [depot](../depot).
//! Installs a Habitat package from a [depot](../depot).
//!
//! # Examples
//!
//! ```bash
//! $ bldr install chef/redis
//! $ hab pkg install chef/redis
//! ```
//!
//! Will install `chef/redis` package from the package depot at `http://bldr.co:9633`.
//! Will install `chef/redis` package from a custom depot:
//!
//! ```bash
//! $ bldr install chef/redis/3.0.1 redis -u http://bldr.co:9633
//! $ hab pkg install chef/redis/3.0.1 redis -u http://depot.co:9633
//! ```
//!
//! Will install the `3.0.1` version of redis.
//! This would install the `3.0.1` version of redis.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would or This will?

//!
//! # Internals
//!
Expand All @@ -32,7 +32,7 @@ use std::fs;
use std::path::{Path, PathBuf};
use std::str::FromStr;

use hcore::fs::PACKAGE_CACHE;
use hcore::fs::CACHE_ARTIFACT_PATH;
use hcore::package::{PackageArchive, PackageIdent, PackageInstall};
use depot_core::data_object;
use depot_client;
Expand All @@ -50,16 +50,16 @@ pub fn start(url: &str, ident_or_archive: &str) -> Result<()> {
}

/// Given a package name and a base url, downloads the package
/// to `/opt/bldr/cache/pkgs`. Returns the filename in the cache as a String
/// to the `CACHE_ARTIFACT_PATH`. Returns the filename in the cache as a String
///
/// # Failures
///
/// * Fails if it cannot create `/opt/bldr/cache/pkgs`
/// * Fails if it cannot create the `CACHE_ARTIFACT_PATH`
/// * Fails if it cannot download the package from the upstream
pub fn from_url<P: AsRef<PackageIdent>>(url: &str, ident: &P) -> Result<data_object::Package> {
println!("Installing {}", ident.as_ref());
let pkg_data = try!(depot_client::show_package(url, ident.as_ref()));
try!(fs::create_dir_all(PACKAGE_CACHE));
try!(fs::create_dir_all(CACHE_ARTIFACT_PATH));
for dep in &pkg_data.tdeps {
try!(install_from_depot(url, &dep, dep.as_ref()));
}
Expand All @@ -71,7 +71,7 @@ pub fn from_archive<P: AsRef<Path>>(url: &str, path: &P) -> Result<()> {
println!("Installing from {}", path.as_ref().display());
let mut archive = PackageArchive::new(PathBuf::from(path.as_ref()));
let ident = try!(archive.ident());
try!(fs::create_dir_all(PACKAGE_CACHE));
try!(fs::create_dir_all(CACHE_ARTIFACT_PATH));
for dep in try!(archive.tdeps()) {
try!(install_from_depot(url, &dep, dep.as_ref()));
}
Expand All @@ -94,7 +94,9 @@ fn install_from_depot<P: AsRef<PackageIdent>>(url: &str,
}
}
Err(_) => {
let mut archive = try!(depot_client::fetch_package(url, ident.as_ref(), PACKAGE_CACHE));
let mut archive = try!(depot_client::fetch_package(url,
ident.as_ref(),
CACHE_ARTIFACT_PATH));
let ident = try!(archive.ident());
try!(archive.unpack());
println!("Installed {}", ident);
Expand Down
17 changes: 6 additions & 11 deletions components/common/src/config_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
// the Software until such time that the Software is made available under an
// open source license such as the Apache 2.0 License.

use std;
use std::collections::HashMap;
use std::fmt;
use std::fs::{self, File};
use std::fs::File;
use std::io::prelude::*;
use std::path::{Path, PathBuf};

use hcore::fs::SERVICE_HOME;
use hcore::fs;
use hcore::service::ServiceGroup;
use openssl::crypto::hash as openssl_hash;
use rustc_serialize::hex::ToHex;
Expand Down Expand Up @@ -112,15 +113,9 @@ impl ConfigFile {

pub fn on_disk_path(&self) -> PathBuf {
if &self.file_name == "gossip.toml" {
PathBuf::from(format!("{}/{}/{}",
SERVICE_HOME,
self.service_group.service,
self.file_name))
fs::svc_path(&self.service_group.service).join(&self.file_name)
} else {
PathBuf::from(format!("{}/{}/files/{}",
SERVICE_HOME,
self.service_group.service,
self.file_name))
fs::svc_files_path(&self.service_group.service).join(&self.file_name)
}
}

Expand Down Expand Up @@ -156,7 +151,7 @@ impl ConfigFile {
let mut new_file = try!(File::create(&new_filename));
try!(new_file.write_all(&self.body));
}
try!(fs::rename(new_filename, self.on_disk_path()));
try!(std::fs::rename(new_filename, self.on_disk_path()));
Ok(true)
}
}
Expand Down
12 changes: 6 additions & 6 deletions components/core/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use rustc_serialize::base64::{STANDARD, ToBase64, FromBase64};
use time;

use error::{Error, Result};
use fs::KEY_CACHE;
use fs::CACHE_KEY_PATH;
use util::perm;

/// Habitat uses [libsodium](https://github.com/jedisct1/libsodium) and it's Rust
Expand Down Expand Up @@ -103,7 +103,7 @@ use util::perm;
/// It's possible to examine the contents of a `.hab` file from a Linux shell:
///
/// ```text
/// $ head -3 /opt/bldr/cache/pkgs/chef-glibc-2.22-20160310192356.bldr
/// $ head -3 /path/to/chef-glibc-2.22-20160310192356.bldr
/// habitat-20160405144945
/// BLAKE2b
/// w4yC7/QADdC+NfH/wgN5u4K94nMieb1TxTVzbSfpMwRQ4k+YwhLs1nDXSIbSC8jHdF/7/LqLWtgPvGDmoKIvBDI0aGpIcGdlNDJhMDBnQ3lsMVVFM0JvRlZGSHhXcnBuWWF0/// SllXTXo1ZDg9
Expand All @@ -130,9 +130,9 @@ static SECRET_BOX_KEY_SUFFIX: &'static str = "box.key";
/// See also: https://download.libsodium.org/doc/hashing/generic_hashing.html
static SIG_HASH_TYPE: &'static str = "BLAKE2b";

/// This environment variable allows you to override the fs::KEY_CACHE
/// This environment variable allows you to override the fs::CACHE_KEY_PATH
/// at runtime. This is useful for testing.
static HABITAT_KEY_CACHE_ENV_VAR: &'static str = "HABITAT_KEY_CACHE";
static CACHE_KEY_PATH_ENV_VAR: &'static str = "HAB_CACHE_KEY_PATH";

/// Create secret key files with these permissions
static PUBLIC_KEY_PERMISSIONS: &'static str = "0400";
Expand Down Expand Up @@ -179,10 +179,10 @@ fn env_var_or_default(env_var: &str, default: &str) -> String {
}

/// Return the canonical location for nacl keys
/// This value can be overridden via HABITAT_KEY_CACHE_ENV_VAR,
/// This value can be overridden via CACHE_KEY_PATH_ENV_VAR,
/// which is useful for testing
fn nacl_key_dir() -> String {
env_var_or_default(HABITAT_KEY_CACHE_ENV_VAR, KEY_CACHE)
env_var_or_default(CACHE_KEY_PATH_ENV_VAR, CACHE_KEY_PATH)
}

/// Calculate the BLAKE2b hash of a file
Expand Down
Loading