-
-
Notifications
You must be signed in to change notification settings - Fork 2
maint: rework PHP error reporting for link tester #104
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,3 +21,4 @@ KeymanSentry.php | |
| KeymanVersion.php | ||
| MarkdownHost.php | ||
| tests.inc.sh | ||
| tests.container.sh | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # Always use LF for Dockerfile - otherwise HEREDOCs in Dockerfile | ||
| # will not work on Windows - we end up with a filename `foo\r` for | ||
| # the command | ||
| # ```Dockerfile | ||
| # RUN <<EOF cat > foo | ||
| # echo "Hello world" | ||
| # EOF | ||
| # ``` | ||
| Dockerfile text eol=lf | ||
| *.sh text eol=lf |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,6 +81,9 @@ function build_docker_container() { | |
| builder_echo "Building using $BUILDER_CONFIGURATION configuration" | ||
|
|
||
| # Download docker image. --mount option requires BuildKit | ||
| # | ||
| # note: --no-cache may be added here if trying to replicate broken ci locally | ||
| # where Docker resources have been cached | ||
| DOCKER_BUILDKIT=1 $CONTAINER_ENGINE build -t $IMAGE_NAME --build-arg BUILDER_CONFIGURATION="${BUILDER_CONFIGURATION}" $FILE $TARGET | ||
| } | ||
|
|
||
|
|
@@ -188,6 +191,7 @@ function test_docker_container() { | |
|
|
||
| local LINK_RESULT=0 | ||
| echo "TIER_TEST" > tier.txt | ||
| trap _docker_cleanup_test_docker_container ERR EXIT SIGINT SIGTERM | ||
|
|
||
| # Similar pattern in ci.yml on sites | ||
|
|
||
|
|
@@ -206,17 +210,70 @@ function test_docker_container() { | |
| if ! builder_has_option --no-link-check; then | ||
| builder_echo blue "---- Testing links" | ||
|
|
||
| do_test_links_setup "${CONTAINER_DESC}" | ||
|
|
||
| do_test_links "http://localhost:${CONTAINER_PORT}" "$TEST_PATH" "${SKIP_PATHS[@]}" || LINK_RESULT=$? | ||
| builder_echo blue "Done checking links; linkinator exit code: ${LINK_RESULT}" | ||
| do_test_print_link_report | ||
|
|
||
| do_test_print_container_error_logs "${CONTAINER_DESC}" | ||
|
|
||
| do_test_links_cleanup "${CONTAINER_DESC}" | ||
| fi | ||
|
|
||
| rm tier.txt | ||
| return "$LINK_RESULT" | ||
| } | ||
|
|
||
| _docker_cleanup_test_docker_container() { | ||
| rm -f "$THIS_SCRIPT_PATH/tier.txt" | ||
| } | ||
|
|
||
| # | ||
| # Setup a temporary container for interactive composer updates | ||
| # | ||
| function docker_build_and_start_composer_container() { | ||
| local COMPOSER_ID=composer-temp | ||
| docker build -f Dockerfile --target composer-builder --tag $COMPOSER_ID . | ||
|
|
||
| local DOCKER_BINDING | ||
| if [[ $OSTYPE =~ msys|cygwin ]]; then | ||
| # Windows needs leading slashes for path | ||
| DOCKER_BINDING="//$(pwd):/var/www/html/" | ||
| else | ||
| DOCKER_BINDING="$(pwd):/var/www/html/" | ||
| fi | ||
|
|
||
| docker run -v "$DOCKER_BINDING" --name $COMPOSER_ID --user root --rm -d $COMPOSER_ID | ||
|
|
||
| echo | ||
| echo "Some of the following commands may be helpful:" | ||
| echo " docker exec $COMPOSER_ID composer audit" | ||
| echo " docker exec $COMPOSER_ID composer update" | ||
| echo " docker exec $COMPOSER_ID composer update --lock" | ||
| echo " docker exec $COMPOSER_ID composer require package-name" | ||
| echo " docker exec $COMPOSER_ID composer require package-name --dev" | ||
| echo | ||
| } | ||
|
|
||
| # | ||
| # Cleanup the temporary container used for interactive composer updates | ||
| # (including copying composer files) | ||
| # | ||
| function docker_stop_and_cleanup_composer_container() { | ||
| local COMPOSER_ID=composer-temp | ||
| # copy modified files to mounted volume: | ||
| docker exec $COMPOSER_ID cp composer.lock //var/www/html/ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are the double slash required?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a cygwin thing. Needed on Windows, otherwise it prepends a Windows path. Works without issue on other platforms as far as I have tested (might be worth testing on your Linux setup) |
||
| docker exec $COMPOSER_ID cp composer.json //var/www/html/ | ||
| # cleanup | ||
| docker stop $COMPOSER_ID | ||
| docker rmi $COMPOSER_ID | ||
|
|
||
| builder_echo "Copied any changes from composer.json, composer.lock from init container into repo" | ||
| builder_echo "Note: 'build.sh build' will be required if changes have been made to /vendor by composer" | ||
| } | ||
|
|
||
|
|
||
|
|
||
| # Returns 0 if the specified container engine is available, 1 otherwise | ||
| _is_container_engine() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #!/bin/bash | ||
| # | ||
| # Keyman is copyright (C) SIL Global. MIT License. | ||
| # | ||
| # Scripts to run in container for link tests -- capture all PHP messages emitted | ||
| # when each page is visited by the link checker, and report on errors | ||
| # | ||
|
|
||
| set -eu | ||
|
|
||
| if [[ ${BUILDER_PLATFORM-x} != docker ]]; then | ||
| echo tests.container.sh should run only in the Docker container context | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ $# -lt 1 ]; then | ||
| echo "usage: $0 setup|report|cleanup" | ||
| exit 65 | ||
| fi | ||
|
|
||
| ERROR_LOG=/tmp/php_errors.log | ||
|
|
||
| if [ "$1" == "setup" ]; then | ||
| cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini | ||
| echo "error_log = $ERROR_LOG" >> /usr/local/etc/php/php.ini | ||
| # note: apache restart must run from docker host | ||
| rm -f $ERROR_LOG | ||
| elif [ "$1" == "report" ]; then | ||
| if [ -f $ERROR_LOG ]; then | ||
| cat $ERROR_LOG | ||
| exit 1 | ||
| fi | ||
| elif [ "$1" == "cleanup" ]; then | ||
| cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini | ||
| # note: apache restart must run from docker host | ||
| else | ||
| echo "Invalid parameter" | ||
| exit 65 | ||
| fi | ||
|
|
||
| exit 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These could be split into a separate PR if you think that is warranted.