Skip to content

Commit

Permalink
fix: testing docker configuration
Browse files Browse the repository at this point in the history
- Use `bin/wait-for-it.sh` to wait on the WordPress instance boot.
- Add notes about the testing setup in the `README.md`.
- Simplify `docker-compose.yml` health checks.

Fixes: #4
  • Loading branch information
johnhooks committed Dec 15, 2023
1 parent 43940e2 commit dfb407b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 29 deletions.
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,34 @@ A super cool search plugin which uses indexing to make the search of post conten

### Getting started

The testing environment setup in a container through Docker.
The development environment is setup in a Docker container.

```sh
# Command to start the testing WordPress instance.
# Create a development environment file
cp .env.example .env

# Command to start the development WordPress instance.
docker-compose up -d
```

## Testing

The development environment is setup in a separate Docker container than development.

```sh
# Create a testing environment file
cp tests/.env.example tests/.env

# Command to start the testing WordPress instance.
bin/test-up.sh

# Command to run Codeception unit tests from inside the container.
bin/test-run.sh unit

# Command to run Codeception acceptance tests from outside the container.
vendor/bin/codecept run acceptance
```

### Testing database

The testing container does not persist volumes. If a local database dump exists, it will be loaded when initializing the database container.
Expand All @@ -25,5 +46,5 @@ Use the following command to create a local database dump.

```sh
# Command to dump the testing database to tests/_data/dump.sql
bin/dump-acceptance-db
bin/dump-acceptance-db.sh
```
5 changes: 3 additions & 2 deletions bin/test-up.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash

docker compose --file tests/docker-compose.yml --env-file tests/.env up --wait
docker compose --file tests/docker-compose.yml --env-file tests/.env exec -T wordpress chown -R www-data:www-data wp-content wp-content/plugins wp-content/plugins/indexed-search
docker compose --file tests/docker-compose.yml --env-file tests/.env up -d
./bin/wait-for-it.sh http://localhost:5389
docker compose --file tests/docker-compose.yml --env-file tests/.env exec -T wordpress chown www-data:www-data wp-content wp-content/plugins
docker compose --file tests/docker-compose.yml --env-file tests/.env exec -T -w /var/www/html/wp-content/plugins/indexed-search wordpress bash bin/wp-install.sh
32 changes: 14 additions & 18 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ version: "3.8"

services:
wordpress:
container_name: index_search_wordpress
restart: always
build:
context: ./config/development

env_file:
- .env

ports:
- ${WORDPRESS_LOCALHOST_PORT}:80
- 9003:9003

environment:
WORDPRESS_DB_HOST: database
Expand All @@ -31,9 +32,9 @@ services:
"--fail",
"http://localhost:80",
]
interval: 1s
timeout: 1s
retries: 30
interval: 30s
timeout: 30s
retries: 3

tmpfs:
- /var/www/html
Expand All @@ -46,10 +47,12 @@ services:
- database

database:
container_name: index_search_database
image: mariadb:10.8
restart: always

env_file:
- .env

ports:
- "${WORDPRESS_DB_LOCALHOST_PORT}:3306"

Expand All @@ -60,20 +63,13 @@ services:
MYSQL_DATABASE: ${WORDPRESS_DB_NAME} # Same as db name.

healthcheck:
test:
[
"CMD",
"mysqlshow",
"-u${WORDPRESS_DB_USER}",
"-p${WORDPRESS_DB_PASSWORD}",
"${WORDPRESS_DB_NAME}",
]
interval: 1s
timeout: 1s
retries: 30
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
interval: 30s
timeout: 30s
retries: 3

tmpfs:
- /var/lib/mysql

volumes:
- ./tests/_data/dump.sql:/docker-entrypoint-initdb.d/datadump.sql
- ./tests/_data:/docker-entrypoint-initdb.d
12 changes: 6 additions & 6 deletions tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ services:
"--fail",
"http://localhost:80",
]
interval: 1s
timeout: 1s
retries: 30
interval: 30s
timeout: 30s
retries: 3

tmpfs:
- /var/www/html
Expand Down Expand Up @@ -60,9 +60,9 @@ services:

healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
interval: 1s
timeout: 1s
retries: 30
interval: 30s
timeout: 30s
retries: 3

tmpfs:
- /var/lib/mysql
Expand Down

0 comments on commit dfb407b

Please sign in to comment.