Skip to content
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

fix: testing docker configuration #9

Merged
merged 6 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 0 additions & 16 deletions codeception.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ params:
extensions:
enabled:
- "Codeception\\Extension\\RunFailed"
- "lucatume\\WPBrowser\\Extension\\ChromeDriverController"
- "lucatume\\WPBrowser\\Extension\\DockerComposeController"
commands:
- "lucatume\\WPBrowser\\Command\\RunOriginal"
- "lucatume\\WPBrowser\\Command\\RunAll"
Expand All @@ -28,17 +26,3 @@ extensions:
- "lucatume\\WPBrowser\\Command\\DevStop"
- "lucatume\\WPBrowser\\Command\\DevInfo"
- "lucatume\\WPBrowser\\Command\\DevRestart"
- "lucatume\\WPBrowser\\Command\\ChromedriverUpdate"
config:
"lucatume\\WPBrowser\\Extension\\BuiltInServerController":
suites:
- Acceptance
docroot: "%WORDPRESS_ROOT_DIR%"
port: "%WORDPRESS_LOCALHOST_PORT%"
workers: 5
"lucatume\\WPBrowser\\Extension\\ChromeDriverController":
port: "%CHROMEDRIVER_PORT%"
binary: "%CHROMEDRIVER_BINARY%"
"lucatume\\WPBrowser\\Extension\\DockerComposeController":
compose-file: docker-compose.yml
env-file: tests/.env
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
Loading