diff --git a/packages/env/lib/build-docker-compose-config.js b/packages/env/lib/build-docker-compose-config.js index fe8bf1e308379..7abc4a5b08f53 100644 --- a/packages/env/lib/build-docker-compose-config.js +++ b/packages/env/lib/build-docker-compose-config.js @@ -111,8 +111,20 @@ module.exports = function buildDockerComposeConfig( config ) { } // Set the default ports based on the config values. - const developmentPorts = `\${WP_ENV_PORT:-${ config.env.development.port }}:80`; - const testsPorts = `\${WP_ENV_TESTS_PORT:-${ config.env.tests.port }}:80`; + const developmentPorts = [ + `\${WP_ENV_PORT:-${ config.env.development.port }}:80`, + ]; + const testsPorts = [ + `\${WP_ENV_TESTS_PORT:-${ config.env.tests.port }}:80`, + ]; + + // Set the default SSL ports based on the config values. + if ( config.env.development.ssl ) { + developmentPorts.push( `${ config.env.development.ssl }:443` ); + } + if ( config.env.tests.ssl ) { + testsPorts.push( `${ config.env.tests.ssl }:443` ); + } // Set the WordPress, WP-CLI, PHPUnit PHP version if defined. const developmentPhpVersion = config.env.development.phpVersion @@ -197,7 +209,7 @@ module.exports = function buildDockerComposeConfig( config ) { build: '.', depends_on: [ 'mysql' ], image: developmentWpImage, - ports: [ developmentPorts ], + ports: developmentPorts, environment: { ...dbEnv.credentials, ...dbEnv.development, @@ -207,7 +219,7 @@ module.exports = function buildDockerComposeConfig( config ) { 'tests-wordpress': { depends_on: [ 'tests-mysql' ], image: testsWpImage, - ports: [ testsPorts ], + ports: testsPorts, environment: { ...dbEnv.credentials, ...dbEnv.tests, diff --git a/packages/env/lib/config/config.js b/packages/env/lib/config/config.js index 401077c495f30..7e45e37187e73 100644 --- a/packages/env/lib/config/config.js +++ b/packages/env/lib/config/config.js @@ -74,6 +74,7 @@ module.exports = async function readConfig( configPath ) { plugins: [], themes: [], port: 8888, + ssl: null, mappings: {}, config: { WP_DEBUG: true, @@ -91,6 +92,7 @@ module.exports = async function readConfig( configPath ) { tests: { config: { WP_DEBUG: false, SCRIPT_DEBUG: false }, port: 8889, + ssl: null, }, }, }; @@ -272,6 +274,11 @@ function withOverrides( config ) { // Don't overwrite the port of WP_HOME when set. if ( ! ( configKey === 'WP_HOME' && !! baseUrl.port ) ) { baseUrl.port = config.env[ envKey ].port; + + if ( config.env[ envKey ].ssl ) { + baseUrl.protocol = 'https'; + baseUrl.port = config.env[ envKey ].ssl; + } } config.env[ envKey ].config[ configKey ] = baseUrl.toString(); diff --git a/packages/env/lib/config/parse-config.js b/packages/env/lib/config/parse-config.js index ce0b7e044e070..5dad0d24ef63f 100644 --- a/packages/env/lib/config/parse-config.js +++ b/packages/env/lib/config/parse-config.js @@ -35,6 +35,7 @@ const HOME_PATH_PREFIX = `~${ path.sep }`; module.exports = function parseConfig( config, options ) { return { port: config.port, + ssl: config.ssl, phpVersion: config.phpVersion, coreSource: includeTestsPath( parseSourceString( config.core, options ), diff --git a/packages/env/lib/config/test/__snapshots__/config.js.snap b/packages/env/lib/config/test/__snapshots__/config.js.snap index 230796119d6e1..843b4848c8ce0 100644 --- a/packages/env/lib/config/test/__snapshots__/config.js.snap +++ b/packages/env/lib/config/test/__snapshots__/config.js.snap @@ -26,6 +26,7 @@ Object { "phpVersion": null, "pluginSources": Array [], "port": 2000, + "ssl": null, "themeSources": Array [], }, "tests": Object { @@ -49,6 +50,7 @@ Object { "phpVersion": null, "pluginSources": Array [], "port": 1000, + "ssl": null, "themeSources": Array [], }, }, diff --git a/packages/env/lib/config/validate-config.js b/packages/env/lib/config/validate-config.js index aa0572306569f..88c8ef041074b 100644 --- a/packages/env/lib/config/validate-config.js +++ b/packages/env/lib/config/validate-config.js @@ -51,6 +51,12 @@ function validateConfig( config, envLocation ) { ); } + if ( config?.ssl && ! Number.isInteger( config.ssl ) ) { + throw new ValidationError( + `Invalid .wp-env.json: "${ envPrefix }ssl" must be an integer.` + ); + } + if ( typeof config.config !== 'object' ) { throw new ValidationError( `Invalid .wp-env.json: "${ envPrefix }config" must be an object.`