From 326b8361882f02486000c8c39848fa3c05a4432a Mon Sep 17 00:00:00 2001 From: Gregor Wassmann Date: Fri, 20 May 2022 16:48:13 +0200 Subject: [PATCH 1/6] Allow ignoring paths --- README.md | 9 +++++---- bin/compile | 14 +++++++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 55960df..09a619d 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,11 @@ Add as a first buildpack in the chain. Set `PROJECT_PATH` environment variable t # How to use: 1. `heroku buildpacks:clear` if necessary -2. `heroku buildpacks:set https://github.com/timanovsky/subdir-heroku-buildpack` -3. `heroku buildpacks:add heroku/nodejs` or whatever buildpack you need for your application -4. `heroku config:set PROJECT_PATH=projects/nodejs/frontend` pointing to what you want to be a project root. -5. Deploy your project to Heroku. +1. `heroku buildpacks:set https://github.com/timanovsky/subdir-heroku-buildpack` +1. `heroku buildpacks:add heroku/nodejs` or whatever buildpack you need for your application +1. `heroku config:set PROJECT_PATH=projects/nodejs/frontend` pointing to what you want to be a 1roject root. +1. `heroku config:set KEEPS=./modules/alpha*:./modules/beta*` to specify what you want to keep using GLOBIGNORE syntax. +1. Deploy your project to Heroku. # How it works The buildpack takes subdirectory you configured, erases everything else, and copies that subdirectory to project root. Then normal Heroku slug compilation proceeds. diff --git a/bin/compile b/bin/compile index 086157a..c657a47 100755 --- a/bin/compile +++ b/bin/compile @@ -10,6 +10,7 @@ ENV_DIR=${3:-} if [ -f $ENV_DIR/PROJECT_PATH ]; then PROJECT_PATH=`cat $ENV_DIR/PROJECT_PATH` + if [ -d $BUILD_DIR/$PROJECT_PATH ]; then echo "-----> Subdir buildpack in $PROJECT_PATH" echo " creating cache: $CACHE_DIR" @@ -19,7 +20,16 @@ if [ -f $ENV_DIR/PROJECT_PATH ]; then echo " moving working dir: $PROJECT_PATH to $TMP_DIR" cp -R $BUILD_DIR/$PROJECT_PATH/. $TMP_DIR/ echo " cleaning build dir $BUILD_DIR" - rm -rf $BUILD_DIR/* + + # Optionally, keep some files using GLOBIGNORE pattern + $KEEPS='' + if [ -f $ENV_DIR/KEEPS ]; then + KEEPS=`cat $ENV_DIR/KEEPS` + echo " ignoring $KEEPS" + fi + + (GLOBIGNORE=$KEEPS; rm -rf $BUILD_DIR/*) + echo " copying preserved work dir from cache $TMP_DIR to build dir $BUILD_DIR" cp -R $TMP_DIR/. $BUILD_DIR/ echo " cleaning tmp dir $TMP_DIR" @@ -30,5 +40,3 @@ fi echo "PROJECT_PATH is undefined" exit 1 - - From f4d00c43623df1fb525109bdfc551b3f86651ef7 Mon Sep 17 00:00:00 2001 From: Gregor Wassmann Date: Sat, 21 May 2022 11:07:03 +0200 Subject: [PATCH 2/6] Typo --- bin/compile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/compile b/bin/compile index c657a47..14f5419 100755 --- a/bin/compile +++ b/bin/compile @@ -22,7 +22,7 @@ if [ -f $ENV_DIR/PROJECT_PATH ]; then echo " cleaning build dir $BUILD_DIR" # Optionally, keep some files using GLOBIGNORE pattern - $KEEPS='' + KEEPS='' if [ -f $ENV_DIR/KEEPS ]; then KEEPS=`cat $ENV_DIR/KEEPS` echo " ignoring $KEEPS" From 45d108b95ce4be4371207bd8d51e534f3e64e635 Mon Sep 17 00:00:00 2001 From: Gregor Wassmann Date: Wed, 25 May 2022 17:02:20 +0200 Subject: [PATCH 3/6] Debug --- README.md | 5 +++-- bin/compile | 32 +++++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 09a619d..e345ec3 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,9 @@ Add as a first buildpack in the chain. Set `PROJECT_PATH` environment variable t 1. `heroku buildpacks:clear` if necessary 1. `heroku buildpacks:set https://github.com/timanovsky/subdir-heroku-buildpack` 1. `heroku buildpacks:add heroku/nodejs` or whatever buildpack you need for your application -1. `heroku config:set PROJECT_PATH=projects/nodejs/frontend` pointing to what you want to be a 1roject root. -1. `heroku config:set KEEPS=./modules/alpha*:./modules/beta*` to specify what you want to keep using GLOBIGNORE syntax. +1. `heroku config:set PROJECT_PATH=projects/nodejs/frontend` pointing to what you want to be a project root. +1. `heroku config:set KEEPS=./dependencies:./vendor` to specify what you want to keep using GLOBIGNORE syntax. +1. `heroku config:set REMOVE_PATHS=./dependencies/other ./vendor/other` to specify what you want to remove that was previously ignored. 1. Deploy your project to Heroku. # How it works diff --git a/bin/compile b/bin/compile index 14f5419..b592ad6 100755 --- a/bin/compile +++ b/bin/compile @@ -10,16 +10,27 @@ ENV_DIR=${3:-} if [ -f $ENV_DIR/PROJECT_PATH ]; then PROJECT_PATH=`cat $ENV_DIR/PROJECT_PATH` - if [ -d $BUILD_DIR/$PROJECT_PATH ]; then echo "-----> Subdir buildpack in $PROJECT_PATH" + echo `pwd` + echo $SHELL + + # Optionally, unlink a folder + UNLINK='' + if [ -f $ENV_DIR/UNLINK ]; then + UNLINK=`cat $ENV_DIR/UNLINK` + echo " unlinking $BUILD_DIR/$UNLINK" + unlink $BUILD_DIR/$UNLINK + fi + echo " creating cache: $CACHE_DIR" mkdir -p $CACHE_DIR TMP_DIR=`mktemp -d $CACHE_DIR/subdirXXXXX` echo " created tmp dir: $TMP_DIR" echo " moving working dir: $PROJECT_PATH to $TMP_DIR" cp -R $BUILD_DIR/$PROJECT_PATH/. $TMP_DIR/ - echo " cleaning build dir $BUILD_DIR" + + echo " cleaning build dir $BUILD_DIR" # Optionally, keep some files using GLOBIGNORE pattern KEEPS='' @@ -28,12 +39,27 @@ if [ -f $ENV_DIR/PROJECT_PATH ]; then echo " ignoring $KEEPS" fi - (GLOBIGNORE=$KEEPS; rm -rf $BUILD_DIR/*) + # Enter build dir + cd $BUILD_DIR + (GLOBIGNORE=".:..:.buildpacks:$KEEPS"; rm -rf ./*) + + # Optionally, remove some paths previously ignored + if [ -f $ENV_DIR/REMOVE_PATHS ]; then + REMOVE_PATHS=`cat $ENV_DIR/REMOVE_PATHS` + echo " removing $REMOVE_PATHS" + rm -rf $REMOVE_PATHS + fi + + cd - + # End entering build dir echo " copying preserved work dir from cache $TMP_DIR to build dir $BUILD_DIR" cp -R $TMP_DIR/. $BUILD_DIR/ echo " cleaning tmp dir $TMP_DIR" rm -rf $TMP_DIR + + echo `ls -1q $BUILD_DIR/*` + exit 0 fi fi From bbae3203f5ab6b6eda1da5e5d6c73edb028d4c63 Mon Sep 17 00:00:00 2001 From: Gregor Wassmann Date: Wed, 1 Jun 2022 12:18:59 +0200 Subject: [PATCH 4/6] Skip extra removals --- README.md | 1 - bin/compile | 8 -------- 2 files changed, 9 deletions(-) diff --git a/README.md b/README.md index e345ec3..5a0f750 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,6 @@ Add as a first buildpack in the chain. Set `PROJECT_PATH` environment variable t 1. `heroku buildpacks:add heroku/nodejs` or whatever buildpack you need for your application 1. `heroku config:set PROJECT_PATH=projects/nodejs/frontend` pointing to what you want to be a project root. 1. `heroku config:set KEEPS=./dependencies:./vendor` to specify what you want to keep using GLOBIGNORE syntax. -1. `heroku config:set REMOVE_PATHS=./dependencies/other ./vendor/other` to specify what you want to remove that was previously ignored. 1. Deploy your project to Heroku. # How it works diff --git a/bin/compile b/bin/compile index b592ad6..b27ed4e 100755 --- a/bin/compile +++ b/bin/compile @@ -42,14 +42,6 @@ if [ -f $ENV_DIR/PROJECT_PATH ]; then # Enter build dir cd $BUILD_DIR (GLOBIGNORE=".:..:.buildpacks:$KEEPS"; rm -rf ./*) - - # Optionally, remove some paths previously ignored - if [ -f $ENV_DIR/REMOVE_PATHS ]; then - REMOVE_PATHS=`cat $ENV_DIR/REMOVE_PATHS` - echo " removing $REMOVE_PATHS" - rm -rf $REMOVE_PATHS - fi - cd - # End entering build dir From 66a22f885bf2d61df413741abded4e95e33abe9e Mon Sep 17 00:00:00 2001 From: Gregor Wassmann Date: Wed, 1 Jun 2022 12:21:12 +0200 Subject: [PATCH 5/6] Remove debugging --- README.md | 10 +++++----- bin/compile | 7 +------ 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 5a0f750..aa271f1 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ Add as a first buildpack in the chain. Set `PROJECT_PATH` environment variable t # How to use: 1. `heroku buildpacks:clear` if necessary -1. `heroku buildpacks:set https://github.com/timanovsky/subdir-heroku-buildpack` -1. `heroku buildpacks:add heroku/nodejs` or whatever buildpack you need for your application -1. `heroku config:set PROJECT_PATH=projects/nodejs/frontend` pointing to what you want to be a project root. -1. `heroku config:set KEEPS=./dependencies:./vendor` to specify what you want to keep using GLOBIGNORE syntax. -1. Deploy your project to Heroku. +2. `heroku buildpacks:set https://github.com/timanovsky/subdir-heroku-buildpack` +3. `heroku buildpacks:add heroku/nodejs` or whatever buildpack you need for your application +4. `heroku config:set PROJECT_PATH=projects/nodejs/frontend` pointing to what you want to be a project root. +5. `heroku config:set KEEPS=./dependencies:./vendor` to specify what you want to keep using GLOBIGNORE syntax. +5. Deploy your project to Heroku. # How it works The buildpack takes subdirectory you configured, erases everything else, and copies that subdirectory to project root. Then normal Heroku slug compilation proceeds. diff --git a/bin/compile b/bin/compile index b27ed4e..974d44c 100755 --- a/bin/compile +++ b/bin/compile @@ -12,10 +12,8 @@ if [ -f $ENV_DIR/PROJECT_PATH ]; then PROJECT_PATH=`cat $ENV_DIR/PROJECT_PATH` if [ -d $BUILD_DIR/$PROJECT_PATH ]; then echo "-----> Subdir buildpack in $PROJECT_PATH" - echo `pwd` - echo $SHELL - # Optionally, unlink a folder + # Optionally, unlink a folder. This may be needed to keep Gemfiles, etc. unchanged. UNLINK='' if [ -f $ENV_DIR/UNLINK ]; then UNLINK=`cat $ENV_DIR/UNLINK` @@ -49,9 +47,6 @@ if [ -f $ENV_DIR/PROJECT_PATH ]; then cp -R $TMP_DIR/. $BUILD_DIR/ echo " cleaning tmp dir $TMP_DIR" rm -rf $TMP_DIR - - echo `ls -1q $BUILD_DIR/*` - exit 0 fi fi From ccc2eff60ef71b0f6c5584a8cda883dee7b671a6 Mon Sep 17 00:00:00 2001 From: Gregor Wassmann Date: Wed, 1 Jun 2022 12:30:15 +0200 Subject: [PATCH 6/6] Docs --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index aa271f1..3c3fbf4 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ Add as a first buildpack in the chain. Set `PROJECT_PATH` environment variable t 3. `heroku buildpacks:add heroku/nodejs` or whatever buildpack you need for your application 4. `heroku config:set PROJECT_PATH=projects/nodejs/frontend` pointing to what you want to be a project root. 5. `heroku config:set KEEPS=./dependencies:./vendor` to specify what you want to keep using GLOBIGNORE syntax. +5. `heroku config:set UNLINK=projects/nodejs/frontend/dependencies` to unlink a symlink that may be used. 5. Deploy your project to Heroku. # How it works