Skip to content

Commit 0e8db30

Browse files
committed
Import from Chromedriver branch/PR heroku/heroku-buildpack-chromedriver#62
1 parent 6faf935 commit 0e8db30

File tree

6 files changed

+254
-35
lines changed

6 files changed

+254
-35
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: build-and-test
2+
3+
on: push
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v3
11+
12+
- name: Run Buildpack Compile
13+
run: ./bin/compile . . .
14+
env:
15+
STACK: heroku-22
16+
17+
- name: Check Installation
18+
run: |
19+
.chrome-for-testing/bin/chrome --version
20+
.chrome-for-testing/bin/chromedriver --version

.gitignore

Lines changed: 0 additions & 34 deletions
This file was deleted.

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,21 @@
1-
# heroku-buildpack-chrome-for-testing
1+
# Heroku Buildpack, Chrome for Testing
2+
3+
This buildpack installs **Google Chrome browser** `chrome` & [`chromedriver`](https://chromedriver.chromium.org/), the Selenium driver for Chrome, in a Heroku app.
4+
5+
## Background
6+
7+
In summer 2023, the Chrome development team [addressed a long-standing problem with keeping Chrome & Chromedriver versions updated and aligned](https://developer.chrome.com/blog/chrome-for-testing/) with each other for automated testing environments. This buildpack follows this strategy to keep `chrome` & `chromedriver` versions in-sync.
8+
9+
## Selecting the Chrome Release Channel
10+
11+
By default, this buildpack will download the latest `Stable` release, which is provided
12+
by [Google](https://googlechromelabs.github.io/chrome-for-testing/).
13+
14+
You can control the channel of the release by setting the `GOOGLE_CHROME_CHANNEL`
15+
config variable to `Stable`, `Beta`, `Dev`, or `Canary`, and then deploy/build the app.
16+
17+
## Releasing a new version
18+
19+
Make sure you publish this buildpack in the buildpack registry
20+
21+
`heroku buildpacks:publish heroku/chrome-for-testing main`

bin/compile

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env bash
2+
# bin/compile <build-dir> <cache-dir> <env-dir>
3+
4+
# fail fast
5+
set -e
6+
set -o pipefail
7+
8+
# debug
9+
# set -x
10+
11+
# parse and derive params
12+
BUILD_DIR=$1
13+
CACHE_DIR=$2
14+
ENV_DIR=$3
15+
BUILDPACK_DIR="$(cd "$(dirname "$0")"; cd ..; pwd)"
16+
17+
function error() {
18+
echo " ! $*" >&2
19+
exit 1
20+
}
21+
22+
function topic() {
23+
echo "-----> $*"
24+
}
25+
26+
function indent() {
27+
c='s/^/ /'
28+
case $(uname) in
29+
Darwin) sed -l "$c";;
30+
*) sed -u "$c";;
31+
esac
32+
}
33+
34+
topic "Installing Chrome for Testing"
35+
36+
INSTALL_DIR="$BUILD_DIR/.chrome-for-testing"
37+
BIN_DIR="$INSTALL_DIR/bin"
38+
mkdir -p "$BIN_DIR"
39+
40+
# Detect if the old config var is still used
41+
if [ -f "$ENV_DIR/CHROMEDRIVER_VERSION" ]; then
42+
error "This buildpack no longer supports CHROMEDRIVER_VERSION config var and must be removed to continue, because this buildpack now installs compatible versions of Chrome & Chromedriver. GOOGLE_CHROME_CHANNEL can be used to set Stable (default), Beta, Dev, or Canary."
43+
fi
44+
45+
# Detect if Chrome is already installed
46+
if which chrome; then
47+
error "Chrome is already installed. This buildpack now installs a compatible version of Chrome. Please, remove the other Chrome installation. Chrome may have been installed by another buildpack (such as heroku/heroku-buildpack-google-chrome buildpack), which should no longer be used with this buildpack."
48+
fi
49+
50+
# Detect requested channel or default to stable
51+
if [ -f "$ENV_DIR/GOOGLE_CHROME_CHANNEL" ]; then
52+
channel=$(cat "$ENV_DIR/GOOGLE_CHROME_CHANNEL")
53+
echo "Using env var GOOGLE_CHROME_CHANNEL=$channel" | indent
54+
else
55+
channel=stable
56+
fi
57+
# The current version endpoint requires ALL CAPS.
58+
CHANNEL="$(echo -n "$channel" | awk '{ print toupper($0) }')"
59+
VERSION="$(curl --silent --show-error --fail --retry 3 --retry-connrefused --connect-timeout 10 "https://googlechromelabs.github.io/chrome-for-testing/LATEST_RELEASE_$CHANNEL")"
60+
echo "Resolved $CHANNEL version $VERSION" | indent
61+
62+
echo "Downloading Chrome" | indent
63+
ZIP_URL="https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/$VERSION/linux64/chrome-linux64.zip"
64+
ZIP_LOCATION="$INSTALL_DIR/chrome.zip"
65+
curl --silent --show-error --fail --retry 3 --retry-connrefused --connect-timeout 10 -o "${ZIP_LOCATION}" "${ZIP_URL}" | indent
66+
unzip -q -j -o "$ZIP_LOCATION" -d "$BIN_DIR" | indent
67+
rm -f "$ZIP_LOCATION"
68+
69+
echo "Downloading Chromedriver" | indent
70+
ZIP_URL="https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/$VERSION/linux64/chromedriver-linux64.zip"
71+
ZIP_LOCATION="$INSTALL_DIR/chromedriver.zip"
72+
curl --silent --show-error --fail --retry 3 --retry-connrefused --connect-timeout 10 -o "${ZIP_LOCATION}" "${ZIP_URL}" | indent
73+
unzip -q -j -o "$ZIP_LOCATION" -d "$BIN_DIR" | indent
74+
rm -f "$ZIP_LOCATION"
75+
76+
source "$BUILDPACK_DIR/bin/install-chrome-dependencies"
77+
78+
echo "Adding executables to PATH" | indent
79+
mkdir -p "$BUILD_DIR/.profile.d"
80+
echo "export PATH=\$HOME/.chrome-for-testing/bin:\$PATH" >> "$BUILD_DIR/.profile.d/chrome-for-testing.sh"
81+
82+
# Verify the executables are actually present
83+
export PATH="$BUILD_DIR/.chrome-for-testing/bin:$PATH"
84+
which chrome | indent
85+
which chromedriver | indent
86+
87+
echo "Installed Chrome for Testing $CHANNEL version $VERSION" | indent

bin/detect

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
# bin/detect <build-dir>
3+
4+
echo "Chrome for Testing"
5+
exit 0

bin/install-chrome-dependencies

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/usr/bin/env bash
2+
# Invoke with `source "$BUILDPACK_DIR/bin/install-chrome-dependencies"` from inside `bin/compile`.
3+
# This script is mostly copied from:
4+
# https://github.com/heroku/heroku-buildpack-google-chrome/blob/master/bin/compile
5+
6+
# Uses variables & methods from compile script:
7+
# BUILD_DIR
8+
# CACHE_DIR
9+
# ENV_DIR
10+
# BUILDPACK_DIR
11+
# topic()
12+
# indent()
13+
14+
topic "Installing Chrome dependencies"
15+
16+
# Install correct dependencies according to $STACK
17+
case "${STACK}" in
18+
"heroku-18" | "heroku-20" | "heroku-22")
19+
# the package list is found by using ci:debug then running ldd $GOOGLE_CHROME_BIN | grep not
20+
# also look here for more packages/notes https://developers.google.com/web/tools/puppeteer/troubleshooting
21+
PACKAGES="
22+
gconf-service
23+
libappindicator1
24+
libasound2
25+
libatk1.0-0
26+
libatk-bridge2.0-0
27+
libcairo-gobject2
28+
libdrm2
29+
libgbm1
30+
libgconf-2-4
31+
libgtk-3-0
32+
libnspr4
33+
libnss3
34+
libx11-xcb1
35+
libxcb-dri3-0
36+
libxcomposite1
37+
libxcursor1
38+
libxdamage1
39+
libxfixes3
40+
libxi6
41+
libxinerama1
42+
libxrandr2
43+
libxshmfence1
44+
libxss1
45+
libxtst6
46+
fonts-liberation
47+
"
48+
;;
49+
*)
50+
error "STACK must be 'heroku-18', 'heroku-20' or 'heroku-22', not '${STACK}'."
51+
esac
52+
53+
if [ ! -f $CACHE_DIR/PURGED_CACHE_V1 ]; then
54+
echo "Purging cache" | indent
55+
rm -rf $CACHE_DIR/apt
56+
rm -rf $CACHE_DIR/archives
57+
rm -rf $CACHE_DIR/lists
58+
touch $CACHE_DIR/PURGED_CACHE_V1
59+
fi
60+
61+
# This is where the original buildpack installed Chrome itself,
62+
# but Chrome for Testing is installed from direct downloads.
63+
#
64+
# echo "Installing Google Chrome from the $channel channel." | indent
65+
# PACKAGES="$PACKAGES https://dl.google.com/linux/direct/google-chrome-${channel}_current_amd64.deb"
66+
67+
APT_CACHE_DIR="$CACHE_DIR/apt/cache"
68+
APT_STATE_DIR="$CACHE_DIR/apt/state"
69+
70+
mkdir -p "$APT_CACHE_DIR/archives/partial"
71+
mkdir -p "$APT_STATE_DIR/lists/partial"
72+
73+
APT_OPTIONS="-o debug::nolocking=true -o dir::cache=$APT_CACHE_DIR -o dir::state=$APT_STATE_DIR"
74+
75+
echo "Updating apt caches" | indent
76+
apt-get $APT_OPTIONS update | indent
77+
78+
for PACKAGE in $PACKAGES; do
79+
if [[ $PACKAGE == *deb ]]; then
80+
PACKAGE_NAME=$(basename $PACKAGE .deb)
81+
PACKAGE_FILE=$APT_CACHE_DIR/archives/$PACKAGE_NAME.deb
82+
83+
echo "Fetching $PACKAGE" | indent
84+
curl -s -L -z $PACKAGE_FILE -o $PACKAGE_FILE $PACKAGE 2>&1 | indent
85+
else
86+
echo "Fetching .debs for $PACKAGE" | indent
87+
apt-get $APT_OPTIONS -y --force-yes -d install --reinstall $PACKAGE | indent
88+
fi
89+
done
90+
91+
mkdir -p $BUILD_DIR/.apt
92+
93+
for DEB in $(ls -1 $APT_CACHE_DIR/archives/*.deb); do
94+
echo "Installing $(basename $DEB)" | indent
95+
dpkg -x $DEB $BUILD_DIR/.apt/
96+
done
97+
98+
echo "Writing profile script" | indent
99+
mkdir -p $BUILD_DIR/.profile.d
100+
cat <<EOF >$BUILD_DIR/.profile.d/000_apt.sh
101+
export PATH="\$HOME/.apt/usr/bin:\$PATH"
102+
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"
103+
export LIBRARY_PATH="\$HOME/.apt/usr/lib/x86_64-linux-gnu:\$HOME/.apt/usr/lib/i386-linux-gnu:\$HOME/.apt/usr/lib:\$LIBRARY_PATH"
104+
export INCLUDE_PATH="\$HOME/.apt/usr/include:\$HOME/.apt/usr/include/x86_64-linux-gnu:\$INCLUDE_PATH"
105+
export CPATH="\$INCLUDE_PATH"
106+
export CPPPATH="\$INCLUDE_PATH"
107+
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"
108+
EOF
109+
110+
export PATH="$BUILD_DIR/.apt/usr/bin:$PATH"
111+
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"
112+
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"
113+
export INCLUDE_PATH="$BUILD_DIR/.apt/usr/include:$BUILD_DIR/.apt/usr/include/x86_64-linux-gnu:$INCLUDE_PATH"
114+
export CPATH="$INCLUDE_PATH"
115+
export CPPPATH="$INCLUDE_PATH"
116+
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"
117+
118+
#give environment to later buildpacks
119+
export | grep -E -e ' (PATH|LD_LIBRARY_PATH|LIBRARY_PATH|INCLUDE_PATH|CPATH|CPPPATH|PKG_CONFIG_PATH)=' > "$BUILDPACK_DIR/export"
120+
121+
echo "Installed Chrome dependencies for $STACK" | indent

0 commit comments

Comments
 (0)