Skip to content
This repository was archived by the owner on Jul 28, 2024. It is now read-only.

Conversation

@borekb
Copy link
Member

@borekb borekb commented Apr 26, 2018

Our dockerized dev setup, originally built in #1227, was not working for me, for example, the newest Xdebug is no longer compatible with PHP 5.x. When fixing this, I've encountered several other issues with our dev / test setup so this PR ends up being a pretty major update.

Highlights

  • Docker images are now pushed to Docker Hub as a source of truth. Previously, it was necessary to build images locally which could fetch newer dependencies than originally intended and break things.
  • Dev and testing stacks have been unified. There is now a single docker-compose.yml, using the same images for both scenarios.
  • Dockerized environment has been updated so that tests pass again
    • A couple are still failing (Workflow tests) but that might be due to actual bugs; to be resolved separately.
    • Selenium tests have been disabled entirely, see below.
  • Gulp is gone, replaced by simpler npm scripts (252c295).
  • PHP used for dev site and tests updated from 5.6 to 7.2.
  • Git Bash is required on Windows.
  • Dev-Setup.md has been reviewed and updated.

Noted for future work

  • Make Selenium tests work again. I spent some time on them in this PR but they will require more love. Quick thoughts at this point:
    • The actual test code (navigating URLs, clicking on things) still looks fine to me but the setup code is slightly suspicious, e.g., here or here.
    • facebook/webdriver seems to be more popular than giorgiosironi/phpunit-selenium (Selenium2TestCase), I've also heard good things about Codeception. As long-term maintainability of our Selenium tests is an important goal, considering a new framework is something we should do.
  • Generally refresh the code in tests. Most of it is alright, some could be improved.
  • test-config.yml is a legacy concept, for example, a test suite should define tests for both WP-CLI and Selenium workers, or for multiple versions of WordPress. Picking test suites from phpunit.xml should be enough.
  • Create a docker-compose version that does not contain any host-mounted volumes. That will very likely speed things up dramatically on Windows and macOS, and will enable us to deploy the test suite on CI.
  • Yes, CI.
  • VersionPress should bump its required PHP version to at least 7.0, see related discussion below: Dev setup updates – spring 2018 #1329 (comment)
  • Various other improvements:
    • Print progress of site setup when running tests (the console is "dark" for quite a while).
    • Better configuration of PhpStorm inspections
    • Adopt PHPStan (we already have an issue for it: Adopt PHPStan #1210)

Full todo list

  • Update dev and tests PHP from 5.6 to 7.2
  • Generally review Docker images.
  • Push images to Docker Hub, script it.
  • Explore why tests are failing and fix them
  • Explore Swarm / stacks instead of docker-compose
  • Unite dev-env and testing stack (🎉)
    • Done in 06e1965, makes a lot of things simpler.
  • Replace cleanup-docker-stack with npm stop and npm run stop-and-cleanup.
    • Done as part of 06e1965 (unit dev and test stack)
  • phpunit.override.xml is not a great name, it's not overriding anything. Gitignore phpunit.*.xml and update docs.
  • Get rid of Gulp as it is most likely causing subtle issues, and is generally a legacy technology anyway
  • 🏃 General Dev-Setup.md updates, @pavelevap to contribute his experience with Docker Toolbox. Almost done.
  • Think about ports, e.g., 3306 might conflict with local database server.
    • The bigger problem was port 80 which is not easily mapped to something else due to how WordPress treats home / siteurl. So both web servers and DB servers run on their default ports 80 and 3306. See 920e8fb.
  • Revert changes to frontend build script in 0cf52f0
  • Test with cmd.exe
    • After removing Gulp (252c295), cmd.exe was close to working again but it will just be easier to require Git Bash (curl, rm -rf etc.). It is automated since 9e0904e.
  • @pavelevap is experiencing issues with symlink in copyVersionPressFiles(), maybe related to Docker Toolbox? Explore this.
  • Check PhpStorm files
  • Move certain CLI arguments like --color from package.json to phpunit.xml
  • Consider switching to digests – example
    • Won't happen now.
  • Possibly output progress info during site setup - some steps take tens of seconds and the console is completely dark in that case.
    • Postponed.
  • Try removing volumes to speed things up
    • Later.

(This is an issue-less PR.)

borekb added 2 commits April 25, 2018 22:48
In the frontend `build` script, I had to use `node_modules/.bin/tsc` instead of just `tsc`. Maybe it's a bug in npm@6, it was working fine before.
- Some Docker images were no longer building, for example, newer Xdebug no longer supports PHP 5.x. I've updated all of them to use PHP 7.2.
- New `npm run rebuild-images` script.
- `Dev-Setup.md` updated slightly.
- Test database runs on a standard port 3306, I'm not sure how the 3391 port could have worked previously (`test-config.yml` does not support a port)

Some e2e tests are currently failing which needs further exploration.
@borekb borekb added the scope: dev-infrastructure Build scripts, IDE settings, CI, Docker dev stack, testing, tooling, etc. label Apr 26, 2018
@borekb borekb added this to the 4.0 milestone Apr 26, 2018
@borekb borekb self-assigned this Apr 26, 2018
@borekb borekb requested a review from pavelevap April 26, 2018 07:07
@borekb
Copy link
Member Author

borekb commented Apr 26, 2018

Current status:

  • I am able to npm install && npm start and browse the dockerized dev site, log in to it and activate VersionPress.
  • I am able to run all the unit tests successfully: cd ./plugins/versionpress/tests && docker-compose run tests ../vendor/bin/phpunit -c phpunit.xml --testsuite Unit
  • Full test suite can be run without crashing down but some tests are failing:

image

@pavelevap could you please try it on your computer and generally go through the Dev-Setup.md document to see if things make sense and are generally working? Feel free to update the instructions as you see fit and push to this PR.

"scripts": {
"start": "node webpack/webpack-dev-server.js --config webpack/webpack.dev.js --env.port 8888",
"build": "npm install && tsc --noEmit && webpack -p --config webpack/webpack.prod.js --hide-modules",
"build": "npm install && node_modules/.bin/tsc --noEmit && node_modules/.bin/webpack -p --config webpack/webpack.prod.js --hide-modules",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change does not work for me with cmd.exe.

@leepeterson
Copy link

@borekb about how soon do you think this’ll be approved and merged? exciting stuff!

@borekb
Copy link
Member Author

borekb commented May 3, 2018

@leepeterson The tests are currently failing and the updated Dockerfiles are not entirely finished yet. @pavelevap is looking at it, I personally won't have much time to return to it until next week.

borekb added 4 commits May 13, 2018 01:00
…ld be unified, images pushed to Docker Hub and maybe Docker stacks / Swarm mode used. This is the first step in which the dev-env image has been moved to its own `./dev-env/wordpress-image` folder and no longer installs WordPress automatically (this anticipates that tests will use this image as well).

The image is now also pushed to Docker Hub as `versionpress/wordpress`. It is close to the stock WordPress image, just with Git, WP-CLI and Xdebug installed.
…y, however, one-off jobs (we'll need them for tests) are not really supported, see moby/moby#23880, so this will get reverted soon.
- Both use cases run from the same `docker-compose.yml`. Docker-compose always runs a specific service from the stack, e.g., `docker-compose up -d wordpress`, never the entire `docker-compose up` which would also run the tests (we want that on demand).
- There are two test "services" in `docker-compose.yml`: `tests` which doesn't start WordPress and `tests-with-wordpress` which does. When running tests, a decision needs to be made which one to run.
- To make running tests simpler, there are two new npm scripts, `npm run tests:unit` and `npm run tests:full`. There is no `tests` script for now, one needs to decide which tests to run.
- `testenv` image and the entire `package.json` project in `plugins/versionpress/tests` is no longer needed so I've removed them.
- Docker Compose stack is run in background by default. Dev-Setup.md updated to give tips how to work with the background scenario.
- `npm run cleanup-docker-stack` was not a great name, there are now two separate scripts `stop` and `stop-and-cleanup` that hopefully make the distinction clearer.
- Containerized MySQL now runs on port 3306 (ports will need revising later on).
- Some cleanups of `docker-compose.yml`, e.g., `depends_on` removed (links are used).
- Other Dev-Setup.md cleanups.

Note that the 'tests:full' tests are still failing, fixes are coming in later commits.
@borekb
Copy link
Member Author

borekb commented May 13, 2018

✨ I've significantly updated our devenv / testing stack in 06e1965. See the commit's full description for all the details but the TL;DR is that we now use a unified Docker Compose stack for both devenv and testing purposes and the original testenv image is gone.

The integration tests are still failing but at least there is now a predictable environment where to hunt bugs down.

borekb added 3 commits May 13, 2018 20:28
…nning tests under the www-data user always (no sudo). This is done a bit indirectly as Docker doesn't support mounting volumes as a non-root user (see moby/moby#2259), by creating a custom image `versionpress/wordpress:cli`. Newer Git version was necessary to install into the container anyway.
@borekb
Copy link
Member Author

borekb commented May 13, 2018

Killed the permission bugs in 87769bf! 🎉

Many more tests pass now:

image

borekb added 10 commits May 13, 2018 21:59
…replace Gulp. It breaks down with more complex stuff like packaging a release.
…r in more complex cases, via TypeScript files in the `./scripts` directory.

Why the change?

Gulp used to be popular (and progressive!) when we first started with VersionPress but today, it feels like an unnecessary abstraction. In our specific case, it was probably causing strange issues with nested `npm run`s – hard to tell as some dependencies were a couple of years old / unmaintained. Also, in the past, we've had trouble generating ZIP files reliably and Gulp itself doesn't seem to be that actively developed anyway.

So I rewrote the functionality to a simpler and more straightforward code. Less dependencies = win.
…ntroduced in 0cf52f0 (was probably some temporary problem on my PC)
@borekb
Copy link
Member Author

borekb commented May 22, 2018

Status update:

db6842c adds support for command-line started debugging. That will be quite important for me as I cannot get PhpStorm to work correctly with Docker Compose (IDEA-192416).

All tests are passing for me when I launch them in smaller batches. The full tests:full suite is failing on too many database connections, we're probably not clearing things up properly somewhere. DBAsserter and it's staticInitialization() method is my guess. This query:

show status where `variable_name` = 'Max_used_connections';

returned like 150 concurrent connections.

@borekb
Copy link
Member Author

borekb commented May 23, 2018

a104f51 fixes "too many connections" database error, making the tests:full suite nearly pass:

image

The remaining errors are in workflow tests (cloning / merging) which will need a slight update of the filesystem structure in our Docker Compose stack. Errors are:

1) VersionPress\Tests\Workflow\CloneMergeTest::cloneLooksExactlySameAsOriginal
Exception: Error executing cmd 'php '/tmp/wp-cli-latest-stable.phar' vp activate --yes' from working directory '/var/www/html':
Error: VersionPress is already fully activated.


/opt/versionpress/tests/Automation/WpAutomation.php:621
/opt/versionpress/tests/Automation/WpAutomation.php:662
/opt/versionpress/tests/Automation/WpAutomation.php:507
/opt/versionpress/tests/Workflow/CloneMergeTest.php:232
/opt/versionpress/tests/Workflow/CloneMergeTest.php:186
/opt/versionpress/tests/Workflow/CloneMergeTest.php:37

2) VersionPress\Tests\Workflow\CloneMergeTest::dateModifiedMergesAutomatically
Exception: Error executing cmd 'php '/tmp/wp-cli-latest-stable.phar' vp activate --yes' from working directory '/var/www/html':
Error: VersionPress is already fully activated.


/opt/versionpress/tests/Automation/WpAutomation.php:621
/opt/versionpress/tests/Automation/WpAutomation.php:662
/opt/versionpress/tests/Automation/WpAutomation.php:507
/opt/versionpress/tests/Workflow/CloneMergeTest.php:232
/opt/versionpress/tests/Workflow/CloneMergeTest.php:83

3) VersionPress\Tests\Workflow\CloneMergeTest::sitesAreNotMergedIfThereIsConflict
Exception: Error executing cmd 'php '/tmp/wp-cli-latest-stable.phar' option update 'blogname' 'Blogname from clone - conflict'' from working directory '/var/www/wptestclone':
Error: This does not seem to be a WordPress install.
Pass --path=`path/to/wordpress` or run `wp core download`.


/opt/versionpress/tests/Automation/WpAutomation.php:621
/opt/versionpress/tests/Automation/WpAutomation.php:662
/opt/versionpress/tests/Automation/WpAutomation.php:329
/opt/versionpress/tests/Workflow/CloneMergeTest.php:146

- The test site moved into a subdirectory of /var/www/html – it is in `/var/ww/html/wptest`, the clone in `.../wptestclone`.
- Updated CloneMergeTest so that it runs correctly

Note: `CloneMergeTest::dateModifiedMergesAutomatically()` test currently fails but it's a problem with the merge driver, most likely, not with the testing setup itself.
@borekb
Copy link
Member Author

borekb commented May 23, 2018

2a477de makes Workflow tests run again.

Merge driver test is still failing because it seems that the merge driver doesn't select the newer datetime – might be an actual bug in it. This is an example output:

1) VersionPress\Tests\Workflow\CloneMergeTest::dateModifiedMergesAutomatically
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'2018-05-23 10:06:38
+'2018-05-23 10:05:51
 '

(The newer date is expected but wp vp pull and the merge driver chooses the older one.)

borekb added 2 commits May 23, 2018 13:34
…rrect place, not `/var/www/html` (it wasn't causing any major trouble but was unnecessary)
@borekb
Copy link
Member Author

borekb commented May 23, 2018

🎉 WP-CLI tests now fully now! The only failures are merge driver tests as described in #1329 (comment) which will be for a separate PR.

image

Remaining TODO items in this PR:

@borekb
Copy link
Member Author

borekb commented May 24, 2018

I've updated the PR description and consider this PR mostly done. @JanVoracek verified that the tests run exactly the same on Mac which is good.

If someone wants to look at Dev-Setup.md at this point and possibly try the dev / test setup, that would be great. I think we'll be able to merge next week.

Copy link
Collaborator

@pavelevap pavelevap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are working, huge improvements, I guess. 🎉 Some minor things can be solved in particular issues.

@borekb
Copy link
Member Author

borekb commented Jun 7, 2018

Thanks, @pavelevap, I think we can merge this.

@borekb borekb merged commit a491044 into master Jun 7, 2018
@borekb borekb deleted the dev-setup-updates branch June 7, 2018 12:35
@borekb borekb mentioned this pull request Jun 18, 2018
11 tasks
@borekb borekb mentioned this pull request Mar 26, 2019
10 tasks
@borekb borekb added the noteworthy Significant issue or PR, to be highlighted in release notes label Mar 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

noteworthy Significant issue or PR, to be highlighted in release notes scope: dev-infrastructure Build scripts, IDE settings, CI, Docker dev stack, testing, tooling, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants