Heroku buildpack env with working {detect,release}

This commit is contained in:
Susan Potter 2012-02-18 01:25:51 -06:00
parent 02ca331708
commit 26bfc04768
15 changed files with 269 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
tmp/
.rvmrc

11
.rvmrc.example Normal file
View file

@ -0,0 +1,11 @@
rvm use 1.9.2@cabal-heroku-buildpack
BUILDPACK_GHC_BASE_URL="http://www.haskell.org/ghc/dist"
GHC_BOOTSTRAP_VERSION=7.0.4
export GHC_BOOTSTRAP_VERSION BUILDPACK_GHC_BASE_URL
# Aruba envvars
ARUBA_REPORT_TEMPLATES=templates
ARUBA_REPORT_DIR=doc
export ARUBA_REPORT_TEMPLATES ARUBA_REPORT_DIR

5
Gemfile Normal file
View file

@ -0,0 +1,5 @@
source :rubygems
group :testing do
gem 'aruba'
end

37
Gemfile.lock Normal file
View file

@ -0,0 +1,37 @@
GEM
remote: http://rubygems.org/
specs:
aruba (0.4.11)
childprocess (>= 0.2.3)
cucumber (>= 1.1.1)
ffi (>= 1.0.11)
rspec (>= 2.7.0)
builder (3.0.0)
childprocess (0.3.1)
ffi (~> 1.0.6)
cucumber (1.1.5)
builder (>= 2.1.2)
diff-lcs (>= 1.1.2)
gherkin (~> 2.8.0)
json (>= 1.4.6)
term-ansicolor (>= 1.0.6)
diff-lcs (1.1.3)
ffi (1.0.11)
gherkin (2.8.0)
json (>= 1.4.6)
json (1.6.5)
rspec (2.8.0)
rspec-core (~> 2.8.0)
rspec-expectations (~> 2.8.0)
rspec-mocks (~> 2.8.0)
rspec-core (2.8.0)
rspec-expectations (2.8.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.8.0)
term-ansicolor (1.0.7)
PLATFORMS
ruby
DEPENDENCIES
aruba

47
README.md Normal file
View file

@ -0,0 +1,47 @@
# GHC/Cabal Heroku Buildpack
This is a custom Heroku buildpack for Haskell applications that are built
using GHC and Cabal.
## Version / Dependencies
Based on the current (as of this writing) Haskell Platform (2011.4.0.0 ->
GHC v7.0.4).
Work will be done after some level of stability to update this buildpack
to support GHC 7.4.x soon thereafter.
The goal will be to allow some variance of GHC and Platform versions. At
present there are zero plans to actively support GHC 6.x with this
buildpack. If it happens to work, then great, otherwise you are free to fork
this repository to make it work for your needs.
## Status
Experimental; in progress - still testing.
## Usage
Like other buildpacks you will need to specify the buildpack when creating
your Heroku application. Something like the following:
heroku create --stack cedar --buildpack https://github.com/mbbx6spp/cabal-heroku-buildpack
You will also need to specify environment variables after your app is
created. For instance,
BUILDPACK_GHC_BASE_URL
BUILDPACK_PLATFORM_BASE_URL
These should be your S3 base URL for the GHC bootstrap and Platform
distributions respectively.
More to be said, but I am too tired to write it now.
Check back soon.
## Contributors
* Susan Potter [mbbx6spp on GitHub](https://github.com/mbbx6spp)

22
Rakefile Normal file
View file

@ -0,0 +1,22 @@
# encoding: utf-8
require 'rubygems'
require 'bundler'
Bundler.setup(:testing)
require 'cucumber/rake/task'
def darwin?
os=%x[uname -s]
"Darwin" === os
end
Cucumber::Rake::Task.new do |t|
opts = defined?(JRUBY_VERSION) ? %w{--tags ~@jruby} : []
opts += %w{--tags ~@fails-on-darwin} if darwin?
t.cucumber_opts = opts
end
desc "Run Cucumber features"
task :test => [:cucumber]
task :default => :test

30
bin/compile Executable file
View file

@ -0,0 +1,30 @@
#!/usr/bin/env bash
# bin/compile BUILD_DIR CACHE_DIR
set -e
source scripts/functions
BUILD_DIR=$1
CACHE_DIR=$2
## CHECK BUILDPACK_GHC_BASE_URL is set
if [ "$BUILDPACK_GHC_BASE_URL" != "" ]; then
arch=$(uname -m)
ghcver=$GHC_BOOTSTRAP_VERSION
bsdir=$CACHE_DIR/bootstrap
ghcurl="$BUILDPACK_GHC_BASE_URL/$ghcver/ghc-$ghcver-$arch-unknown-linux.tar.bz2"
echo "Info: bootstrap directory: ${bsdir}";
echo "Info: bootstrap URL: $ghcurl";
if [ -f "$bsdir.completed" ]; then
echo "Info: already downloaded GHC bootstrap version ${ghcver}";
else
echo "Info: downloading GHC $ghcver form $ghcurl";
$(downloadAndExtract $bsdir $ghcurl);
$(configureMakeInstall $bsdir/ghc-$ghcver $BUILD_DIR/bootstrap/ghc-$ghcver);
touch $bsdir.completed
fi;
else
echo "Error: please set BUILDPACK_GHC_BASE_URL";
exit 1;
fi

15
bin/detect Executable file
View file

@ -0,0 +1,15 @@
#!/usr/bin/env bash
# bin/detect BUILD_DIR
set -e
BUILD_DIR=$1
echo $BUILD_DIR
CABAL_FILE="$(find $BUILD_DIR -maxdepth 1 -name '*.cabal' -print -quit)"
# Check a *.cabal file exists at the root of the source tree
if [[ -e $CABAL_FILE ]]; then
echo "GHC/Cabal" && exit 0
else
echo "nada" && exit 1
fi

19
bin/release Executable file
View file

@ -0,0 +1,19 @@
#!/usr/bin/env bash
# bin/release BUILD_DIR
BUILD_DIR=$1
cat <<EOF
---
config_vars:
GHC_PACKAGE_PATH: "$BUILD_DIR/ghc-packages.conf:"
GHCRTS: "-M512m -c70 -H128m"
HASKELL_PLATFORM_VERSION: 2011.4.0.0
GHC_BOOTSTRAP_VERSION: 7.0.4
BUILDPACK_GHC_BASE_URL:
BUILDPACK_PLATFORM_BASE_URL:
addons:
- shared-database:5mb
default_process_types:
EOF

15
features/detect.feature Normal file
View file

@ -0,0 +1,15 @@
Feature: Detect
In order to build and deploy an application
As the bin/detect script of the buildpack
I want to determine if the source tree is buildable
Scenario: no *.cabal file
When I run `detect ../features/fixtures/invaliddir`
Then the output should contain "nada"
And the exit status should be 1
Scenario: a *.cabal file
When I run `detect ../features/fixtures/validdir`
Then the output should contain "GHC/Cabal"
And the exit status should be 0

View file

12
features/release.feature Normal file
View file

@ -0,0 +1,12 @@
Feature: Release
In order to build and deploy an application
As the bin/release script of the buildpack
I want to setup the build environment
Scenario: default
When I run `release`
Then the output should contain "addons:"
And the output should contain "config_vars:"
And the output should contain "default_process_types:"
And the exit status should be 0

View file

17
features/support/env.rb Normal file
View file

@ -0,0 +1,17 @@
require 'rubygems'
require 'aruba/cucumber'
require 'fileutils'
require 'rspec/expectations'
ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
Before do
@aruba_timeout_seconds = 5
@dirs = ["bin"]
end
Aruba.configure do |config|
config.before_cmd do |cmd|
puts "About to run '#{cmd}'"
end
end

37
scripts/functions Normal file
View file

@ -0,0 +1,37 @@
function indent() {
c='s/^/ /'
case $(uname) in
Darwin) sed -l "$c";;
*) sed -u "$c";;
esac
}
function clearEnvironment() {
unset GIT_DIR
}
function downloadAndExtract() {
mkdir -p $1 && curl $2 -o - | tar jxf - -C $1
}
function configureMakeInstall() {
pushd $1
echo -n "Info: configure --prefix=$2"
./configure --prefix=$2;
echo "[OK]"
echo -n "Info: make"
make
echo "[OK]";
echo -n "Info: make install"
make install
echo "[OK]"
popd
}
function mkCompilerDir() {
local compilerDir=$CACHE_DIR/compilers/$1;
[[ ! -d "$compilerDir" ]]; mkdir -p $compilerDir;
echo $compilerDir;
}