git.iko.soy/heroku-buildpack-stack
on master help sign in
Merge pull request #11 from mfine/mfine-stack-vars

Templating stack.yaml, take 2

commitf1a13fc4cadae738f7d659fcb1263cd0725bb750 authorMark Fine <mark.fine@gmail.com> dateWed 22 Jun 2016, 18:54 (10 years ago) parent33b95eb567da77
3 files changed+31−2
README.md+23 bin/compile+7−1 bin/detect+1−1
README.md+23
@@ -12,6 +12,29 @@ Set this buildpack on an exiting app:
1212
1313 $ heroku buildpacks:set https://github.com/mfine/heroku-buildpack-stack
1414
15+### Templating stack.yaml
16+
17+To avoid committing secrets into `stack.yaml` for access to private
18+repos, an app's config vars values can be substituted for tags
19+enclosed in double brackets. For example, given a `stack.yaml` containing:
20+
21+ packages:
22+ -location:
23+ git: https://mfine:{{GITPASS}}@github.com/mfine/heroku-buildpack-stack.git
24+
25+and an application with config vars:
26+
27+ $ heroku config -app calm-storm-51595
28+ === murmuring-beyond-51595 Config Vars
29+ GITPASS: abc123
30+ $
31+
32+before compilation, the `stack.yaml` will be substituted as follows:
33+
34+ packages:
35+ -location:
36+ git: https://mfine:abc123@github.com/mfine/heroku-buildpack-stack.git
37+
1538[1]: https://github.com/mfine/heroku-buildpack-stack
1639[2]: http://devcenter.heroku.com/articles/buildpacks
1740[3]: https://github.com/commercialhaskell/stack
bin/compile+7−1
@@ -63,7 +63,7 @@ speak "Restoring $LIBGMP_VER files from cache"
6363rsync -avq "$LIBGMP_DIR/ghc-libs/" "$WORK_DIR/vendor/ghc-libs"
6464
6565########## stack exe ###############################################
66−STACK_VER=${STACK_VER:-1.0.4}
66+STACK_VER=${STACK_VER:-1.1.2}
6767STACK_URL=${STACK_URL:-https://github.com/commercialhaskell/stack/releases/download/v"$STACK_VER"/stack-"$STACK_VER"-linux-x86_64.tar.gz}
6868STACK_DIR="$CACHE_DIR/stack-$STACK_VER"
6969STACK_EXE="$STACK_DIR/stack"
@@ -76,6 +76,12 @@ speak "Restoring stack-$STACK_VER"
7676rsync -avq "$STACK_EXE" "$WORK_DIR/vendor/bin/stack"
7777chmod a+x "$WORK_DIR/vendor/bin/stack"
7878
79+########## stack vars ##############################################
80+if [ -d "$ENV_DIR" ]; then
81+ speak "Substituting stack vars"
82+ perl -p -i -e 's/\{\{([^}]+)\}\}/defined$ENV{$1}?$ENV{$1}:$&/eg' "$BUILD_DIR/stack.yaml"
83+fi
84+
7985########## project build ###########################################
8086speak "Running stack"
8187cd "$BUILD_DIR"
bin/detect+1−1
@@ -1,6 +1,6 @@
11#!/usr/bin/env bash
22
3−if [ -n "$(find "$1" -name stack.yaml -print -quit)" ]; then
3+if [ -n "$(find "$1" -name stack.yaml -maxdepth 1 -print -quit)" ]; then
44 echo "Haskell"
55 exit 0
66else