forked from heroku/heroku-buildpack-google-chrome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile
executable file
·206 lines (174 loc) · 6.12 KB
/
compile
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/usr/bin/env bash
# bin/compile <build-dir> <cache-dir>
# fail fast
set -e
# debug
# set -x
# parse and derive params
BUILD_DIR=$1
CACHE_DIR=$2
ENV_DIR=$3
LP_DIR=`cd $(dirname $0); cd ..; pwd`
function error() {
echo " ! $*" >&2
exit 1
}
function topic() {
echo "-----> $*"
}
function indent() {
c='s/^/ /'
case $(uname) in
Darwin) sed -l "$c";;
*) sed -u "$c";;
esac
}
# Detect requested channel or default to stable
if [ -f $ENV_DIR/GOOGLE_CHROME_CHANNEL ]; then
channel=$(cat $ENV_DIR/GOOGLE_CHROME_CHANNEL)
else
channel=stable
fi
# Detect requested Chrome version or default to current
if [ -f $ENV_DIR/CHROME_VERSION ]; then
version=$(cat $ENV_DIR/CHROME_VERSION)
else
version=current
fi
# Setup bin and shim locations for desired channel, and detect invalid channels
case "$channel" in
"stable")
BIN=chrome/chrome
SHIM=google-chrome-stable
;;
"beta")
BIN=chrome-beta/chrome
SHIM=google-chrome-beta
;;
"unstable")
BIN=chrome-unstable/chrome
SHIM=google-chrome-unstable
;;
*)
error "GOOGLE_CHROME_CHANNEL must be 'stable', 'beta', or 'unstable', not '$channel'."
;;
esac
# Install correct dependencies according to $STACK
case "${STACK}" in
"heroku-18" | "heroku-20")
# the package list is found by using ci:debug then running ldd $GOOGLE_CHROME_BIN | grep not
# also look here for more packages/notes https://developers.google.com/web/tools/puppeteer/troubleshooting
PACKAGES="
gconf-service
libappindicator1
libasound2
libatk1.0-0
libatk-bridge2.0-0
libcairo-gobject2
libdrm2
libgbm1
libgconf-2-4
libgtk-3-0
libnspr4
libnss3
libx11-xcb1
libxcb-dri3-0
libxcomposite1
libxcursor1
libxdamage1
libxfixes3
libxi6
libxinerama1
libxrandr2
libxshmfence1
libxss1
libxtst6
fonts-liberation
"
;;
*)
error "STACK must be 'heroku-18' or 'heroku-20', not '${STACK}'."
esac
if [ ! -f $CACHE_DIR/PURGED_CACHE_V1 ]; then
topic "Purging cache"
rm -rf $CACHE_DIR/apt
rm -rf $CACHE_DIR/archives
rm -rf $CACHE_DIR/lists
touch $CACHE_DIR/PURGED_CACHE_V1
fi
topic "Installing Google Chrome ($version) from the $channel channel."
if [[ $CHROME_VERSION == "current" ]]; then
PACKAGES="$PACKAGES https://dl.google.com/linux/direct/google-chrome-${channel}_current_amd64.deb"
else
PACKAGES="$PACKAGES https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-${channel}_${version}_amd64.deb"
fi
APT_CACHE_DIR="$CACHE_DIR/apt/cache"
APT_STATE_DIR="$CACHE_DIR/apt/state"
mkdir -p "$APT_CACHE_DIR/archives/partial"
mkdir -p "$APT_STATE_DIR/lists/partial"
APT_OPTIONS="-o debug::nolocking=true -o dir::cache=$APT_CACHE_DIR -o dir::state=$APT_STATE_DIR"
topic "Updating apt caches"
apt-get $APT_OPTIONS update | indent
for PACKAGE in $PACKAGES; do
if [[ $PACKAGE == *deb ]]; then
PACKAGE_NAME=$(basename $PACKAGE .deb)
PACKAGE_FILE=$APT_CACHE_DIR/archives/$PACKAGE_NAME.deb
topic "Fetching $PACKAGE"
curl -s -L -z $PACKAGE_FILE -o $PACKAGE_FILE $PACKAGE 2>&1 | indent
else
topic "Fetching .debs for $PACKAGE"
apt-get $APT_OPTIONS -y --force-yes -d install --reinstall $PACKAGE | indent
fi
done
mkdir -p $BUILD_DIR/.apt
for DEB in $(ls -1 $APT_CACHE_DIR/archives/*.deb); do
if ! [[ $version == "current" ]] && [[ $(basename $DEB) == "google-chrome-stable_current_amd64.deb" ]]; then
topic "Skipping install of Google Chrome current version because only version $version should be installed."
else
topic "Installing $(basename $DEB)"
dpkg -x $DEB $BUILD_DIR/.apt/
fi
done
topic "Writing profile script"
mkdir -p $BUILD_DIR/.profile.d
cat <<EOF >$BUILD_DIR/.profile.d/000_apt.sh
export PATH="\$HOME/.apt/usr/bin:\$PATH"
export LD_LIBRARY_PATH="\$HOME/.apt/usr/lib/x86_64-linux-gnu:\$HOME/.apt/usr/lib/i386-linux-gnu:\$HOME/.apt/usr/lib:\$LD_LIBRARY_PATH"
export LIBRARY_PATH="\$HOME/.apt/usr/lib/x86_64-linux-gnu:\$HOME/.apt/usr/lib/i386-linux-gnu:\$HOME/.apt/usr/lib:\$LIBRARY_PATH"
export INCLUDE_PATH="\$HOME/.apt/usr/include:\$HOME/.apt/usr/include/x86_64-linux-gnu:\$INCLUDE_PATH"
export CPATH="\$INCLUDE_PATH"
export CPPPATH="\$INCLUDE_PATH"
export PKG_CONFIG_PATH="\$HOME/.apt/usr/lib/x86_64-linux-gnu/pkgconfig:\$HOME/.apt/usr/lib/i386-linux-gnu/pkgconfig:\$HOME/.apt/usr/lib/pkgconfig:\$PKG_CONFIG_PATH"
EOF
export PATH="$BUILD_DIR/.apt/usr/bin:$PATH"
export LD_LIBRARY_PATH="$BUILD_DIR/.apt/usr/lib/x86_64-linux-gnu:$BUILD_DIR/.apt/usr/lib/i386-linux-gnu:$BUILD_DIR/.apt/usr/lib:$LD_LIBRARY_PATH"
export LIBRARY_PATH="$BUILD_DIR/.apt/usr/lib/x86_64-linux-gnu:$BUILD_DIR/.apt/usr/lib/i386-linux-gnu:$BUILD_DIR/.apt/usr/lib:$LIBRARY_PATH"
export INCLUDE_PATH="$BUILD_DIR/.apt/usr/include:$BUILD_DIR/.apt/usr/include/x86_64-linux-gnu:$INCLUDE_PATH"
export CPATH="$INCLUDE_PATH"
export CPPPATH="$INCLUDE_PATH"
export PKG_CONFIG_PATH="$BUILD_DIR/.apt/usr/lib/x86_64-linux-gnu/pkgconfig:$BUILD_DIR/.apt/usr/lib/i386-linux-gnu/pkgconfig:$BUILD_DIR/.apt/usr/lib/pkgconfig:$PKG_CONFIG_PATH"
#give environment to later buildpacks
export | grep -E -e ' (PATH|LD_LIBRARY_PATH|LIBRARY_PATH|INCLUDE_PATH|CPATH|CPPPATH|PKG_CONFIG_PATH)=' > "$LP_DIR/export"
topic "Rewrite package-config files"
find $BUILD_DIR/.apt -type f -ipath '*/pkgconfig/*.pc' | xargs --no-run-if-empty -n 1 sed -i -e 's!^prefix=\(.*\)$!prefix='"$BUILD_DIR"'/.apt\1!g'
topic "Creating google-chrome shims"
BIN_DIR=$BUILD_DIR/.apt/usr/bin
rm $BIN_DIR/$SHIM
cat <<EOF >$BIN_DIR/$SHIM
#!/usr/bin/env bash
if [ \$1 = "--version" ]; then
exec \$HOME/.apt/opt/google/$BIN --version
elif [ \$1 = "--product-version" ]; then
exec \$HOME/.apt/opt/google/$BIN --product-version
else
exec \$HOME/.apt/opt/google/$BIN --headless --no-sandbox --disable-gpu --remote-debugging-port=9222 \$@
fi
EOF
chmod +x $BIN_DIR/$SHIM
cp $BIN_DIR/$SHIM $BIN_DIR/google-chrome
# export the chrome binary location, so it's easier to tell chromedriver
# about the non-standard location
cat <<EOF >$BUILD_DIR/.profile.d/010_google-chrome.sh
export GOOGLE_CHROME_BIN="\$HOME/.apt/opt/google/$BIN"
export GOOGLE_CHROME_SHIM="\$HOME/.apt/usr/bin/$SHIM"
EOF