Skip to content

Commit 9438e81

Browse files
committed
Fix error with command substitution
1 parent 0bf5a60 commit 9438e81

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

README.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,30 @@ Order matters for this buildpack to work. Here's the run order that you should s
2525

2626

2727
## Customize the following config variables:
28-
1. `PLAYWRIGHT_BUILDPACK_BROWSERS` accepts a comma-separated list of the browser names `chromium,firefox,webkit`. By default, it's installing the executables for all these browsers.
28+
1. `PLAYWRIGHT_BUILDPACK_BROWSERS` accepts a comma-separated list of the browser names. By default, it's installing executables for `chromium,firefox,webkit`.
2929
- E.g. To only install Chromium dependencies, set the variable to `chromium`. This will reduce the slug size in the end too.
3030
- **NOTE**: this is what the author uses, usage with the other 2 browsers are unknown. Feel free to test them out and let me know if they work and I'll update the docs.
3131
- This config variable is intended to be shared with [heroku-playwright-buildpack](https://github.com/playwright-community/heroku-playwright-buildpack).
3232
2. `BUILDPACK_BROWSERS_INSTALL_PATH` is the path where the browsers will be installed. Its default value is `browsers` and it's a relative path starting from the [`BUILD_DIR`](https://devcenter.heroku.com/articles/buildpack-api#bin-compile) (the starting directory of the compiled slug to be used by Heroku). It's necessary to have the installed browsers within the `BUILD_DIR` to have the file included by the time Heroku starts the dyno.
3333
- E.g. To install in the directory `utils/browsers`, set the variable to `utils/browsers`.
34-
- This config variable is exported by the buildpack for your use in the next step
3534

36-
## Modify your browser init script
35+
## Modify your browser creation script
3736

38-
Since the browsers are installed in a non-default location, we have to specify the executable path when we create the browser instances.
37+
Since the browsers are installed in a non-default location, we have to specify the executable path when we create the browser instances. The following config variables are exported by the buildpack IF the appropriate browsers are installed:
38+
- `CHROMIUM_EXECUTABLE_PATH`
39+
- `FIREFOX_EXECUTABLE_PATH`
40+
- `WEBKIT_EXECUTABLE_PATH`
3941

40-
Here's how you should create your browser:
42+
For example, if you use `PLAYWRIGHT_BUILDPACK_BROWSERS=chromium`, the script will only install the executable for Chromium and only `CHROMIUM_EXECUTABLE_PATH` will be set.
43+
44+
Here's how you should create your browser using the config variable above:
4145

4246
```
4347
with sync_playwright() as p:
4448
try:
45-
browser = p.chromium.launch(executable_path=env("CHROME_EXECUTABLE_PATH"), ...other arguments)
4649
# for chromium, you don't have to pass in flags like `no-sandbox` or `headless` because they are enabled by default.
4750
# Flags like `--disable-dev-shm-usage` and `--remote-debugging-port=9222` can be added if needed but I haven't needed that
51+
browser = p.chromium.launch(executable_path=os.getenv("CHROMIUM_EXECUTABLE_PATH"), ...other arguments)
4852
```
4953

5054

@@ -59,8 +63,13 @@ The command to install the system packages along with the browser is `playwright
5963
Here are a few things to consider:
6064
- This buildpack is meant for Python Playwright and was developed with Chromium in mind. Any other browser/Playwright distro is not tested by me so I offer no guarantees there
6165
- Verify that the installation is successful. Look at the build logs, you should see progress bar for the executable installations
66+
- Verify that the executable paths are properly set. Look through the logs for something like this
67+
```
68+
```
6269
- You can also `heroku run bash` into the dyno and search for the installation folder to verify that the exe are downloaded.
6370

64-
# Notes
65-
This was developed for usage with `playwright` for Python
71+
# Credits
72+
A lot of code and patterns were borrowed from [heroku-playwright-buildpack](https://github.com/playwright-community/heroku-playwright-buildpack).
73+
74+
Idea for the buildpack were borrowed from [playwright-python-heroku-buildpack](https://github.com/binoche9/playwright-python-heroku-buildpack).
6675

bin/compile

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,28 @@ echo "-----> BUILDPACK_BROWSERS_INSTALL_PATH is $BUILDPACK_BROWSERS_INSTALL_PATH
3131
echo "-----> Browsers will be installed in $PLAYWRIGHT_BROWSERS_PATH"
3232
echo "-----> Installing Playwright executables (env: PLAYWRIGHT_BUILDPACK_BROWSERS) for ${PLAYWRIGHT_BUILDPACK_BROWSERS} (formatted value for command line is '${PLAYWRIGHT_BUILDPACK_BROWSERS//,/ }')."
3333
playwright install ${PLAYWRIGHT_BUILDPACK_BROWSERS//,/ }
34+
# chmod -R +x $PLAYWRIGHT_BROWSERS_PATH
3435
echo "-----> Installation done"
3536

3637
# export the file path as a ENV
3738
# this is meant to be copied over to the $BUILD_DIR under .profile.d/heroku-playwright-python-browsers-defaults.sh and then run
3839

39-
PROFILE_D_FILE=$BUILD_DIR/.profile.d/heroku-playwright-python-browsers-defaults.sh
40-
41-
cat <<EOF >> $PROFILE_D_FILE
42-
CHROMIUM_EXECUTABLE_PATH=\$(find ~+ -type f -name "chrome":-NULL)
40+
cat <<EOF > $BUILD_DIR/.profile.d/heroku-playwright-python-browsers-defaults.sh
41+
CHROMIUM_EXECUTABLE_PATH=\$(find ~+ -type f -name "chrome")
4342
echo "----> CHROMIUM_EXECUTABLE_PATH is \$CHROMIUM_EXECUTABLE_PATH"
44-
if [ "\$CHROMIUM_EXECUTABLE_PATH" != "NULL" ]; then
43+
if [ "\$CHROMIUM_EXECUTABLE_PATH" != "" ]; then
4544
export CHROMIUM_EXECUTABLE_PATH=\$CHROMIUM_EXECUTABLE_PATH
4645
fi
4746
48-
FIREFOX_EXECUTABLE_PATH=\$(find ~+ -type f -name "firefox":-NULL)
47+
FIREFOX_EXECUTABLE_PATH=\$(find ~+ -type f -name "firefox")
4948
echo "----> FIREFOX_EXECUTABLE_PATH is \$FIREFOX_EXECUTABLE_PATH"
50-
if [ "\$FIREFOX_EXECUTABLE_PATH" != "NULL" ]; then
49+
if [ "\$FIREFOX_EXECUTABLE_PATH" != "" ]; then
5150
export FIREFOX_EXECUTABLE_PATH=\$FIREFOX_EXECUTABLE_PATH
5251
fi
5352
54-
WEBKIT_EXECUTABLE_PATH=\$(find ~+ -type f -name "pw_run.sh":-NULL) # see https://github.com/microsoft/playwright/issues/2923
53+
WEBKIT_EXECUTABLE_PATH=\$(find ~+ -type f -name "pw_run.sh") # see https://github.com/microsoft/playwright/issues/2923
5554
echo "----> WEBKIT_EXECUTABLE_PATH is \$WEBKIT_EXECUTABLE_PATH"
56-
if [ "\$WEBKIT_EXECUTABLE_PATH" != "NULL" ]; then
55+
if [ "\$WEBKIT_EXECUTABLE_PATH" != "" ]; then
5756
export WEBKIT_EXECUTABLE_PATH=\$WEBKIT_EXECUTABLE_PATH
5857
fi
5958
EOF

0 commit comments

Comments
 (0)