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

Env: Add SSL port support to the docker compose #33480

Closed
wants to merge 2 commits into from
Closed
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
20 changes: 16 additions & 4 deletions packages/env/lib/build-docker-compose-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -197,7 +209,7 @@ module.exports = function buildDockerComposeConfig( config ) {
build: '.',
depends_on: [ 'mysql' ],
image: developmentWpImage,
ports: [ developmentPorts ],
ports: developmentPorts,
environment: {
...dbEnv.credentials,
...dbEnv.development,
Expand All @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions packages/env/lib/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ module.exports = async function readConfig( configPath ) {
plugins: [],
themes: [],
port: 8888,
ssl: null,
mappings: {},
config: {
WP_DEBUG: true,
Expand All @@ -91,6 +92,7 @@ module.exports = async function readConfig( configPath ) {
tests: {
config: { WP_DEBUG: false, SCRIPT_DEBUG: false },
port: 8889,
ssl: null,
},
},
};
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions packages/env/lib/config/parse-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ),
Expand Down
2 changes: 2 additions & 0 deletions packages/env/lib/config/test/__snapshots__/config.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Object {
"phpVersion": null,
"pluginSources": Array [],
"port": 2000,
"ssl": null,
"themeSources": Array [],
},
"tests": Object {
Expand All @@ -49,6 +50,7 @@ Object {
"phpVersion": null,
"pluginSources": Array [],
"port": 1000,
"ssl": null,
"themeSources": Array [],
},
},
Expand Down
6 changes: 6 additions & 0 deletions packages/env/lib/config/validate-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`
Expand Down