-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* try with Dockerfile * add heroku 24 * separate packages for heroku-24 * remove packages from heroku-24 these no longer exist * Test that Chrome is on PATH and can launch To make testing fully representative of the Heroku platform, we have to run the built app against the run image and not the build image. (Whilst Heroku CI will use the build image, some apps will use the buildpack outside of CI, and so against the run image which has fewer system libraries than the build image.) * Add a `.dockerignore` to speed up local iteration This prevents unnecessary Docker cache invalidation when editing files that don't affect the image, meaning quicker iteration times when developing on this buildpack locally. * Fix packages on Heroku-24 Fixes this error: ``` chrome: error while loading shared libraries: libasound.so.2: cannot open shared object file: No such file or directory ``` And also cleans up the packages list, removing some packages that either are no longer needed, or already exist in the base image. This is safe to do now that `bin/test.sh` checks for missing shared libraries. --------- Co-authored-by: Ed Morley <501702+edmorley@users.noreply.github.com>
- Loading branch information
1 parent
7e489c1
commit 10cb812
Showing
5 changed files
with
81 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.github/ | ||
bin/test.sh | ||
Dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
ARG STACK_VERSION | ||
FROM --platform=linux/amd64 heroku/heroku:${STACK_VERSION}-build as build | ||
|
||
# This ARG duplication is required since the lines before and after the 'FROM' are in different scopes. | ||
ARG STACK_VERSION | ||
ENV STACK="heroku-${STACK_VERSION}" | ||
|
||
# On Heroku-24 and later the default user is not root. | ||
# Once support for Heroku-22 and older is removed, the `useradd` steps below can be removed. | ||
USER root | ||
|
||
# Emulate the platform where root access is not available | ||
RUN useradd -m non-root-user | ||
USER non-root-user | ||
RUN mkdir -p /tmp/build /tmp/cache /tmp/env | ||
COPY --chown=non-root-user . /buildpack | ||
|
||
# Sanitize the environment seen by the buildpack, to prevent reliance on | ||
# environment variables that won't be present when it's run by Heroku CI. | ||
RUN env -i PATH=$PATH HOME=$HOME STACK=$STACK /buildpack/bin/detect /tmp/build | ||
RUN env -i PATH=$PATH HOME=$HOME STACK=$STACK /buildpack/bin/compile /tmp/build /tmp/cache /tmp/env | ||
|
||
# We must then test against the run image since that has fewer system libraries installed. | ||
FROM --platform=linux/amd64 heroku/heroku:${STACK_VERSION} | ||
USER root | ||
# Emulate the platform where root access is not available | ||
RUN useradd -m non-root-user | ||
USER non-root-user | ||
COPY --from=build --chown=non-root-user /tmp/build /app | ||
# Emulate the platform which sources all .profile.d/ scripts on app boot. | ||
RUN echo 'for f in /app/.profile.d/*; do source "${f}"; done' > /app/.profile | ||
ENV HOME=/app | ||
WORKDIR /app | ||
# We have to use a login bash shell otherwise the .profile script won't be run. | ||
CMD ["bash", "-l"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
STACK_VERSION="${1:?'Error: The stack version number must be specified as the first argument.'}" | ||
|
||
set -x | ||
|
||
docker build --progress=plain --build-arg="STACK_VERSION=${STACK_VERSION}" -t heroku-buildpack-chrome-for-testing . | ||
|
||
# Note: All of the container commands must be run via a login bash shell otherwise the profile.d scripts won't be run. | ||
|
||
# Check the profile.d scripts correctly added the binaries to PATH. | ||
docker run heroku-buildpack-chrome-for-testing bash -l -c 'chrome --version' | ||
docker run heroku-buildpack-chrome-for-testing bash -l -c 'chromedriver --version' | ||
|
||
# Check that there are no missing dynamically linked libraries. | ||
docker run heroku-buildpack-chrome-for-testing bash -l -c 'ldd $(which chrome)' | ||
docker run heroku-buildpack-chrome-for-testing bash -l -c 'ldd $(which chromedriver)' | ||
|
||
# Check Chrome can fully boot in both new and old headless modes. | ||
docker run heroku-buildpack-chrome-for-testing bash -l -c 'chrome --no-sandbox --headless=new --screenshot https://google.com' | ||
docker run heroku-buildpack-chrome-for-testing bash -l -c 'chrome --no-sandbox --headless=old --screenshot https://google.com' |