├── bin ├── detect └── compile ├── LICENSE └── README.markdown /bin/detect: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | readonly BUILD_DIR=$1 6 | 7 | if [[ ! -n "${BUILD_DIR}" ]]; then 8 | echo "No build directory specified - exiting" 9 | exit 1 10 | fi 11 | 12 | if [[ ! -f "${BUILD_DIR}/.slug-post-clean" ]]; then 13 | echo "Could not find .slug-post-clean file - exiting" 14 | exit 1 15 | fi 16 | 17 | echo "POST BUILD CLEAN" 18 | exit 0 19 | -------------------------------------------------------------------------------- /bin/compile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | readonly BUILD_DIR=$1 6 | readonly CLEAN_FILES=.slug-post-clean 7 | 8 | if [[ ! -n "${BUILD_DIR}" ]]; then 9 | echo "No build directory specified - exiting" 10 | exit 1 11 | fi 12 | 13 | cd ${BUILD_DIR} 14 | 15 | if [[ ! -f "${CLEAN_FILES}" ]]; then 16 | echo "Could not find .slug-post-clean file - exiting" 17 | exit 1 18 | fi 19 | 20 | while read file; do 21 | [[ ! -n "${file}" ]] && continue 22 | 23 | if [[ -f "${file}" ]]; then 24 | echo "Removing file ${file} from slug" 25 | rm -f ${file} 26 | elif [[ -d "${file}" ]]; then 27 | echo "Removing directory ${file} from slug" 28 | rm -rf ${file} 29 | else 30 | echo "Location ${file} not found - ignoring" 31 | fi 32 | done <${CLEAN_FILES} 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Lostmy.name Ltd 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | # Post-build Clean Buildpack 2 | 3 | A simple buildpack to run after all other buildpacks have completed, 4 | which removes a set of files defined in `.slug-post-clean`, so that they 5 | are not included in the finished slug. 6 | 7 | ## Rationale 8 | 9 | While this may seem to duplicate functionality provided by Heroku's 10 | `.slugignore`, there is a key difference: `.slugignore`'d files are 11 | removed after the repo is cloned, but before any buildpack is run. They 12 | can therefore not be involved in the build process itself. 13 | 14 | However, it is not uncommon for there to exist files in the repo that 15 | are necessary for the build, but are not required at runtime. There may 16 | also be installable build dependencies that are not runtime 17 | dependencies. 18 | 19 | In our case, a complex front-end build involves significant CSS, JS and 20 | image assets, along with a large installation of node modules, all of 21 | which are used only for building the production assets, but then remain 22 | part of the slug. 23 | 24 | ## Usage 25 | 26 | You will need to use the [`heroku-buildpack-multi` 27 | buildpack](https://github.com/ddollar/heroku-buildpack-multi), and add 28 | your existing buildpack(s) to the `.buildpacks` file in your application 29 | repository. The post-build-clean buildpack **must** be last in the 30 | buildpack order: 31 | 32 | ``` 33 | # .buildpacks 34 | https://github.com/heroku/heroku-buildpack-nodejs 35 | https://github.com/heroku/heroku-buildpack-ruby 36 | https://github.com/Lostmyname/heroku-buildpack-post-build-clean 37 | ``` 38 | 39 | The `.slug-post-clean` file supports single-file and single-directory 40 | declarations only, e.g.: 41 | 42 | ``` 43 | some_huge_file.psd 44 | some/nested/directory 45 | why_does_this_app_even_contain_a.tiff 46 | ``` 47 | 48 | I might expand it to support file globs, but for the moment it's not 49 | necessary and the testing implications give me the willies. 50 | --------------------------------------------------------------------------------