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

Dockerized dev setup#1227

Merged
borekb merged 66 commits intomasterfrom
1041-dockerized-dev-setup
Jul 3, 2017
Merged

Dockerized dev setup#1227
borekb merged 66 commits intomasterfrom
1041-dockerized-dev-setup

Conversation

@borekb
Copy link
Copy Markdown
Member

@borekb borekb commented May 21, 2017

Resolves #1041 (Dockerized development environment)
Resolves #1144 (Update .idea template files)
Resolves #974 (Update project dependencies)
Resolves parts of #1213 (Update dev setup and dependencies for 4.0-beta)

This is not perfect yet but already implements a lot of work so let's merge it.

Summary

  • Local development environment is powered by Docker, no need to set up local web server, database server or anything.
  • Tests run on Docker as well. Selenium tests are now as easy to run as unit tests.
  • Some VersionPress code had to be updated to work in a read-only environment (wp-content/plugins/versionpress is a read-only mount), for example, there's a new wp-content/vpcache folder instead of wp-content/plugins/versionpress/temp.
  • Dev-Setup.md rewritten and simplified, Testing.md incorporated into it.
  • Dependencies update and general project cleanup:
    • PhpStorm instructions and project files updated to 2017.2.
    • .editorconfig files unified.
    • PHP dependencies updated.

Known issues

Future work

  • Parametrize runs with WP-CLI or Selenium workers, or even do both at the same time (would require bigger change).
    • Technically, TestConfig / test-config.yml and TestRunnerOptions could be unified. Any parameter from test-config should be switchable via CLI argument.
  • Travis CI.
  • Selenium tests can be observed using VNC viewer, not that useful but it's fun to watch.

TODO list:

  • Build a basic Docker-based environment:
    • WordPress latest on PHP 5.6
    • WP-CLI and Git inside it
    • MySQL
    • Adminer
  • Map <repo>/plugins/versionpress into the container
  • PhpStorm setup, document debugging
  • Git on the host should be able to inspect site repo
  • DB tools on the host should be able to connect to the MySQL database
  • Turn off xdebug.remote_autostart for performance reasons
  • Pre-install WordPress via WP-CLI (currently, web installation needs to be finished)
  • Create npm scripts for tasks like starting up the stack or starting fresh
  • Update Dev-Setup.md
    • Build section
  • Run tests in a container
    • Unit tests
    • Full integration tests (Selenium, maybe switch to Chrome headless)
      • Basic docker-compose-based testing stack. Done in 6843b87.
      • Incorporate all the other tests (currently, only PublicWebTest is run). There will very likely be many smaller issues, for example, WpConfigSplitterTest tests are failing because file system is now read-only.
      • WpAutomation currently does tricky handling of users and permissions (root vs. www-data), this could most likely be simplified.
      • Make both Selenium and WP-CLI workers work easily at the same time (right now, it is a test-config.yml value that needs to be switched manually). Will be a separate PR.
      • Selenium host should be configurable via test-config.yml.
      • Testing section of Dev-Setup.md will need some cleanup.
      • In the end, don't forget to get rid of the temporary selenium-tests.
    • Integrate Testing.md into Dev-Setup.md
  • Sort out frontend dev
  • Smaller things while we're at it:
    • Unify .editorconfig files
    • Consider docker-compose up -d

borekb added 5 commits May 21, 2017 11:42
- Custom WP image build that includes WP-CLI and Git
- docker-file.yml to start the services easily
- Fresh start on Dev-Setup.md

Current status: the site can be started in a container and changes in the source folder are reflected there.
RUN yes | pecl install xdebug \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_autostart=1" >> /usr/local/etc/php/conf.d/xdebug.ini \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is what makes the responses slow. See http://stackoverflow.com/a/19273025/1243495

@borekb borekb self-assigned this Jun 21, 2017
@borekb borekb force-pushed the 1041-dockerized-dev-setup branch from 7a3de8f to 500ad42 Compare June 22, 2017 09:55
borekb added 3 commits June 23, 2017 00:20
- Section about Testing in Dev-Setup.md
- Composer dependencies revisited and slimmed down to a currently required minimum (packages for end2end tests are currently missing so those tests are broken; to be fixed soon).
- Most of the dependencies updated to a "reasonable latest", as far as PHP 5.6 compatibility allows (config.platform.php in composer.json updated to PHP 5.6).
- Some small fixes in actual code were required because of different paths in Docker containers or newer PHPUnit versions.
- PhpStorm .idea templates updated.
…WebTest` but this has been WIP for a couple of days so I'm going to commit the current state, with further updates coming soon. Details:

- New `tests/docker-compose.yml` that defines the testing stack.
    - Two new images, `apache-php5.6` to run the site and `testenv` to provide an environment for test execution.
- Two test suites implemented as docker-compose "services": `unit-tests` and `selenium-tests`.
- Tests can be run by npm scripts like `npm run test:unit-tests` or directly by docker-compose: `docker-compose run unit-tests`.
- Some VersionPress code has been updated to support the new testing setup:
    - ❗ `VERSIONPRESS_TEMP_DIR` changed from `VERSIONPRESS_PLUGIN_DIR/temp` to `WP_CONTENT_DIR/vpcache` as the plugin directory is now mounted as a read-only file system.
        - I took the opportunity to also update the name of the folder, it seems that the main use case is now to cache the definition files. So in `WP_CONTENT_DIR`, VersionPress currently creates two folders, `vpdb` and `vpcache`.
    - `WpAutomation` now deals with various permission issues (some path are mounted as read-only file systems with unchangeable `root:root` owner, some can and should be changed to www-data, etc.).
        - Running WP-CLI command as `root` is only needed in `ensureCleanInstallationIsAvailable()` so maybe this could go away soon.
    - `TestConfig::adminName` renamed to `adminUser` to be consistent with newer versions of WP-CLI.
    - Selenium test classes set host to `selenium-hub` (used to be `localhost`; maybe this should be a dynamic value coming from `test-config.yml`).
- `phpunit.xml` split to several `phpunit-<test-type>.xml` files. Each test suite / docker-compose service runs one of them.
- `test-config.yml` is no longer meant to be updated manually so it was committed to the repo directly. `test-config.sample.yml` was removed.
- Major updates to `Dev-Setup.md`: mostly the _Testing_ section but also added better intro and a new section _Docker tips_. Full debugging workflows around docker-compose tests are described.

Known issues:

- Those permissions in `WpAutomation`.
- `WpConfigSplitterTest` "unit" tests are failing because they write to file system which is now read-only.
- By far not all tests have been incorporated yet.
- I've used the name `vp01` for testing site, maybe it should be renamed to something more intuitive.
- Testing section of `Dev-Setup.md` will need some cleanup. VNC viewer setup would be cool.
@borekb
Copy link
Copy Markdown
Member Author

borekb commented Jun 27, 2017

Major progress on dockerizing integration tests in 6843b87. I'm very happy that running full-blown Selenium tests is now as easy as unit tests. Compare:

  • docker-compose run unit-tests
  • docker-compose run selenium-tests

It won't get much better than that :)

Good resource I used: sandrokeil/docker-selenium-grid-phpunit: An example how to use a Selenium-Grid with Docker and PHPUnit/Mink

Next steps:

- [ ] Incorporate all the other tests (currently, only `PublicWebTest` is run). - [ ] `WpConfigSplitterTest` "unit" tests are failing because they write to file system which is now read-only. - [ ] `WpAutomation` currently does tricky handling of users and permissions (root vs. www-data), this could most likely be simplified. - [ ] Choose a better name for the test site (currently, the legacy name `vp01` used). - [ ] Testing section of `Dev-Setup.md` will need some cleanup, documenting VNC viewer setup would be cool.

Moved to OP.

@borekb
Copy link
Copy Markdown
Member Author

borekb commented Jun 27, 2017

@JanVoracek I'm seeking feedback on certain things from 6843b87 please:

  1. Does it generally look right? For example, one slightly controversial thing is mounting the project folder to /var/www/html/vp01/wp-content/plugins/versionpress inside the containers: it makes it very convenient to edit files on the host OS and immediately see the changes inside containers, and it's also safe as the the mount is read-only but it also means that Docker will lock those files to root (impossible to change to www-data) and also, technically speaking, the contents of /var/www/html/vp01/wp-content/plugins/versionpress is slightly different than what gulp build exports and users install. I think those are reasonable trade-offs but would like to know your opinion.

  2. Is this OK?

    VERSIONPRESS_TEMP_DIR changed from VERSIONPRESS_PLUGIN_DIR/temp to WP_CONTENT_DIR/vpcache as the plugin directory is now mounted as a read-only file system.

    I've chosen the name vpcache as it seems that the main use of this folder in v4 is caching definition files (not only that but I think vpcache is still quite suitable). So in WP_CONTENT_DIR, VersionPress currently creates two folders: vpdb and vpcache.

  3. If you try to follow the instructions, do they work?

@borekb borekb added the noteworthy Significant issue or PR, to be highlighted in release notes label Jul 3, 2017
@borekb
Copy link
Copy Markdown
Member Author

borekb commented Jul 3, 2017

I've updated the original description to provide all the details on this PR. It is large enough so let's merge it!

image

@borekb borekb merged commit c6a14cc into master Jul 3, 2017
@borekb borekb deleted the 1041-dockerized-dev-setup branch July 3, 2017 17:32
@borekb borekb changed the title 1041 Dockerized dev setup Dockerized dev setup Jul 4, 2017
@borekb borekb mentioned this pull request Jul 4, 2017
3 tasks
@borekb borekb removed the noteworthy Significant issue or PR, to be highlighted in release notes label Jul 4, 2017
@borekb borekb mentioned this pull request May 24, 2018
19 tasks
@borekb borekb mentioned this pull request Mar 26, 2019
10 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants