Skip to content

Commit

Permalink
[plan-build] Generate blake2b hashes in src dir & fix HAB_BIN.
Browse files Browse the repository at this point in the history
This change addresses 2 issues:

* The file that contains the cryptographic hashes to be stored in the
  `FILES` metadata file needs to be created under the source cache, not
  in the `$PLAN_CONTEXT` directory.
* The `$HAB_BIN` variable must be used throughout the program and not
  the `$_hab_cmd` variable, who's role has been downplayed.

References #725

Signed-off-by: Fletcher Nichol <[email protected]>
  • Loading branch information
fnichol committed Jun 11, 2016
1 parent e255813 commit 9a9f746
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions components/plan-build/bin/hab-plan-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,6 @@ _ensure_origin_key_present() {
# * `$_shasum_cmd` (either gsha256sum or sha256sum on system)
# * `$_tar_cmd` (GNU version of tar)
# * `$_mktemp_cmd` (GNU version from coreutils)
# * `$_hab_cmd` (hab CLI for signing artifacts)
#
# Note that all of the commands noted above are considered internal
# implementation details and are subject to change with little to no notice,
Expand Down Expand Up @@ -1856,13 +1855,15 @@ _build_metadata() {

# Generate the blake2b hashes of all the files in the package. This
# is not in the resulting MANIFEST because MANIFEST is included!
pushd "$HAB_CACHE_SRC_PATH/$pkg_dirname" > /dev/null
build_line "Generating blake2b hashes of all files in the package"
find $pkg_prefix -type f \
| $_sort_cmd \
| while read file; do _generate_blake2b $file; done > ${pkg_name}_blake2b_hashes_list
| while read file; do _b2sum $file; done > ${pkg_name}_blake2bsums

build_line "Generating signed metadata FILES"
$_hab_cmd pkg sign --origin $pkg_origin ${pkg_name}_blake2b_hashes_list $pkg_prefix/FILES
$HAB_BIN pkg sign --origin $pkg_origin ${pkg_name}_blake2bsums $pkg_prefix/FILES
popd > /dev/null
return 0
}

Expand Down Expand Up @@ -2053,8 +2054,8 @@ EOT
#
# TODO: (jtimberman) If `hab pkg hash` itself starts to output
# like `sha256sum` at some point, we'll need to update this function.
_generate_blake2b() {
echo -en "$($_hab_cmd pkg hash $1) $1\n"
_b2sum() {
echo -en "$($HAB_BIN pkg hash $1) $1\n"
}

# **Internal** Create the package artifact with `tar`/`hab pkg sign`
Expand All @@ -2067,13 +2068,13 @@ _generate_artifact() {
rm -fv $tarf $xzf $pkg_artifact
$_tar_cmd -cf $tarf $pkg_prefix
$_xz_cmd --compress -6 --threads=0 --verbose $tarf
$_hab_cmd pkg sign --origin $pkg_origin $xzf $pkg_artifact
$HAB_BIN pkg sign --origin $pkg_origin $xzf $pkg_artifact
rm -f $tarf $xzf
}

_prepare_build_outputs() {
_pkg_sha256sum=$($_shasum_cmd $pkg_artifact | cut -d " " -f 1)
_pkg_blake2bsum=$($_hab_cmd pkg hash $pkg_artifact)
_pkg_blake2bsum=$($HAB_BIN pkg hash $pkg_artifact)
mkdir -pv $pkg_output_path
cp -v $pkg_artifact $pkg_output_path/

Expand Down

0 comments on commit 9a9f746

Please sign in to comment.