Skip to content

Commit 8a39b9c

Browse files
Replace wp-env with Docker Compose (#55)
* Replace wp-env with docker-compose * Ommit cli version * Name stack tinify * Change 60 74 * Use dockerfiles to select build version * Use external network when running in github action * replace override * Update lock file * Use aliasses * Check for install * Wait for wordpress to be ready * Set env for per variation composer project * Add healthcheck for database * use playwright directly * Change check on playwright version * Change run cmds * Use correct images * Add network name to allow mock to connect * Remove force click * Add port to localstack * Pick specifically 4.6 * Use non-https * Skip salts * Wait for selectors to appear (due to js) * await clickers * Remove wordpress-scripts
1 parent 1fe8255 commit 8a39b9c

21 files changed

Lines changed: 270 additions & 20079 deletions

.github/workflows/integration-tests.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ jobs:
1515
strategy:
1616
matrix:
1717
include:
18-
- { wp: 40, php: 56 }
19-
- { wp: 40, php: 70 }
18+
- { wp: 46, php: 56 }
19+
- { wp: 46, php: 70 }
2020
- { wp: 57, php: 73 }
21-
- { wp: 60, php: 73 }
21+
- { wp: 60, php: 74 }
2222
- { wp: 63, php: 80 }
2323
- { wp: 67, php: 82 }
2424
- { wp: 68, php: 83 }
@@ -45,7 +45,7 @@ jobs:
4545

4646
- name: Get installed Playwright version
4747
id: playwright-version
48-
run: echo "PLAYWRIGHT_VERSION=$(node -e "console.log(require('./package-lock.json').dependencies['@playwright/test'].version)")" >> $GITHUB_ENV
48+
run: echo "PLAYWRIGHT_VERSION=$(node -p "require('./package.json').devDependencies['@playwright/test']")" >> $GITHUB_ENV
4949

5050
- name: Cache Playwright
5151
uses: actions/cache@v4

.wp-env.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

README.md

100644100755
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,15 @@ Got questions or feedback? Let us know! Contact us at support@tinypng.com.
3030
1. Run `bin/unit-tests <optional path to file>`.
3131

3232
### Running the integration tests
33-
1. Install Docker 1.12 and docker-compose.
34-
2. Install npm dependancies
35-
3. Run `bin/integration-tests <wordpress version> <php version>`. E.g. `bin/integration-tests 60 80`.
33+
1. Start the environment: `bin/run-wordpress [WORDPRESS_VERSION] [PHP_VERSION]`
34+
2. Start mocks `bin/run-mocks`
35+
3. Install npm dependencies: `npm install`.
36+
4. Run `WORDPRESS_PORT-80[WORDPRESS_VERSION] npm run test:playwright`.
37+
38+
To stop:
39+
1. Stop mocks `bin/stop-mocks`
40+
2. Stop WordPress `bin/stop-wordpress [WORDPRESS_VERSION] [PHP_VERSION]`
41+
3642

3743
### Check if the code follows WordPress standard
3844
1. Run `bin/check-style` to make sure there are no errors.

bin/run-wordpress

Lines changed: 99 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,113 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

3-
display_usage() {
4-
echo -e "Usage:\n\t$0 <version> \n\nExample:\n\t$0 45"
5-
}
3+
# Usage: bin/run-wordpress [WORDPRESS_VERSION] [PHP_VERSION]
4+
# Example: bin/run-wordpress 67 82
65

7-
if [ -z "${WORDPRESS_VERSION}" ]; then
8-
if [ $# -eq 0 ]; then
9-
display_usage
10-
exit 1
11-
fi
6+
# Ensure Docker CLI is installed.
7+
if ! command -v docker >/dev/null; then
8+
echo "Docker CLI is required."
9+
exit 1
10+
fi
11+
12+
WORDPRESS_VERSION_ENV="${1:-$WORDPRESS_VERSION}"
13+
PHP_VERSION_ENV="${2:-$PHP_VERSION}"
14+
15+
# Parse WordPress version parameter
16+
if [[ "$WORDPRESS_VERSION_ENV" =~ ^[0-9]{2}$ ]]; then
17+
WORDPRESS_VERSION="${WORDPRESS_VERSION_ENV:0:1}.${WORDPRESS_VERSION_ENV:1:1}"
18+
else
19+
WORDPRESS_VERSION="$WORDPRESS_VERSION_ENV"
20+
fi
21+
22+
# Exports as 8.2
23+
export WORDPRESS_VERSION
24+
export WORDPRESS_VERSION_ENV
25+
26+
# Parse WordPress version parameter
27+
if [[ "$PHP_VERSION_ENV" =~ ^[0-9]{2}$ ]]; then
28+
PHP_VERSION="${PHP_VERSION_ENV:0:1}.${PHP_VERSION_ENV:1:1}"
29+
else
30+
PHP_VERSION="$PHP_VERSION_ENV"
31+
fi
32+
# Exports as dot seperated: 5.6
33+
export PHP_VERSION
34+
export PHP_VERSION_ENV
35+
36+
: "${WORDPRESS_VERSION_ENV:=latest}" # default WordPress version shorthand
37+
: "${PHP_VERSION_ENV:=8.0}" # default PHP version shorthand
1238

13-
wp_version_input="$1"
14-
php_version_input="$2"
39+
: "${WORDPRESS_PORT:=80${WORDPRESS_VERSION_ENV}}"
40+
export WORDPRESS_PORT
1541

16-
## WordPress version ex. "6.7"
17-
export WORDPRESS_VERSION_FULL="${wp_version_input:0:1}.${wp_version_input:1}"
42+
export COMPOSE_PROJECT_NAME="tinify_${WORDPRESS_VERSION_ENV}_${PHP_VERSION_ENV}"
1843

19-
## WordPress version ex "67"
20-
export WORDPRESS_VERSION="${wp_version_input}"
44+
DOCKERFILE_PATH="./config/docker/${WORDPRESS_VERSION_ENV}-${PHP_VERSION_ENV}.Dockerfile"
45+
if [ ! -f "$DOCKERFILE_PATH" ]; then
46+
echo "No Docker file available: $DOCKERFILE_PATH"
47+
exit 1
48+
fi
49+
50+
echo "Starting Docker environment with WordPress $WORDPRESS_VERSION and PHP $PHP_VERSION..."
51+
docker compose -f config/docker-compose.yml up -d
52+
53+
echo "Installing WordPress..."
2154

22-
## PHP Version ex "80"
23-
export PHP_VERSION="${php_version_input}"
55+
docker compose -f config/docker-compose.yml run --rm --user root --no-TTY --env WORDPRESS_PORT --env WORDPRESS_VERSION wpcli bash <<EOF
56+
set -e
57+
58+
if [ ! -f wp-load.php ]; then
59+
echo "Downloading WordPress \${WORDPRESS_VERSION}..."
60+
TMP=\$(mktemp -d)
61+
curl -fsSL "http://wordpress.org/wordpress-\${WORDPRESS_VERSION}.tar.gz" | tar -xz -C "\$TMP"
62+
cp -R "\$TMP"/wordpress/* .
63+
rm -rf "\$TMP"
64+
fi
2465
25-
## PHP Version ex "80"
26-
export PHP_VERSION_FULL="${PHP_VERSION:0:1}.${PHP_VERSION:1}"
27-
28-
echo "Starting WordPress ${WORDPRESS_VERSION_FULL} on PHP ${PHP_VERSION_FULL}"
66+
if [ ! -f wp-config.php ]; then
67+
wp config create --dbname=wordpress --dbuser=wordpress --dbpass=wordpress --dbhost=db --allow-root --skip-salts
2968
fi
3069
31-
export WP_ENV_TESTS_PORT=80${WORDPRESS_VERSION}
32-
export WP_ENV_CORE=WordPress/Wordpress#${WORDPRESS_VERSION_FULL}
33-
export WP_ENV_PHP_VERSION=${PHP_VERSION_FULL}
70+
until wp db check --allow-root; do
71+
echo "DB not ready yet.."
72+
sleep 2
73+
done
3474
35-
npx wp-env start || exit 1
75+
wp db create --allow-root 2>/dev/null || true
3676
37-
echo "Installing compatible plugins.."
77+
if ! wp core is-installed --allow-root; then
78+
wp core install \
79+
--url=http://localhost:${WORDPRESS_PORT} \
80+
--title='My Site' \
81+
--admin_user=admin \
82+
--admin_password=password \
83+
--admin_email=wordpress@example.com \
84+
--skip-email \
85+
--allow-root
86+
chown -R 33:33 wp-content/uploads/
87+
else
88+
echo "WordPress already installed."
89+
fi
90+
EOF
91+
92+
echo "Activating tinify.."
93+
docker compose -f config/docker-compose.yml run --rm wpcli wp plugin activate tiny-compress-images --allow-root
3894

39-
if [ "$WORDPRESS_VERSION" -ge 55 ]; then
40-
echo "Installing compatible plugins for WordPress ${WORDPRESS_VERSION_FULL}.."
41-
npx wp-env run tests-cli wp plugin install amazon-s3-and-cloudfront || exit 1
95+
if [ "$WORDPRESS_VERSION_ENV" -ge 55 ]; then
96+
echo "Installing compatible plugins for WordPress ${WORDPRESS_PORT}.."
97+
docker compose -f config/docker-compose.yml run --rm --user 33 wpcli wp plugin install amazon-s3-and-cloudfront --activate --allow-root || exit 1
4298
fi
4399

44-
echo "To stop, run: bin/stop-wordpress"
100+
MAX_ATTEMPTS=10
101+
ATTEMPT=0
102+
until curl -s --head --fail "http://localhost:${WORDPRESS_PORT}" >/dev/null; do
103+
if [ $ATTEMPT -ge $MAX_ATTEMPTS ]; then
104+
echo "Timed out waiting for WordPress"
105+
exit 1
106+
fi
107+
echo "Waiting for WordPress to be ready..."
108+
sleep 2
109+
ATTEMPT=$((ATTEMPT + 1))
110+
done
111+
112+
echo "WordPress is ready at http://localhost:${WORDPRESS_PORT} (admin/password)"
113+
echo "To stop, run: bin/stop-wordpress ${WORDPRESS_VERSION_ENV} ${PHP_VERSION_ENV}"

bin/stop-mocks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ mv src/vendor/tinify/Tinify/Client.php.bak src/vendor/tinify/Tinify/Client.php
55
mv src/config/class-tiny-config.php.bak src/config/class-tiny-config.php
66

77
echo "Shutting down mocks.."
8-
docker compose -f config/mocks.docker-compose.yml down
8+
docker compose -f config/mocks.docker-compose.yml down -v

bin/stop-wordpress

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

3+
echo "Stopping Docker environment..."
34

4-
npx wp-env stop
5+
WORDPRESS_VERSION_ENV="${1:-$WORDPRESS_VERSION}"
6+
export WORDPRESS_VERSION_ENV
57

8+
PHP_VERSION_ENV="${2:-$PHP_VERSION}"
9+
export PHP_VERSION_ENV
610

11+
export COMPOSE_PROJECT_NAME="tinify_${WORDPRESS_VERSION_ENV}_${PHP_VERSION_ENV}"
12+
13+
docker compose -f config/docker-compose.yml down -v

config/docker-compose.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
services:
2+
db:
3+
image: mariadb:lts
4+
environment:
5+
MYSQL_DATABASE: wordpress
6+
MYSQL_USER: wordpress
7+
MYSQL_PASSWORD: wordpress
8+
MYSQL_ROOT_PASSWORD: root
9+
volumes:
10+
- db_data:/var/lib/mysql
11+
ports:
12+
- '3306:3306'
13+
healthcheck:
14+
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
15+
start_period: 10s
16+
interval: 10s
17+
timeout: 5s
18+
retries: 3
19+
networks:
20+
- tinify
21+
22+
wordpress:
23+
depends_on:
24+
- db
25+
build:
26+
dockerfile: docker/${WORDPRESS_VERSION_ENV}-${PHP_VERSION_ENV}.Dockerfile
27+
environment:
28+
WORDPRESS_DB_HOST: db:3306
29+
WORDPRESS_DB_USER: wordpress
30+
WORDPRESS_DB_PASSWORD: wordpress
31+
WORDPRESS_DB_NAME: wordpress
32+
WORDPRESS_DEBUG: '1'
33+
AWS_ENDPOINT: http://localstack:4566
34+
AWS_USE_PATH_STYLE_ENDPOINT: true
35+
AWS_ACCESS_KEY_ID: test_key_id
36+
AWS_SECRET_ACCESS_KEY: test_secret_access_key
37+
AWS_REGION: eu-central-1
38+
AWS_DEFAULT_REGION: eu-central-1
39+
volumes:
40+
- wordpress_data:/var/www/html
41+
- ../:/var/www/html/wp-content/plugins/tiny-compress-images
42+
ports:
43+
- '${WORDPRESS_PORT:-8000}:80'
44+
extra_hosts: ['host.docker.internal:host-gateway']
45+
networks:
46+
- tinify
47+
48+
wpcli:
49+
image: 'wordpress:cli-php${PHP_VERSION:-8.2}'
50+
user: "33:33"
51+
environment:
52+
WORDPRESS_DB_HOST: db:3306
53+
WORDPRESS_DB_USER: wordpress
54+
WORDPRESS_DB_PASSWORD: wordpress
55+
WORDPRESS_DB_NAME: wordpress
56+
volumes:
57+
- wordpress_data:/var/www/html
58+
- ../:/var/www/html/wp-content/plugins/tiny-compress-images
59+
working_dir: /var/www/html
60+
networks:
61+
- tinify
62+
depends_on:
63+
wordpress:
64+
condition: service_started
65+
db:
66+
condition: service_healthy
67+
68+
volumes:
69+
db_data:
70+
wordpress_data:
71+
72+
networks:
73+
tinify:
74+
name: tinify

config/docker/46-56.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM wordpress:4.6-php5.6-apache

config/docker/46-70.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM wordpress:4.6-php7.0-apache

config/docker/57-73.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM wordpress:5.7-php7.3-apache

0 commit comments

Comments
 (0)