forked from syahrul-aiman/nodejs-java-buildpack
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcompile
More file actions
executable file
·174 lines (140 loc) · 4.91 KB
/
compile
File metadata and controls
executable file
·174 lines (140 loc) · 4.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/env bash
# bin/compile <build-dir> <cache-dir> <env-dir>
set -e
set -o pipefail # don't ignore exit codes when piping output
set -o nounset # fail on unset variables
unset GIT_DIR # Avoid GIT_DIR leak from previous build steps
### Constants
DEFAULT_CACHE="node_modules bower_components"
### Configure directories
BUILD_DIR=${1:-}
CACHE_DIR=${2:-}
ENV_DIR=${3:-}
BP_DIR=$(cd $(dirname ${0:-}); cd ..; pwd)
$BP_DIR/compile-extensions/bin/check_stack_support
mkdir -p "$BUILD_DIR/.heroku/node/"
cd $BUILD_DIR
export PATH="$BUILD_DIR/.heroku/node/bin":$PATH
mkdir -p "$BUILD_DIR/.heroku/cf/"
# CF Common
export BUILDPACK_PATH=$BP_DIR
source $BP_DIR/compile-extensions/lib/common
# END CF Common
LOG_FILE='/tmp/node-build-log.txt'
echo "" > "$LOG_FILE"
### Load dependencies
source $BP_DIR/lib/output.sh
source $BP_DIR/lib/json.sh
source $BP_DIR/lib/failure.sh
source $BP_DIR/lib/environment.sh
source $BP_DIR/lib/binaries.sh
source $BP_DIR/lib/binaries_java.sh
source $BP_DIR/lib/binaries_maven.sh
source $BP_DIR/lib/binaries_swift.sh
source $BP_DIR/lib/binaries_cfcli.sh
source $BP_DIR/lib/cache.sh
source $BP_DIR/lib/dependencies.sh
### Handle errors
handle_failure() {
header "Build failed"
warn_untracked_dependencies "$LOG_FILE"
warn_angular_resolution "$LOG_FILE"
failure_message | output "$LOG_FILE"
}
trap 'handle_failure' ERR
### Check initial state
[ -e "$BUILD_DIR/node_modules" ] && PREBUILD=true || PREBUILD=false
### Failures that should be caught immediately
fail_invalid_package_json "$BUILD_DIR"
warn_prebuilt_modules "$BUILD_DIR"
warn_missing_package_json "$BUILD_DIR"
### Compile
create_env() {
write_profile "$BP_DIR" "$BUILD_DIR"
export_env_dir "$ENV_DIR"
create_default_env
}
header "Creating runtime environment"
create_env # can't pipe the whole thing because piping causes subshells, preventing exports
list_node_config | output "$LOG_FILE"
install_bins() {
local node_engine=$(read_json "$BUILD_DIR/package.json" ".engines.node")
local iojs_engine=$(read_json "$BUILD_DIR/package.json" ".engines.iojs")
local npm_engine=$(read_json "$BUILD_DIR/package.json" ".engines.npm")
local java_engine=$(read_json "$BUILD_DIR/package.json" ".engines.java")
local maven_engine=$(read_json "$BUILD_DIR/package.json" ".engines.maven")
local swift_engine=$(read_json "$BUILD_DIR/package.json" ".engines.swift")
if [ -n "$iojs_engine" ]; then
echo "engines.iojs (package.json): $iojs_engine (iojs)"
else
echo "engines.node (package.json): ${node_engine:-unspecified}"
fi
echo "engines.npm (package.json): ${npm_engine:-unspecified (use default)}"
echo ""
if [ -n "$iojs_engine" ]; then
warn_node_engine "$iojs_engine"
install_iojs "$iojs_engine" "$BUILD_DIR/.heroku/node"
echo "Using bundled npm version for iojs compatibility: `npm --version`"
else
warn_node_engine "$node_engine"
install_nodejs "$node_engine" "$BUILD_DIR/.heroku/node"
install_npm "$npm_engine" "$BUILD_DIR/.heroku/node"
fi
warn_old_npm
install_java "$java_engine" "$BUILD_DIR/.heroku/java"
install_maven "$maven_engine" "$BUILD_DIR/.heroku/maven"
# install_swift "$swift_engine" "$BUILD_DIR/.heroku/swift"
install_cfcli "$BUILD_DIR/.heroku/cf"
}
header "Installing binaries"
install_bins | output "$LOG_FILE"
restore_cache() {
local cache_status="$(get_cache_status)"
if [ "$cache_status" == "valid" ]; then
local cache_directories=$(get_cache_directories)
if [ "$cache_directories" == "" ]; then
echo "Loading 2 from cacheDirectories (default):"
restore_cache_directories "$BUILD_DIR" "$CACHE_DIR" "$DEFAULT_CACHE"
else
echo "Loading $(echo $cache_directories | wc -w | xargs) from cacheDirectories (package.json):"
restore_cache_directories "$BUILD_DIR" "$CACHE_DIR" $cache_directories
fi
else
echo "Skipping cache restore ($cache_status)"
fi
}
header "Restoring cache"
restore_cache | output "$LOG_FILE"
build_dependencies() {
if $PREBUILD; then
echo "Prebuild detected (node_modules already exists)"
rebuild_node_modules "$BUILD_DIR"
else
install_node_modules "$BUILD_DIR"
fi
}
header "Building dependencies"
build_dependencies | output "$LOG_FILE"
cache_build() {
local cache_directories=$(get_cache_directories)
echo "Clearing previous node cache"
clear_cache
if ! ${NODE_MODULES_CACHE:-true}; then
echo "Skipping cache save (disabled by config)"
elif [ "$cache_directories" == "" ]; then
echo "Saving 2 cacheDirectories (default):"
save_cache_directories "$BUILD_DIR" "$CACHE_DIR" "$DEFAULT_CACHE"
else
echo "Saving $(echo $cache_directories | wc -w | xargs) cacheDirectories (package.json):"
save_cache_directories "$BUILD_DIR" "$CACHE_DIR" $cache_directories
fi
save_signature
}
header "Caching build"
cache_build | output "$LOG_FILE"
summarize_build() {
cd $BUILD_DIR
(npm ls --depth=0 | tail -n +2 || true) 2>/dev/null
}
header "Build succeeded!"
summarize_build | output "$LOG_FILE"