Skip to content

Commit 9e7d749

Browse files
committed
Finalize code and doc
1 parent 9438e81 commit 9e7d749

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

README.md

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,39 @@ Follow the steps below.
1111

1212
This buildpack relies on the CLI command `playwright install`. This requires [`playwright`](https://pypi.org/project/playwright/) to be installed. Do this by specifying a `requirements.txt` or any other methods accepted by the Heroku Python buildpacks.
1313

14+
Example `requirements.txt`:
15+
```
16+
environs==10.3.0
17+
exceptiongroup==1.2.0
18+
greenlet==3.0.1
19+
gunicorn==21.2.0
20+
idna==3.6
21+
iniconfig==2.0.0
22+
marshmallow==3.20.2
23+
packaging==23.2
24+
playwright==1.40.0
25+
pluggy==1.3.0
26+
```
27+
1428
## Buildpack ordering
1529

1630
Order matters for this buildpack to work. Here's the run order that you should should have:
1731

1832
![Buildpack Image](Buildpacks.PNG)
1933

2034
1. The official [Python buildpack](https://elements.heroku.com/buildpacks/heroku/heroku-buildpack-python).
21-
- Runs first so that Playwright is available as a CLI tool after the package installation is done
22-
1. This build pack. [Here's how to add this buildpack to your app](https://devcenter.heroku.com/articles/buildpacks#using-a-third-party-buildpack) by using its Git URL.
23-
2. The [heroku-playwright-buildpack](https://github.com/playwright-community/heroku-playwright-buildpack)
24-
- **Why?** This buildpack CANNOT install system requirements (i.e. `playwright install --with-deps`) due to restrictions from Heroku. It's only able to install the browser executables. Thus, we rely on [heroku-playwright-buildpack](https://github.com/playwright-community/heroku-playwright-buildpack) to get the needed system packages.
35+
- Runs first so that Playwright is available as a CLI tool after the package installation is done
36+
2. This build pack. [Here's how to add this buildpack to your app](https://devcenter.heroku.com/articles/buildpacks#using-a-third-party-buildpack) by using its Git URL.
37+
3. The [heroku-playwright-buildpack](https://github.com/playwright-community/heroku-playwright-buildpack)
2538

2639

2740
## Customize the following config variables:
2841
1. `PLAYWRIGHT_BUILDPACK_BROWSERS` accepts a comma-separated list of the browser names. By default, it's installing executables for `chromium,firefox,webkit`.
29-
- E.g. To only install Chromium dependencies, set the variable to `chromium`. This will reduce the slug size in the end too.
30-
- **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.
31-
- This config variable is intended to be shared with [heroku-playwright-buildpack](https://github.com/playwright-community/heroku-playwright-buildpack).
42+
- E.g. To only install Chromium dependencies, set the variable to `chromium`. This will reduce the slug size in the end too.
43+
- **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.
44+
- This config variable is intended to be shared with another variable with the same name from [heroku-playwright-buildpack](https://github.com/playwright-community/heroku-playwright-buildpack).
3245
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.
33-
- E.g. To install in the directory `utils/browsers`, set the variable to `utils/browsers`.
46+
- E.g. To install in the directory `utils/browsers`, set the variable to `utils/browsers`.
3447

3548
## Modify your browser creation script
3649

@@ -63,13 +76,18 @@ The command to install the system packages along with the browser is `playwright
6376
Here are a few things to consider:
6477
- 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
6578
- 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-
```
69-
- You can also `heroku run bash` into the dyno and search for the installation folder to verify that the exe are downloaded.
79+
- Verify that the executable paths are properly set. Look through the logs (the app's log, not the buildpack) for something like this
80+
```
81+
2024-02-07T21:57:03.415283+00:00 app[release.8706]: ----> CHROMIUM_EXECUTABLE_PATH is /app/browsers/chromium-1091/chrome-linux/chrome
82+
2024-02-07T21:57:03.555317+00:00 app[release.8706]: ----> FIREFOX_EXECUTABLE_PATH is /app/browsers/firefox-1429/firefox/firefox
83+
2024-02-07T21:57:03.690086+00:00 app[release.8706]: ----> WEBKIT_EXECUTABLE_PATH is /app/browsers/webkit-1944/pw_run.sh
84+
```
85+
- You can also `heroku run bash` into the dyno and search for the installation folder to:
86+
- Verify that the exe are downloaded by going into `BUILDPACK_BROWSERS_INSTALL_PATH`
87+
- Verify that the env variables like `CHROMIUM_EXECUTABLE_PATH` are set properly
7088
7189
# Credits
72-
A lot of code and patterns were borrowed from [heroku-playwright-buildpack](https://github.com/playwright-community/heroku-playwright-buildpack).
90+
A lot of code and patterns were taken from [heroku-playwright-buildpack](https://github.com/playwright-community/heroku-playwright-buildpack).
7391
74-
Idea for the buildpack were borrowed from [playwright-python-heroku-buildpack](https://github.com/binoche9/playwright-python-heroku-buildpack).
92+
Idea for the buildpack was inspired by [playwright-python-heroku-buildpack](https://github.com/binoche9/playwright-python-heroku-buildpack).
7593

bin/compile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ set -e
66
BUILD_DIR=$1
77
ENV_DIR=$3
88

9+
# taken (and modified a bit) from https://devcenter.heroku.com/articles/buildpack-api#bin-compile
910
export_env_dir() {
1011
acceptlist_regex='(BUILDPACK_BROWSERS_INSTALL_PATH|PLAYWRIGHT_BUILDPACK_BROWSERS)'
1112
denylist_regex='^(PATH|GIT_DIR|CPATH|CPPATH|LD_PRELOAD|LIBRARY_PATH)$'
@@ -23,15 +24,13 @@ export_env_dir
2324
# modify the installation location
2425
BUILDPACK_BROWSERS_INSTALL_PATH=${BUILDPACK_BROWSERS_INSTALL_PATH:-"/browsers"}
2526

26-
# follow format of https://github.com/playwright-community/heroku-playwright-buildpack/blob/master/bin/compile
2727
PLAYWRIGHT_BUILDPACK_BROWSERS=${PLAYWRIGHT_BUILDPACK_BROWSERS:-chromium,firefox,webkit}
2828

2929
export PLAYWRIGHT_BROWSERS_PATH=$BUILD_DIR/$BUILDPACK_BROWSERS_INSTALL_PATH
3030
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
3534
echo "-----> Installation done"
3635

3736
# export the file path as a ENV

0 commit comments

Comments
 (0)