From 775bffe4a9973a821e4a075a51b97f15dc9dd160 Mon Sep 17 00:00:00 2001 From: Simo Kinnunen Date: Wed, 1 Jul 2015 18:44:31 +0900 Subject: [PATCH] Get rid of our internal "build system" and switch to a CI-buildable Dockerfile instead. --- .dockerignore | 14 ++++ .gitignore | 1 - .npmignore | 2 - Dockerfile | 29 ++++++++ buildpack/bin/common.sh | 8 --- buildpack/bin/compact | 19 ----- buildpack/bin/compile | 17 ----- buildpack/buildpacks/bower/bin/common.sh | 26 ------- buildpack/buildpacks/bower/bin/compile | 56 --------------- buildpack/buildpacks/bower/bin/detect | 8 --- buildpack/buildpacks/gulp/bin/common.sh | 26 ------- buildpack/buildpacks/gulp/bin/compile | 29 -------- buildpack/buildpacks/gulp/bin/detect | 8 --- buildpack/buildpacks/node/README.md | 1 - buildpack/buildpacks/node/bin/common.sh | 38 ---------- buildpack/buildpacks/node/bin/compact | 27 ------- buildpack/buildpacks/node/bin/compile | 92 ------------------------ buildpack/buildpacks/node/bin/detect | 8 --- buildpack/image | 1 - 19 files changed, 43 insertions(+), 367 deletions(-) create mode 100644 .dockerignore delete mode 100644 buildpack/bin/common.sh delete mode 100755 buildpack/bin/compact delete mode 100755 buildpack/bin/compile delete mode 100644 buildpack/buildpacks/bower/bin/common.sh delete mode 100755 buildpack/buildpacks/bower/bin/compile delete mode 100755 buildpack/buildpacks/bower/bin/detect delete mode 100644 buildpack/buildpacks/gulp/bin/common.sh delete mode 100755 buildpack/buildpacks/gulp/bin/compile delete mode 100755 buildpack/buildpacks/gulp/bin/detect delete mode 100644 buildpack/buildpacks/node/README.md delete mode 100644 buildpack/buildpacks/node/bin/common.sh delete mode 100755 buildpack/buildpacks/node/bin/compact delete mode 100755 buildpack/buildpacks/node/bin/compile delete mode 100755 buildpack/buildpacks/node/bin/detect delete mode 100644 buildpack/image diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..985d7f8e9 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,14 @@ +*.mo +*.tgz +.DS_Store +.env +.git/ +.idea/ +Dockerfile +node_modules/ +npm-debug.log +res/bower_components/ +res/build/ +rethinkdb_data/ +temp/ +tmp/ diff --git a/.gitignore b/.gitignore index 2757e3387..1287ffea8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ .idea/ /*.tgz /.env -/.heroku/ /doc/*.png /node_modules/ /res/bower_components/ diff --git a/.npmignore b/.npmignore index fdfe53e9d..3986963d2 100644 --- a/.npmignore +++ b/.npmignore @@ -5,14 +5,12 @@ /.editorconfig /.env /.gitignore -/.heroku/ /.idea/ /.jscsrc /.npmignore /.npmrc /Dockerfile /bower.json -/buildpack/ /component.json /doc/ /gulpfile.js diff --git a/Dockerfile b/Dockerfile index 233db08e8..f68cf4527 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,41 @@ FROM sorccu/node:0.12.2 MAINTAINER Simo Kinnunen +# Install requirements. RUN export DEBIAN_FRONTEND=noninteractive && \ apt-get update && \ apt-get -y install libzmq3-dev libprotobuf-dev git graphicsmagick && \ apt-get clean && \ rm -rf /var/cache/apt/* +# Add a user for the app. +RUN useradd --system \ + --no-create-home \ + --shell /usr/sbin/nologin \ + --home-dir /app \ + stf + +# Sneak the stf executable into $PATH. ENV PATH /app/bin:$PATH +# Work in app dir by default. +WORKDIR /app + +# Export default app port, not enough for all processes but it should do +# for now. +EXPOSE 3000 + +# Copy app source. +COPY . /app/ + +# Get the rest of the dependencies and build. +RUN export PATH=/app/node_modules/.bin:$PATH && \ + npm install && \ + bower install --allow-root && \ + gulp build + +# Switch to weak user. +USER stf + +# Show help by default. CMD stf --help diff --git a/buildpack/bin/common.sh b/buildpack/bin/common.sh deleted file mode 100644 index e04b57f0b..000000000 --- a/buildpack/bin/common.sh +++ /dev/null @@ -1,8 +0,0 @@ -error() { - echo " ! $*" >&2 - exit 1 -} - -status() { - echo "-----> $*" -} diff --git a/buildpack/bin/compact b/buildpack/bin/compact deleted file mode 100755 index e28bd50f3..000000000 --- a/buildpack/bin/compact +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - -set -e # fail fast -set -o pipefail # don't ignore exit codes when piping output -# set -x # enable debugging - -bp_dir=$(cd $(dirname $0); cd ..; pwd) - -# Load some convenience functions like status() -source $bp_dir/bin/common.sh - -for pack in node bower gulp; do - if name=$($bp_dir/buildpacks/$pack/bin/detect "$@"); then - if test -f $bp_dir/buildpacks/$pack/bin/compact; then - status "Compacting ${name}" - $bp_dir/buildpacks/$pack/bin/compact "$@" - fi - fi -done diff --git a/buildpack/bin/compile b/buildpack/bin/compile deleted file mode 100755 index 154b55d82..000000000 --- a/buildpack/bin/compile +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash - -set -e # fail fast -set -o pipefail # don't ignore exit codes when piping output -# set -x # enable debugging - -bp_dir=$(cd $(dirname $0); cd ..; pwd) - -# Load some convenience functions like status() -source $bp_dir/bin/common.sh - -for pack in node bower gulp; do - if name=$($bp_dir/buildpacks/$pack/bin/detect "$@"); then - status "Detected ${name}" - $bp_dir/buildpacks/$pack/bin/compile "$@" - fi -done diff --git a/buildpack/buildpacks/bower/bin/common.sh b/buildpack/buildpacks/bower/bin/common.sh deleted file mode 100644 index 1dfda70a3..000000000 --- a/buildpack/buildpacks/bower/bin/common.sh +++ /dev/null @@ -1,26 +0,0 @@ -error() { - echo " ! $*" >&2 - exit 1 -} - -status() { - echo "-----> $*" -} - -protip() { - echo - echo "PRO TIP: $*" | indent - echo "See https://devcenter.heroku.com/articles/nodejs-support" | indent - echo -} - -# sed -l basically makes sed replace and buffer through stdin to stdout -# so you get updates while the command runs and dont wait for the end -# e.g. npm install | indent -indent() { - c='s/^/ /' - case $(uname) in - Darwin) sed -l "$c";; # mac/bsd sed: -l buffers on line boundaries - *) sed -u "$c";; # unix/gnu sed: -u unbuffered (arbitrary) chunks of data - esac -} diff --git a/buildpack/buildpacks/bower/bin/compile b/buildpack/buildpacks/bower/bin/compile deleted file mode 100755 index 8b067401f..000000000 --- a/buildpack/buildpacks/bower/bin/compile +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env bash - -set -e # fail fast -set -o pipefail # don't ignore exit codes when piping output -# set -x # enable debugging - -# Configure directories -build_dir=$1 -cache_dir=$2 -env_dir=$3 - -bp_dir=$(cd $(dirname $0); cd ..; pwd) - -# Load some convenience functions like status() and indent() -source $bp_dir/bin/common.sh - -# Expose user-installed bower -export PATH=$build_dir/node_modules/.bin:$PATH - -# Get bower version -bower_bin=$(which bower) -bower_version=$(bower --version) -status "Using Bower $bower_version from ${bower_bin#$build_dir/}" - -# Run subsequent node/bower commands from the build path -cd $build_dir - -# Figure out where Bower should install the components -bower_install=$(node -pe 'JSON.parse(require("fs").readFileSync(process.argv[1])).directory || "bower_components"' .bowerrc) - -# If the bower installation directory is checked into source control -# then assume that we are not supposed to touch it. Otherwise, restore -# from the build cache. -if test -d $build_dir/$bower_install; then - status "Found existing $bower_install directory; skipping cache" -elif test -d $cache_dir/bower/install; then - status "Restoring $bower_install directory from cache" - cp -r $cache_dir/bower/install $build_dir/$bower_install - - status "Pruning cached dependencies not specified in bower.json" - bower --allow-root --config.cwd=$build_dir prune 2>&1 | indent -fi - -status "Installing bower dependencies" -bower --allow-root --config.cwd=$build_dir --config.storage.packages=$cache_dir/bower/packages --config.storage.registry=$cache_dir/bower/registry install 2>&1 | indent - -# Purge bower-related cached content, being careful not to purge the top-level -# cache, for the sake of heroku-buildpack-multi apps. -rm -rf $cache_dir/bower -mkdir -p $cache_dir/bower - -# If app has a node_modules directory, cache it. -if test -d $build_dir/$bower_install; then - status "Caching $bower_install directory for future builds" - cp -r $build_dir/$bower_install $cache_dir/bower/install/ -fi diff --git a/buildpack/buildpacks/bower/bin/detect b/buildpack/buildpacks/bower/bin/detect deleted file mode 100755 index 48ff27e7b..000000000 --- a/buildpack/buildpacks/bower/bin/detect +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -# bin/detect - -if [ -f $1/.bowerrc ]; then - echo "Bower" && exit 0 -else - echo "no" && exit 1 -fi diff --git a/buildpack/buildpacks/gulp/bin/common.sh b/buildpack/buildpacks/gulp/bin/common.sh deleted file mode 100644 index 1dfda70a3..000000000 --- a/buildpack/buildpacks/gulp/bin/common.sh +++ /dev/null @@ -1,26 +0,0 @@ -error() { - echo " ! $*" >&2 - exit 1 -} - -status() { - echo "-----> $*" -} - -protip() { - echo - echo "PRO TIP: $*" | indent - echo "See https://devcenter.heroku.com/articles/nodejs-support" | indent - echo -} - -# sed -l basically makes sed replace and buffer through stdin to stdout -# so you get updates while the command runs and dont wait for the end -# e.g. npm install | indent -indent() { - c='s/^/ /' - case $(uname) in - Darwin) sed -l "$c";; # mac/bsd sed: -l buffers on line boundaries - *) sed -u "$c";; # unix/gnu sed: -u unbuffered (arbitrary) chunks of data - esac -} diff --git a/buildpack/buildpacks/gulp/bin/compile b/buildpack/buildpacks/gulp/bin/compile deleted file mode 100755 index fac335996..000000000 --- a/buildpack/buildpacks/gulp/bin/compile +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bash - -set -e # fail fast -set -o pipefail # don't ignore exit codes when piping output -# set -x # enable debugging - -# Configure directories -build_dir=$1 -cache_dir=$2 -env_dir=$3 - -bp_dir=$(cd $(dirname $0); cd ..; pwd) - -# Load some convenience functions like status() and indent() -source $bp_dir/bin/common.sh - -# Expose user-installed bower -export PATH=$build_dir/node_modules/.bin:$PATH - -# Get gulp version -gulp_bin=$(which gulp) -status "Using Gulp from ${gulp_bin#$build_dir/}" -gulp -v 2>&1 | indent - -# Run subsequent node/gulp commands from the build path -cd $build_dir - -status "Building" -gulp build 2>&1 | indent diff --git a/buildpack/buildpacks/gulp/bin/detect b/buildpack/buildpacks/gulp/bin/detect deleted file mode 100755 index ef4c700b3..000000000 --- a/buildpack/buildpacks/gulp/bin/detect +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -# bin/detect - -if [ -f $1/gulpfile.js ]; then - echo "Gulp" && exit 0 -else - echo "no" && exit 1 -fi diff --git a/buildpack/buildpacks/node/README.md b/buildpack/buildpacks/node/README.md deleted file mode 100644 index 5e2167b7a..000000000 --- a/buildpack/buildpacks/node/README.md +++ /dev/null @@ -1 +0,0 @@ -This buildpack is based on [heroku-buildpack-nodejs](https://github.com/heroku/heroku-buildpack-nodejs). diff --git a/buildpack/buildpacks/node/bin/common.sh b/buildpack/buildpacks/node/bin/common.sh deleted file mode 100644 index 689f66f47..000000000 --- a/buildpack/buildpacks/node/bin/common.sh +++ /dev/null @@ -1,38 +0,0 @@ -error() { - echo " ! $*" >&2 - exit 1 -} - -status() { - echo "-----> $*" -} - -protip() { - echo - echo "PRO TIP: $*" | indent - echo "See https://devcenter.heroku.com/articles/nodejs-support" | indent - echo -} - -# sed -l basically makes sed replace and buffer through stdin to stdout -# so you get updates while the command runs and dont wait for the end -# e.g. npm install | indent -indent() { - c='s/^/ /' - case $(uname) in - Darwin) sed -l "$c";; # mac/bsd sed: -l buffers on line boundaries - *) sed -u "$c";; # unix/gnu sed: -u unbuffered (arbitrary) chunks of data - esac -} - -cat_npm_debug_log() { - test -f $build_dir/npm-debug.log && cat $build_dir/npm-debug.log -} - -cp_keep_links() { - if [ "$(uname)" == "Darwin" ]; then - cp -p "$@" - else - cp --preserve=links "$@" - fi -} diff --git a/buildpack/buildpacks/node/bin/compact b/buildpack/buildpacks/node/bin/compact deleted file mode 100755 index c985ddc8e..000000000 --- a/buildpack/buildpacks/node/bin/compact +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash - -set -e # fail fast -set -o pipefail # don't ignore exit codes when piping output -# set -x # enable debugging - -# Configure directories -build_dir=$1 -cache_dir=$2 -env_dir=$3 - -bp_dir=$(cd $(dirname $0); cd ..; pwd) - -# Load some convenience functions like status() and indent() -source $bp_dir/bin/common.sh - -# Output npm debug info on error -trap cat_npm_debug_log ERR - -# Run subsequent node/npm commands from the build path -cd $build_dir - -# Run twice as we may be able to remove a few more dependencies -# on the second run -status "Pruning development dependencies" -npm prune --production --userconfig $build_dir/.npmrc 2>&1 | indent -npm prune --production --userconfig $build_dir/.npmrc 2>&1 | indent diff --git a/buildpack/buildpacks/node/bin/compile b/buildpack/buildpacks/node/bin/compile deleted file mode 100755 index bf402f89e..000000000 --- a/buildpack/buildpacks/node/bin/compile +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env bash - -set -e # fail fast -set -o pipefail # don't ignore exit codes when piping output -# set -x # enable debugging - -# Configure directories -build_dir=$1 -cache_dir=$2 -env_dir=$3 - -bp_dir=$(cd $(dirname $0); cd ..; pwd) - -# Load some convenience functions like status() and indent() -source $bp_dir/bin/common.sh - -# Output npm debug info on error -trap cat_npm_debug_log ERR - -# Get node version -node_version=$(node --version) -status "Using Node.js $node_version" - -# Run subsequent node/npm commands from the build path -cd $build_dir - -install() { - ( - # Scope config var availability only to `npm install` - if [ -d "$env_dir" ]; then - status "Exporting config vars to environment" - export_env_dir $env_dir - fi - - status "Installing npm dependencies" - # Make npm output to STDOUT instead of its default STDERR - npm install --loglevel=http --userconfig $build_dir/.npmrc "$@" 2>&1 | indent - ) -} - -# If node_modules directory is checked into source control then -# rebuild any native deps. Otherwise, restore from the build cache. -if test -d $build_dir/node_modules; then - status "Found existing node_modules directory; skipping cache" - # Attempt to work around npm/npm#5400 - install --ignore-scripts - status "Rebuilding any native dependencies to work around npm/npm#5400" - npm rebuild 2>&1 | indent -elif test -d $cache_dir/node/node_modules; then - status "Restoring node_modules directory from cache" - cp_keep_links -R $cache_dir/node/node_modules $build_dir/ - - status "Pruning cached dependencies not specified in package.json" - npm prune 2>&1 | indent - - if test -f $cache_dir/node/.heroku/node-version && [ $(cat $cache_dir/node/.heroku/node-version) != "$node_version" ]; then - status "Node version changed since last build; rebuilding dependencies" - npm rebuild 2>&1 | indent - fi - - # Let's hope that npm/npm#5400 only hits us on the first run - install -else - # Attempt to work around npm/npm#5400 - install --ignore-scripts - status "Rebuilding any native dependencies to work around npm/npm#5400" - npm rebuild 2>&1 | indent -fi - -# Persist goodies like node-version in the slug -mkdir -p $build_dir/.heroku - -# Save resolved node version in the slug for later reference -echo $node_version > $build_dir/.heroku/node-version - -# Purge node-related cached content, being careful not to purge the top-level -# cache, for the sake of heroku-buildpack-multi apps. -rm -rf $cache_dir/node -mkdir -p $cache_dir/node - -# If app has a node_modules directory, cache it. -if test -d $build_dir/node_modules; then - status "Caching node_modules directory for future builds" - cp_keep_links -R $build_dir/node_modules $cache_dir/node -fi - -# Copy goodies to the cache -cp -r $build_dir/.heroku $cache_dir/node - -status "Cleaning up node-gyp and npm artifacts" -rm -rf "$build_dir/.node-gyp" -rm -rf "$build_dir/.npm" diff --git a/buildpack/buildpacks/node/bin/detect b/buildpack/buildpacks/node/bin/detect deleted file mode 100755 index e887295de..000000000 --- a/buildpack/buildpacks/node/bin/detect +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -# bin/detect - -if [ -f $1/package.json ]; then - echo "Node.js" && exit 0 -else - echo "no" && exit 1 -fi diff --git a/buildpack/image b/buildpack/image deleted file mode 100644 index 728412c94..000000000 --- a/buildpack/image +++ /dev/null @@ -1 +0,0 @@ -sorccu/node:0.10