@wordpress/env 11.3.0 → 11.4.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/lib/config/load-config.js +1 -1
- package/lib/config/parse-source-string.js +1 -1
- package/lib/runtime/docker/docker-config.js +34 -1
- package/lib/runtime/docker/wordpress.js +1 -1
- package/lib/runtime/playground/index.js +2 -2
- package/lib/test/build-docker-compose-config.js +46 -0
- package/package.json +2 -2
|
@@ -111,7 +111,8 @@ RUN groupadd -o -g $HOST_GID $HOST_USERNAME || true
|
|
|
111
111
|
RUN useradd -mlo -u $HOST_UID -g $HOST_GID $HOST_USERNAME || true
|
|
112
112
|
|
|
113
113
|
# Install any dependencies we need in the container.
|
|
114
|
-
${ installDependencies( 'wordpress', env, config ) }
|
|
114
|
+
${ installDependencies( 'wordpress', env, config ) }
|
|
115
|
+
${ getLoopbackPortConfig( config.env[ env ].port ) }`;
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
/**
|
|
@@ -331,7 +332,39 @@ RUN echo 'spx.data_dir="/tmp/spx"' >> /usr/local/etc/php/php.ini
|
|
|
331
332
|
RUN mkdir -p /tmp/spx && chmod 777 /tmp/spx`;
|
|
332
333
|
}
|
|
333
334
|
|
|
335
|
+
/**
|
|
336
|
+
* Generates Dockerfile RUN steps that make Apache also listen on the
|
|
337
|
+
* host-mapped wp-env port, so PHP loopback requests inside the container
|
|
338
|
+
* (WP-Cron, REST API loopback, Site Health) can reach WordPress at
|
|
339
|
+
* WP_HOME = http://localhost:<port>.
|
|
340
|
+
*
|
|
341
|
+
* @see https://github.com/WordPress/gutenberg/issues/20569
|
|
342
|
+
* @see https://github.com/docker-library/wordpress/issues/611#issuecomment-1378316911
|
|
343
|
+
*
|
|
344
|
+
* @param {number} port The host-side port wp-env exposes WordPress on.
|
|
345
|
+
* @return {string} The Dockerfile fragment, or '' when no change is needed.
|
|
346
|
+
*/
|
|
347
|
+
function getLoopbackPortConfig( port ) {
|
|
348
|
+
// Apache already listens on 80 by default and wp-env never
|
|
349
|
+
// configures SSL, so 80 and 443 are no-ops. Mirrors the same
|
|
350
|
+
// short-circuit in lib/config/add-or-replace-port.js.
|
|
351
|
+
if ( port === 80 || port === 443 ) {
|
|
352
|
+
return '';
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return `
|
|
356
|
+
# Make Apache listen on the wp-env-mapped port in addition to 80 so
|
|
357
|
+
# PHP loopback requests (WP-Cron, REST API, Site Health) inside the
|
|
358
|
+
# container reach WordPress at WP_HOME = http://localhost:${ port }.
|
|
359
|
+
# See https://github.com/WordPress/gutenberg/issues/20569
|
|
360
|
+
RUN echo 'Listen ${ port }' >> /etc/apache2/ports.conf
|
|
361
|
+
RUN sed -i 's|<VirtualHost \\*:80>|<VirtualHost *:80 *:${ port }>|' /etc/apache2/sites-enabled/000-default.conf`;
|
|
362
|
+
}
|
|
363
|
+
|
|
334
364
|
module.exports = {
|
|
335
365
|
writeDockerFiles,
|
|
336
366
|
ensureDockerInitialized,
|
|
367
|
+
// Exported for testing.
|
|
368
|
+
wordpressDockerFileContents,
|
|
369
|
+
getLoopbackPortConfig,
|
|
337
370
|
};
|
|
@@ -327,7 +327,7 @@ class PlaygroundRuntime {
|
|
|
327
327
|
try {
|
|
328
328
|
const pidContent = await fs.readFile( pidFile, 'utf8' );
|
|
329
329
|
pid = parseInt( pidContent.trim(), 10 );
|
|
330
|
-
} catch
|
|
330
|
+
} catch {
|
|
331
331
|
// PID file doesn't exist or can't be read
|
|
332
332
|
spinner.text = 'Stopped WordPress Playground.';
|
|
333
333
|
return;
|
|
@@ -350,7 +350,7 @@ class PlaygroundRuntime {
|
|
|
350
350
|
} catch {
|
|
351
351
|
// Process group already terminated
|
|
352
352
|
}
|
|
353
|
-
} catch
|
|
353
|
+
} catch {
|
|
354
354
|
// Process group doesn't exist or already terminated
|
|
355
355
|
}
|
|
356
356
|
|
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
* Internal dependencies
|
|
4
4
|
*/
|
|
5
5
|
const buildDockerComposeConfig = require( '../runtime/docker/build-docker-compose-config' );
|
|
6
|
+
const {
|
|
7
|
+
wordpressDockerFileContents,
|
|
8
|
+
getLoopbackPortConfig,
|
|
9
|
+
} = require( '../runtime/docker/docker-config' );
|
|
6
10
|
const getHostUser = require( '../runtime/docker/get-host-user' );
|
|
7
11
|
|
|
8
12
|
// The basic config keys which build docker compose config requires.
|
|
@@ -279,3 +283,45 @@ describe( 'buildDockerComposeConfig', () => {
|
|
|
279
283
|
} );
|
|
280
284
|
} );
|
|
281
285
|
} );
|
|
286
|
+
|
|
287
|
+
describe( 'getLoopbackPortConfig', () => {
|
|
288
|
+
it( 'returns Apache Listen and VirtualHost edits for a non-default port using an anchored sed pattern', () => {
|
|
289
|
+
const out = getLoopbackPortConfig( 8888 );
|
|
290
|
+
expect( out ).toContain( 'Listen 8888' );
|
|
291
|
+
expect( out ).toContain( '/etc/apache2/ports.conf' );
|
|
292
|
+
expect( out ).toContain( '<VirtualHost *:80 *:8888>' );
|
|
293
|
+
expect( out ).toContain(
|
|
294
|
+
'/etc/apache2/sites-enabled/000-default.conf'
|
|
295
|
+
);
|
|
296
|
+
// Guard against a future "simplification" to a greedy s/80/.../g
|
|
297
|
+
// that would also match e.g. unrelated "80" substrings.
|
|
298
|
+
expect( out ).not.toMatch( /s\|80\|/ );
|
|
299
|
+
expect( out ).toMatch( /s\|<VirtualHost \\\*:80>\|/ );
|
|
300
|
+
} );
|
|
301
|
+
|
|
302
|
+
it( 'returns an empty string for port 80 (Apache already listens there)', () => {
|
|
303
|
+
expect( getLoopbackPortConfig( 80 ) ).toBe( '' );
|
|
304
|
+
} );
|
|
305
|
+
|
|
306
|
+
it( 'returns an empty string for port 443 (wp-env does not configure SSL)', () => {
|
|
307
|
+
expect( getLoopbackPortConfig( 443 ) ).toBe( '' );
|
|
308
|
+
} );
|
|
309
|
+
} );
|
|
310
|
+
|
|
311
|
+
describe( 'wordpressDockerFileContents', () => {
|
|
312
|
+
it( 'injects the resolved per-environment port into the generated Dockerfile', () => {
|
|
313
|
+
const config = {
|
|
314
|
+
xdebug: 'off',
|
|
315
|
+
spx: 'off',
|
|
316
|
+
env: {
|
|
317
|
+
development: { port: 8888, phpVersion: null },
|
|
318
|
+
tests: { port: 8889, phpVersion: null },
|
|
319
|
+
},
|
|
320
|
+
};
|
|
321
|
+
const dockerfile = wordpressDockerFileContents( 'tests', config );
|
|
322
|
+
// Proves getLoopbackPortConfig is wired in AND that each environment
|
|
323
|
+
// uses its own port (not the development port).
|
|
324
|
+
expect( dockerfile ).toContain( 'Listen 8889' );
|
|
325
|
+
expect( dockerfile ).not.toContain( 'Listen 8888' );
|
|
326
|
+
} );
|
|
327
|
+
} );
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/env",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.4.0",
|
|
4
4
|
"description": "A zero-config, self contained local WordPress environment for development and testing.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"scripts": {
|
|
64
64
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "b862d8c84121a47bbeff882f6c87e61681ce2e0d"
|
|
67
67
|
}
|