Allow env vars to control wp-config.php settings #63
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR makes all the settings in the
wp-config.php
file controllable by env vars. The hardcoded settings have caused us issues in the past, because they mean that e.g. it's not possible to run a wpc-based WordPress instance that can be pointed at two different database instances (e.g. to switch between a development and a test db). This means we end up having to wrangle a single database to switch between test and development data, e.g. by backing up dev data before running a test suite, and then having to restore that backup once the tests are complete.By making all the settings over-ridable by env vars, it's easy to point a WordPress container at different database instances, or even to run two different WordPress instances side-by-side on different ports, with each pointing at a different db.
I wouldn't expect us to to ever need to over-ride a lot of the settings in the file, but it was simple to extend the approach to every variable in
wp-config.php
, so that's what I've done.How to test
Pull this branch, and build a local copy of this image:
Pick an example Whippet project (ideally one you already have a db set up for locally, but any of our docker-based WordPress projects will work), and in the
docker-compose.yml
file replaceimage: thedxw/wpc-wordpress
withimage:local/test-wordpress-image
. When you rundocker-compose up
, the site should start up as normal.Now add a second MySQL container to the
docker-compose.yml
file, as follows:Add the following to the end of the
wordpress
image in thedocker-compose.yml
:Add
mysql_test_data:
to the list of volumes at the top ofdocker-compose.yml
.Stop your existing docker containers, and then start the network again with
DB_HOST=mysql_test docker compose up
. When you visit http://localhost, you should find you're at the start of a fresh WordPress install process. Complete the process and setup a basic site.Now stop the containers and re-start them in their original state, using
DB_HOST=mysql docker compose up
. You should find you're now viewing your original dev site. You can now switch between them by stopping and re-starting the network with the appropriateDB_HOST
variable, and the unique data for both should persist across docker stop/starts.