Skip to content

Commit

Permalink
Add the on-prem bootstrapping script
Browse files Browse the repository at this point in the history
Signed-off-by: Josh Black <raskchanky@gmail.com>
  • Loading branch information
raskchanky committed Feb 20, 2018
1 parent 03661d0 commit 37b0556
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 2 deletions.
22 changes: 20 additions & 2 deletions README.md
Expand Up @@ -31,5 +31,23 @@ Nagigate to http://${APP_HOSTNAME_OR_IP}/#/sign-in to access the Builder UI
## Debug Logging

1. `cd ${SRC_ROOT}`
1. for svc in originsrv api sessionsrv; do echo 'log_level="debug"' | hab config apply "builder-${svc}.default" $(date +%s) ; done
1. journalctl -fu hab-sup
1. `for svc in originsrv api sessionsrv; do echo 'log_level="debug"' | hab config apply "builder-${svc}.default" $(date +%s) ; done`
1. `journalctl -fu hab-sup`

## Adding an initial set of packages

1. If you'd like to bootstrap your depot with the latest set of stable packages
from the [core-plans repo](https://github.com/habitat-sh/on-prem-builder.git), there's a script for that.
1. Export a valid GitHub personal authentication token as `HAB_AUTH_TOKEN` in
your environment and run `sudo ./scripts/on-prem-install.sh`, passing the
root URL of your new depot as the first argument. For example:
`HAB_AUTH_TOKEN=abc123 ./scripts/on-prem-install.sh http://depot.example.com`
1. The above process currently does not currently support air-gapped environments and
will require internet access in order to work. It's also quite a lengthy
process, as it will download a large number of packages from the public
Habitat Depot and then re-upload those packages to your new on-prem depot.
It's also worth noting that the core packages downloaded will get installed
into the Habitat artifact cache (`/hab/cache/artifacts`) on the machine
where this script is run. Please ensure that you have plenty of free drive
space available. It also may be difficult to cleanup any unused packages
after this process has run.
101 changes: 101 additions & 0 deletions scripts/on-prem-install.sh
@@ -0,0 +1,101 @@
#!/bin/bash

# The purpose of this script is to download the latest version of every package in
# the core-plans repo (via hab pkg install) and then upload the resulting hab
# artifact cache. Note that this does not support air-gapped environments.
#
# Also note that if you run this on a machine that already has a populated hab
# artifact cache, you will likely be uploading more packages than you think.
# In practice, this will probably not be an issue.

set -eo pipefail

exists() {
if command -v $1 >/dev/null 2>&1
then
return 0
else
return 1
fi
}

check_tools() {
local ref=$1[@]

for tool in ${!ref}
do
if ! exists "$tool"; then
echo "Please install $tool and run this script again."
exit 1
fi
done
}

check_vars() {
local ref=$1[@]

for var in ${!ref}
do
if [ -z "${!var}" ]; then
echo "Please ensure that $var is exported in your environment and run this script again."
exit 1
fi
done
}

help() {
echo "Usage: on-prem-install.sh <ON_PREM_DEPOT_URL>"
}

if [ -z "$1" ]; then
help
exit 1
fi

required_tools=( git hab )
required_vars=( HAB_AUTH_TOKEN )

check_tools required_tools
check_vars required_vars

core_tmp=$(mktemp -d)
core="$core_tmp/core-plans"
artifact_cache="/hab/cache/artifacts"

mkdir -p "$artifact_cache"

git clone https://github.com/habitat-sh/core-plans.git "$core"
pushd "$core"
dir_list=$(find . -type f -name "plan.sh" -printf "%h\n" | sed -r "s|^\.\/||" | sort -u)
total=$(echo "$dir_list" | wc -l)
count="0"

for p in $dir_list
do
count=$((count+1))
echo ""
echo "[$count/$total] Installing latest version of core/$p"

hab pkg install core/$p || true # if this fails, it's likely because of a mismatched platform and we don't want to completely abort
done
popd

pushd "$artifact_cache"
harts=$(find . -type f -name "*.hart")
total=$(echo "$harts" | wc -l)
count="0"

for hart in $harts
do
count=$((count+1))
echo ""
echo "[$count/$total] Uploading $hart to the depot at $1"
hab pkg upload --url $1 --channel stable $hart || true # again, don't abort the whole process if an upload fails - just keep going.
done

echo "Package uploads finished."
popd

rm -fr "$core_tmp"

echo "Done."

0 comments on commit 37b0556

Please sign in to comment.