Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
121 lines (104 sloc) 3.81 KB
#
# Copyright:: Copyright (c) 2016 Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
pkg_name=ruby-rails-sample
pkg_version=0.0.2
pkg_origin=delivery-example
pkg_maintainer="The Habitat Maintainers <humans@habitat.sh>"
pkg_license=('mit')
pkg_source=https://github.com/jtimberman/ruby-rails-sample/archive/${pkg_version}.tar.gz
pkg_shasum=b8a75cdea714a69a13c429a1529452e47544da7c10f313930b453becd0d2ef20
pkg_deps=(
core/bundler
core/cacerts
core/glibc
core/libffi
core/libxml2
core/libxslt
core/libyaml
core/node
core/postgresql
core/ruby
)
pkg_build_deps=(
core/coreutils
core/gcc
core/make
)
pkg_svc_user="root"
pkg_svc_group=$pkg_svc_user
pkg_lib_dirs=(lib)
pkg_include_dirs=(include)
pkg_expose=(3000)
# The configure scripts for some RubyGems that build native extensions
# use `/usr/bin` paths for commands. This is not going to work in a
# studio where we don't have any of those commands. But we're kind of
# stuck because the native extension is going to be built during
# `bundle install`.
#
# We clean this link up in `do_install`.
do_prepare() {
build_line "Setting link for /usr/bin/env to 'coreutils'"
[[ ! -f /usr/bin/env ]] && ln -s "$(pkg_path_for coreutils)/bin/env" /usr/bin/env
return 0
}
do_build() {
# shellcheck disable=SC2153
export CPPFLAGS="${CPPFLAGS} ${CFLAGS}"
# shellcheck disable=SC2155
local _bundler_dir=$(pkg_path_for bundler)
# shellcheck disable=SC2155
local _libxml2_dir=$(pkg_path_for libxml2)
# shellcheck disable=SC2155
local _libxslt_dir=$(pkg_path_for libxslt)
# shellcheck disable=SC2155
local _postgresql_dir=$(pkg_path_for postgresql)
# shellcheck disable=SC2155
local _pgconfig=$_postgresql_dir/bin/pg_config
# shellcheck disable=SC2155
local _zlib_dir=$(pkg_path_for zlib)
# shellcheck disable=SC2154
export GEM_HOME=${pkg_prefix}/vendor/bundle
export GEM_PATH=${_bundler_dir}:${GEM_HOME}
# don't let bundler split up the nokogiri config string (it breaks
# the build), so specify it as an env var instead
export NOKOGIRI_CONFIG="--use-system-libraries --with-zlib-dir=${_zlib_dir} --with-xslt-dir=${_libxslt_dir} --with-xml2-include=${_libxml2_dir}/include/libxml2 --with-xml2-lib=${_libxml2_dir}/lib"
# we control the variable above, and it will be all on one line, and
# we need single quotes otherwise the extconf doesn't build the
# extension.
# shellcheck disable=SC2086,SC2016
bundle config build.nokogiri '${NOKOGIRI_CONFIG}'
bundle config build.pg --with-pg-config="${_pgconfig}"
# We need to add tzinfo-data to the Gemfile since we're not in an
# environment that has this from the OS
if ! grep -q 'gem .*tzinfo-data.*' Gemfile; then
echo 'gem "tzinfo-data"' >> Gemfile
fi
# Remove the specific ruby version, because our ruby is 2.3
sed -e 's/^ruby.*//' -i Gemfile
bundle install --jobs 2 --retry 5 --path vendor/bundle --binstubs
}
do_install() {
cp -R . "${pkg_prefix}/static"
for binstub in ${pkg_prefix}/static/bin/*; do
build_line "Setting shebang for ${binstub} to 'ruby'"
[[ -f $binstub ]] && sed -e "s#/usr/bin/env ruby#$(pkg_path_for ruby)/bin/ruby#" -i "$binstub"
done
if [[ $(readlink /usr/bin/env) = "$(pkg_path_for coreutils)/bin/env" ]]; then
build_line "Removing the symlink we created for '/usr/bin/env'"
rm /usr/bin/env
fi
}