Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CHROME_VERSION envvar for later buildpacks #95

Conversation

fkztw
Copy link

@fkztw fkztw commented Sep 10, 2020

Reason why I send this PR

Send this PR because lots of https://github.com/heroku/heroku-buildpack-chromedriver users (including me) encountered the chromedirver and Chrome version mismatch problem (This version of ChromeDriver only supports Chrome version XX) so often and some of these users even create issues in here:

Although heroku-buildpack-chromedriver has a feature which you can set the CHROMEDIRVER_VERSION config var in Heroku dashboard to make it install the specific version of chromedriver.
But, It's annoying that if I push my code to Heroku once a while. It will download the new version Chrome and new version chromedriver then this problem shows again. (Same for new users.)
I have to login to the console, check the version of Chrome, modify the CHROMEDIRVER_VERSION config var and make Heroku rebuild my app again to solve this problem.

So, I came out with a idea:

"What if heroku-buildpack-chromedriver can install the same version of chromedriver for the Chrome installed by heroku-buildpack-google-chrome automatically?"

At first, I was trying to solve this problem in heroku-buildpack-chromedriver without sending PR to this upstream repo.
But, after spent some time on digging out the code, realizing how it works and testing on my own Heroku app.
I found out I cannot get the version of Chrome installed by heroku-buildpack-google-chrome.
Although it did export PATH="$BUILD_DIR/.apt/usr/bin:$PATH" for later buildpacks in

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"

I thought I could easily use google-chrome --version to get it in the heroku-buildpack-chromedriver building process, so I don't need to send a PR to this repo. Since there's a alias
$BUILD_DIR/.apt/usr/bin/google-chrome been created at
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

But, I was wrong. The problem is that alias points to the $HOME. During the building process, all things are still in the $BUILD_DIR, not copied to $HOME yet. So, I got the error message while testing my patch:

/tmp/build_04cb8278/.apt/usr/bin/google-chrome: line 3: /app/.apt/opt/google/chrome/chrome: No such file or directory

I am not sure if late buildpack use the same $BUILD_DIR as the previous buildpack, But even if so, I had to call $BUILD_DIR/.apt/opt/google/$BIN --product-version to get the version of Chrome. The problem is $BIN is decided by the $channel in this repo:

# 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

I don't think it's a good idea to find all the possible executables in a downstream repo. So, that's the reason why I am here to send this PR.


Detail

So, I have to get the CRHOME_VERSION from $BUILD_DIR/.apt/opt/google/$BIN --product-version which is the absolute path of the downloaded Chrome.
Export it for the later buildpacks, which is heroku-buildpack-chromedriver here. So, it will know what version of chromedriver to download. (Of course, Need to modify the code of heroku-buildpack-chromedirver.)


Review

After using my patches of these two repos to build my Heroku App:

It works like a charm on Heroku-18.
Here's a part of the build log:
20200910_16:12:19

The version of Chrome installed by heroku-buildpack-google-chrome And the version of chromedirver installed by patched heroku-buildpack-chromedriver (app name erased for safety reason):
20200910_16:15:05


Further

If this PR could be merged, I think it can also solve another PR: #78

Hope this PR could be merged.
Any further discussions are welcome.
Thank you and appreciate your time for reading this long PR description.

@CrazybutSolid
Copy link

+1.

Chrome 85 broke my app. Need to find a way to stick with Chrome 84!

@fkztw
Copy link
Author

fkztw commented Sep 10, 2020

@CrazybutSolid This PR cannot make you stick with Chrome 84. It will still download the latest version of Chrome from https://dl.google.com/linux/direct/google-chrome-${channel}_current_amd64.deb

@kandluis
Copy link

+1

@CrazybutSolid
Copy link

@CrazybutSolid This PR cannot make you stick with Chrome 84. It will still download the latest version of Chrome from https://dl.google.com/linux/direct/google-chrome-${channel}_current_amd64.deb

What can I do make it stick to Chrome 84. I still haven't been able to stabilize it

@arsandov
Copy link

arsandov commented Sep 6, 2021

I think this is useful! Our build just got broke due the new Chrome 93.

@xyNNN
Copy link

xyNNN commented Oct 5, 2021

What's the state of this pull request?

@edmorley
Copy link
Member

Hi! Sorry for the delayed reply. This buildpack has been deprecated in favour of the newer (and hopefully more robust) Chrome for Testing buildpack:
https://blog.heroku.com/improved-browser-testing-on-heroku-with-chrome
https://github.com/heroku/heroku-buildpack-chrome-for-testing

As such, I'm closing this out.

@edmorley edmorley closed this May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants