@wordpress/env 10.39.0 → 11.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +127 -76
- package/lib/cli.js +67 -10
- package/lib/commands/clean.js +13 -4
- package/lib/commands/cleanup.js +79 -0
- package/lib/commands/destroy.js +30 -18
- package/lib/commands/index.js +6 -2
- package/lib/commands/logs.js +17 -8
- package/lib/commands/reset.js +46 -0
- package/lib/commands/run.js +13 -9
- package/lib/commands/start.js +54 -14
- package/lib/commands/status.js +160 -0
- package/lib/commands/stop.js +13 -6
- package/lib/config/get-config-from-environment-vars.js +2 -5
- package/lib/config/load-config.js +35 -5
- package/lib/config/parse-config.js +53 -21
- package/lib/config/post-process-config.js +38 -16
- package/lib/config/test/__snapshots__/config-integration.js.snap +16 -0
- package/lib/config/test/parse-config.js +33 -0
- package/lib/config/test/post-process-config.js +52 -0
- package/lib/runtime/docker/build-docker-compose-config.js +164 -125
- package/lib/runtime/docker/download-sources.js +5 -1
- package/lib/runtime/docker/download-wp-phpunit.js +3 -0
- package/lib/runtime/docker/index.js +281 -91
- package/lib/runtime/docker/init-config.js +20 -12
- package/lib/runtime/docker/wordpress.js +0 -15
- package/lib/runtime/errors.js +11 -0
- package/lib/runtime/index.js +40 -18
- package/lib/runtime/playground/blueprint-builder.js +25 -33
- package/lib/runtime/playground/index.js +82 -4
- package/lib/test/build-docker-compose-config.js +147 -0
- package/lib/test/cli.js +49 -13
- package/package.json +2 -2
- package/lib/commands/install-path.js +0 -33
|
@@ -88,6 +88,8 @@ function getMounts(
|
|
|
88
88
|
* @return {Object} A docker-compose config object, ready to serialize into YAML.
|
|
89
89
|
*/
|
|
90
90
|
module.exports = function buildDockerComposeConfig( config ) {
|
|
91
|
+
const testsEnabled = config.testsEnvironment !== false;
|
|
92
|
+
|
|
91
93
|
// Since we are mounting files from the host operating system
|
|
92
94
|
// we want to create the host user in some of our containers.
|
|
93
95
|
// This ensures ownership parity and lets us access files
|
|
@@ -99,12 +101,14 @@ module.exports = function buildDockerComposeConfig( config ) {
|
|
|
99
101
|
config.env.development,
|
|
100
102
|
hostUser.name
|
|
101
103
|
);
|
|
102
|
-
const testsMounts =
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
104
|
+
const testsMounts = testsEnabled
|
|
105
|
+
? getMounts(
|
|
106
|
+
config.workDirectoryPath,
|
|
107
|
+
config.env.tests,
|
|
108
|
+
hostUser.name,
|
|
109
|
+
'tests-wordpress'
|
|
110
|
+
)
|
|
111
|
+
: [];
|
|
108
112
|
|
|
109
113
|
// We use a custom Dockerfile in order to make sure that
|
|
110
114
|
// the current host user exists inside the container.
|
|
@@ -135,6 +139,7 @@ module.exports = function buildDockerComposeConfig( config ) {
|
|
|
135
139
|
//
|
|
136
140
|
// https://github.com/WordPress/gutenberg/issues/21164
|
|
137
141
|
if (
|
|
142
|
+
testsEnabled &&
|
|
138
143
|
config.env.development.coreSource &&
|
|
139
144
|
hasSameCoreSource( [ config.env.development, config.env.tests ] )
|
|
140
145
|
) {
|
|
@@ -169,138 +174,172 @@ module.exports = function buildDockerComposeConfig( config ) {
|
|
|
169
174
|
const developmentMysqlPorts = `\${WP_ENV_MYSQL_PORT:-${
|
|
170
175
|
config.env.development.mysqlPort ?? ''
|
|
171
176
|
}}:3306`;
|
|
172
|
-
const testsPorts = `\${WP_ENV_TESTS_PORT:-${ config.env.tests.port }}:80`;
|
|
173
|
-
const testsMysqlPorts = `\${WP_ENV_TESTS_MYSQL_PORT:-${
|
|
174
|
-
config.env.tests.mysqlPort ?? ''
|
|
175
|
-
}}:3306`;
|
|
176
177
|
|
|
177
178
|
const developmentPhpmyadminPorts = `\${WP_ENV_PHPMYADMIN_PORT:-${
|
|
178
179
|
config.env.development.phpmyadminPort ?? ''
|
|
179
180
|
}}:80`;
|
|
180
|
-
const testsPhpmyadminPorts = `\${WP_ENV_TESTS_PHPMYADMIN_PORT:-${
|
|
181
|
-
config.env.tests.phpmyadminPort ?? ''
|
|
182
|
-
}}:80`;
|
|
183
181
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
wordpress: {
|
|
209
|
-
depends_on: [ 'mysql' ],
|
|
210
|
-
build: {
|
|
211
|
-
context: '.',
|
|
212
|
-
dockerfile: 'WordPress.Dockerfile',
|
|
213
|
-
args: imageBuildArgs,
|
|
214
|
-
},
|
|
215
|
-
ports: [ developmentPorts ],
|
|
216
|
-
environment: {
|
|
217
|
-
APACHE_RUN_USER: '#' + hostUser.uid,
|
|
218
|
-
APACHE_RUN_GROUP: '#' + hostUser.gid,
|
|
219
|
-
...dbEnv.credentials,
|
|
220
|
-
...dbEnv.development,
|
|
221
|
-
WP_TESTS_DIR: '/wordpress-phpunit',
|
|
222
|
-
},
|
|
223
|
-
volumes: developmentMounts,
|
|
224
|
-
extra_hosts: [ 'host.docker.internal:host-gateway' ],
|
|
182
|
+
// MySQL healthcheck using MariaDB's official healthcheck.sh script.
|
|
183
|
+
// --connect: verifies TCP connection and that entrypoint has finished
|
|
184
|
+
// --innodb_initialized: ensures InnoDB storage engine is fully initialized
|
|
185
|
+
// MARIADB_AUTO_UPGRADE env var ensures healthcheck user exists for existing installations.
|
|
186
|
+
// Timing is generous to support slow CI environments.
|
|
187
|
+
const mysqlHealthcheck = {
|
|
188
|
+
test: [ 'CMD', 'healthcheck.sh', '--connect', '--innodb_initialized' ],
|
|
189
|
+
interval: '5s',
|
|
190
|
+
timeout: '10s',
|
|
191
|
+
retries: 12,
|
|
192
|
+
start_period: '60s',
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
// Build the services object, conditionally including tests services.
|
|
196
|
+
const services = {
|
|
197
|
+
mysql: {
|
|
198
|
+
image: 'mariadb:lts',
|
|
199
|
+
ports: [ developmentMysqlPorts ],
|
|
200
|
+
environment: {
|
|
201
|
+
MYSQL_ROOT_HOST: '%',
|
|
202
|
+
MYSQL_ROOT_PASSWORD: dbEnv.credentials.WORDPRESS_DB_PASSWORD,
|
|
203
|
+
MYSQL_DATABASE: dbEnv.development.WORDPRESS_DB_NAME,
|
|
204
|
+
// Ensures healthcheck user is created for existing installations.
|
|
205
|
+
MARIADB_AUTO_UPGRADE: '1',
|
|
225
206
|
},
|
|
226
|
-
'
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
ports: [ testsPorts ],
|
|
234
|
-
environment: {
|
|
235
|
-
APACHE_RUN_USER: '#' + hostUser.uid,
|
|
236
|
-
APACHE_RUN_GROUP: '#' + hostUser.gid,
|
|
237
|
-
...dbEnv.credentials,
|
|
238
|
-
...dbEnv.tests,
|
|
239
|
-
WP_TESTS_DIR: '/wordpress-phpunit',
|
|
207
|
+
volumes: [ 'mysql:/var/lib/mysql' ],
|
|
208
|
+
healthcheck: mysqlHealthcheck,
|
|
209
|
+
},
|
|
210
|
+
wordpress: {
|
|
211
|
+
depends_on: {
|
|
212
|
+
mysql: {
|
|
213
|
+
condition: 'service_healthy',
|
|
240
214
|
},
|
|
241
|
-
volumes: testsMounts,
|
|
242
|
-
extra_hosts: [ 'host.docker.internal:host-gateway' ],
|
|
243
215
|
},
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
dockerfile: 'CLI.Dockerfile',
|
|
249
|
-
args: imageBuildArgs,
|
|
250
|
-
},
|
|
251
|
-
volumes: developmentMounts,
|
|
252
|
-
user: hostUser.fullUser,
|
|
253
|
-
environment: {
|
|
254
|
-
...dbEnv.credentials,
|
|
255
|
-
...dbEnv.development,
|
|
256
|
-
WP_TESTS_DIR: '/wordpress-phpunit',
|
|
257
|
-
},
|
|
258
|
-
extra_hosts: [ 'host.docker.internal:host-gateway' ],
|
|
216
|
+
build: {
|
|
217
|
+
context: '.',
|
|
218
|
+
dockerfile: 'WordPress.Dockerfile',
|
|
219
|
+
args: imageBuildArgs,
|
|
259
220
|
},
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
volumes: testsMounts,
|
|
268
|
-
user: hostUser.fullUser,
|
|
269
|
-
environment: {
|
|
270
|
-
...dbEnv.credentials,
|
|
271
|
-
...dbEnv.tests,
|
|
272
|
-
WP_TESTS_DIR: '/wordpress-phpunit',
|
|
273
|
-
},
|
|
274
|
-
extra_hosts: [ 'host.docker.internal:host-gateway' ],
|
|
221
|
+
ports: [ developmentPorts ],
|
|
222
|
+
environment: {
|
|
223
|
+
APACHE_RUN_USER: '#' + hostUser.uid,
|
|
224
|
+
APACHE_RUN_GROUP: '#' + hostUser.gid,
|
|
225
|
+
...dbEnv.credentials,
|
|
226
|
+
...dbEnv.development,
|
|
227
|
+
WP_TESTS_DIR: '/wordpress-phpunit',
|
|
275
228
|
},
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
229
|
+
volumes: developmentMounts,
|
|
230
|
+
extra_hosts: [ 'host.docker.internal:host-gateway' ],
|
|
231
|
+
},
|
|
232
|
+
cli: {
|
|
233
|
+
depends_on: [ 'wordpress' ],
|
|
234
|
+
build: {
|
|
235
|
+
context: '.',
|
|
236
|
+
dockerfile: 'CLI.Dockerfile',
|
|
237
|
+
args: imageBuildArgs,
|
|
285
238
|
},
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
PMA_USER: 'root',
|
|
293
|
-
PMA_PASSWORD: 'password',
|
|
294
|
-
},
|
|
239
|
+
volumes: developmentMounts,
|
|
240
|
+
user: hostUser.fullUser,
|
|
241
|
+
environment: {
|
|
242
|
+
...dbEnv.credentials,
|
|
243
|
+
...dbEnv.development,
|
|
244
|
+
WP_TESTS_DIR: '/wordpress-phpunit',
|
|
295
245
|
},
|
|
246
|
+
extra_hosts: [ 'host.docker.internal:host-gateway' ],
|
|
296
247
|
},
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
248
|
+
phpmyadmin: {
|
|
249
|
+
image: 'phpmyadmin',
|
|
250
|
+
ports: [ developmentPhpmyadminPorts ],
|
|
251
|
+
environment: {
|
|
252
|
+
PMA_PORT: 3306,
|
|
253
|
+
PMA_HOST: 'mysql',
|
|
254
|
+
PMA_USER: 'root',
|
|
255
|
+
PMA_PASSWORD: 'password',
|
|
256
|
+
},
|
|
304
257
|
},
|
|
305
258
|
};
|
|
259
|
+
|
|
260
|
+
const volumes = {
|
|
261
|
+
...( ! config.env.development.coreSource && { wordpress: {} } ),
|
|
262
|
+
mysql: {},
|
|
263
|
+
'user-home': {},
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
if ( testsEnabled ) {
|
|
267
|
+
const testsPorts = `\${WP_ENV_TESTS_PORT:-${ config.env.tests.port }}:80`;
|
|
268
|
+
const testsMysqlPorts = `\${WP_ENV_TESTS_MYSQL_PORT:-${
|
|
269
|
+
config.env.tests.mysqlPort ?? ''
|
|
270
|
+
}}:3306`;
|
|
271
|
+
const testsPhpmyadminPorts = `\${WP_ENV_TESTS_PHPMYADMIN_PORT:-${
|
|
272
|
+
config.env.tests.phpmyadminPort ?? ''
|
|
273
|
+
}}:80`;
|
|
274
|
+
|
|
275
|
+
services[ 'tests-mysql' ] = {
|
|
276
|
+
image: 'mariadb:lts',
|
|
277
|
+
ports: [ testsMysqlPorts ],
|
|
278
|
+
environment: {
|
|
279
|
+
MYSQL_ROOT_HOST: '%',
|
|
280
|
+
MYSQL_ROOT_PASSWORD: dbEnv.credentials.WORDPRESS_DB_PASSWORD,
|
|
281
|
+
MYSQL_DATABASE: dbEnv.tests.WORDPRESS_DB_NAME,
|
|
282
|
+
// Ensures healthcheck user is created for existing installations.
|
|
283
|
+
MARIADB_AUTO_UPGRADE: '1',
|
|
284
|
+
},
|
|
285
|
+
volumes: [ 'mysql-test:/var/lib/mysql' ],
|
|
286
|
+
healthcheck: mysqlHealthcheck,
|
|
287
|
+
};
|
|
288
|
+
services[ 'tests-wordpress' ] = {
|
|
289
|
+
depends_on: {
|
|
290
|
+
'tests-mysql': {
|
|
291
|
+
condition: 'service_healthy',
|
|
292
|
+
},
|
|
293
|
+
},
|
|
294
|
+
build: {
|
|
295
|
+
context: '.',
|
|
296
|
+
dockerfile: 'Tests-WordPress.Dockerfile',
|
|
297
|
+
args: imageBuildArgs,
|
|
298
|
+
},
|
|
299
|
+
ports: [ testsPorts ],
|
|
300
|
+
environment: {
|
|
301
|
+
APACHE_RUN_USER: '#' + hostUser.uid,
|
|
302
|
+
APACHE_RUN_GROUP: '#' + hostUser.gid,
|
|
303
|
+
...dbEnv.credentials,
|
|
304
|
+
...dbEnv.tests,
|
|
305
|
+
WP_TESTS_DIR: '/wordpress-phpunit',
|
|
306
|
+
},
|
|
307
|
+
volumes: testsMounts,
|
|
308
|
+
extra_hosts: [ 'host.docker.internal:host-gateway' ],
|
|
309
|
+
};
|
|
310
|
+
services[ 'tests-cli' ] = {
|
|
311
|
+
depends_on: [ 'tests-wordpress' ],
|
|
312
|
+
build: {
|
|
313
|
+
context: '.',
|
|
314
|
+
dockerfile: 'Tests-CLI.Dockerfile',
|
|
315
|
+
args: imageBuildArgs,
|
|
316
|
+
},
|
|
317
|
+
volumes: testsMounts,
|
|
318
|
+
user: hostUser.fullUser,
|
|
319
|
+
environment: {
|
|
320
|
+
...dbEnv.credentials,
|
|
321
|
+
...dbEnv.tests,
|
|
322
|
+
WP_TESTS_DIR: '/wordpress-phpunit',
|
|
323
|
+
},
|
|
324
|
+
extra_hosts: [ 'host.docker.internal:host-gateway' ],
|
|
325
|
+
};
|
|
326
|
+
services[ 'tests-phpmyadmin' ] = {
|
|
327
|
+
image: 'phpmyadmin',
|
|
328
|
+
ports: [ testsPhpmyadminPorts ],
|
|
329
|
+
environment: {
|
|
330
|
+
PMA_PORT: 3306,
|
|
331
|
+
PMA_HOST: 'tests-mysql',
|
|
332
|
+
PMA_USER: 'root',
|
|
333
|
+
PMA_PASSWORD: 'password',
|
|
334
|
+
},
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
if ( ! config.env.tests.coreSource ) {
|
|
338
|
+
volumes[ 'tests-wordpress' ] = {};
|
|
339
|
+
}
|
|
340
|
+
volumes[ 'mysql-test' ] = {};
|
|
341
|
+
volumes[ 'tests-user-home' ] = {};
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return { services, volumes };
|
|
306
345
|
};
|
|
@@ -41,7 +41,11 @@ module.exports = function downloadSources( config, spinner ) {
|
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
for ( const
|
|
44
|
+
for ( const envName of Object.keys( config.env ) ) {
|
|
45
|
+
if ( envName === 'tests' && config.testsEnvironment === false ) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const env = config.env[ envName ];
|
|
45
49
|
env.pluginSources.forEach( addSource );
|
|
46
50
|
env.themeSources.forEach( addSource );
|
|
47
51
|
Object.values( env.mappings ).forEach( addSource );
|
|
@@ -40,6 +40,9 @@ module.exports = function downloadWPPHPUnit(
|
|
|
40
40
|
|
|
41
41
|
const promises = [];
|
|
42
42
|
for ( const env in config.env ) {
|
|
43
|
+
if ( env === 'tests' && config.testsEnvironment === false ) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
43
46
|
const wpVersion = wpVersions[ env ] ? wpVersions[ env ] : null;
|
|
44
47
|
const directory = path.join(
|
|
45
48
|
config.workDirectoryPath,
|