Habitat build works for all versions, eliminates rake (#2301)

The Habitat plan has been modified to support building from the repo
rather than relying on a gem being pushed to RubyGems. This allows
us to build current packages at every merge rather than only pushing to
Habitat Builder when we promote to stable.

This change also enables Expeditor to perform builds for us and removes
the dependency on the rake task as it is no longer needed.

Signed-off-by: Adam Leff <adam@leff.co>
This commit is contained in:
Adam Leff 2017-11-13 23:01:51 -05:00 committed by Dominik Richter
parent 4f1e9eced6
commit 01b65db6c7
3 changed files with 49 additions and 41 deletions

View file

@ -10,6 +10,9 @@ docker_images:
build_args:
- GEM_SOURCE: http://artifactory.chef.co/omnibus-gems-local
habitat_packages:
- inspec
# Slack channel in Chef Software slack to send notifications about build failures, etc
slack:
notify_channel: inspec-notify
@ -43,6 +46,10 @@ merge_actions:
- "Omnibus: Skip Build"
- "Expeditor: Skip All"
only_if: built_in:bump_version
- built_in:trigger_habitat_package_build:
ignore_labels:
- "Habitat: Skip Build"
- "Expeditor: Skip All"
artifact_actions:
promoted_to_unstable:

View file

@ -150,23 +150,6 @@ task :release_docker do
sh('sh', '-c', cmd)
end
desc 'Release a new Habitat package'
task :release_habitat do
version = Inspec::VERSION
ENV['HAB_ORIGIN'] = "chef"
if Dir.exist?("./results") then
raise "Please remove the ./results directory"
end
if ! ENV.has_key?("HAB_AUTH_TOKEN") then
raise "Please set the HAB_AUTH_TOKEN environment variable"
end
cmd = "echo #{version} > ./habitat/VERSION && "\
"hab pkg build . && " \
"hab pkg upload ./results/*.hart --channel stable"
puts "--> #{cmd}"
sh('sh', '-c', cmd)
end
desc 'Release the website [deprecated]'
task :www do
puts 'The Rake tasks for releasing the website are now in the www/ directory.'

View file

@ -1,5 +1,6 @@
pkg_name=inspec
pkg_origin=chef
pkg_version=$(cat "$PLAN_CONTEXT/../VERSION")
pkg_description="InSpec is an open-source testing framework for infrastructure
with a human- and machine-readable language for specifying compliance,
security and policy requirements."
@ -24,30 +25,7 @@ pkg_build_deps=(
)
pkg_bin_dirs=(bin)
pkg_version() {
cat VERSION
}
do_before() {
if [[ ! -f VERSION ]]; then
exit_with "habitat/VERSION not found. Run 'rake release_habitat' to ensure it exists" 1
fi
update_pkg_version
}
do_prepare() {
# If we use the Gemfile in the project ($SRC_PATH/Gemfile), and run `bundle
# install` (which we do in `do_build` below), Bundler will write out a
# .bundle/config into the $SRC_PATH. If this happens, if you try to use
# InSpec outside of the build process it will fail, since the settings used
# in this plan will be saved in the .bundle/config.
#
# Instead, we build a minimal Gemfile in the $CACHE_PATH and bundle using that.
cat > "$CACHE_PATH/Gemfile" <<GEMFILE
source 'https://rubygems.org'
gem '$pkg_name', '= $pkg_version'
GEMFILE
export BUNDLE_SILENCE_ROOT_WARNING GEM_HOME GEM_PATH
BUNDLE_SILENCE_ROOT_WARNING=1
build_line "Setting BUNDLE_SILENCE_ROOT_WARNING=$BUNDLE_SILENCE_ROOT_WARNING"
@ -58,6 +36,26 @@ GEMFILE
}
do_build() {
# If we use the Gemfile in the project ($SRC_PATH/Gemfile), and run `bundle
# install` (which we do in `do_build` below), Bundler will write out a
# .bundle/config into the $SRC_PATH. If this happens, if you try to use
# InSpec outside of the build process it will fail, since the settings used
# in this plan will be saved in the .bundle/config.
#
# Instead, we first use Bundler to build up a local cache of gem dependencies.
# Then when we build, we'll build the InSpec gem and write out a new Gemfile
# to use that instead.
#
# Building up the local cache of dependencies is necessary because Bundler won't
# try and walk the sources if it finds the initial gem in the local cache.
build_line "Caching InSpec's gem dependencies..."
mkdir -p $CACHE_PATH/vendor/cache
cat > "$CACHE_PATH/Gemfile" <<GEMFILE
source 'https://rubygems.org'
gem '$pkg_name', path: "${PLAN_CONTEXT}/.."
GEMFILE
bundle install \
--binstubs "$pkg_prefix/bin" \
--gemfile "$CACHE_PATH/Gemfile" \
@ -66,6 +64,26 @@ do_build() {
--retry 5 \
--standalone
build_line "Building the InSpec gem..."
gem build inspec.gemspec
build_line "Moving the InSpec gem into the cache path..."
mv inspec-${pkg_version}.gem ${CACHE_PATH}/vendor/cache
build_line "Re-bundling with the new InSpec gem..."
cat > "$CACHE_PATH/Gemfile" <<GEMFILE
gem '$pkg_name', '= ${pkg_version}'
GEMFILE
bundle install \
--binstubs "$pkg_prefix/bin" \
--gemfile "$CACHE_PATH/Gemfile" \
--jobs "$(nproc)" \
--path "$pkg_prefix/bundle" \
--retry 5 \
--local \
--standalone
# Delete everything that's not inspec in bin
find "$pkg_prefix/bin" -type f -not -name 'inspec' -delete
@ -77,7 +95,7 @@ do_build() {
}
do_install() {
install -m 0644 Gemfile.lock "$pkg_prefix/Gemfile.lock"
install -m 0644 ${CACHE_PATH}/Gemfile.lock "$pkg_prefix/Gemfile.lock"
}
do_strip() {