Skip to content

Commit

Permalink
Merge pull request #374 from chef/fnichol/hab-paths-reorg
Browse files Browse the repository at this point in the history
Merged change 21c0986f-7ce2-49a2-ba88-2501fc72a7f9

From review branch fnichol/hab-paths-reorg into master

Signed-off-by: reset <[email protected]>
  • Loading branch information
chef-delivery committed Apr 12, 2016
2 parents b0285a2 + 307d049 commit a2da023
Show file tree
Hide file tree
Showing 75 changed files with 605 additions and 463 deletions.
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
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.
//!
//! # 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

0 comments on commit a2da023

Please sign in to comment.