-
Notifications
You must be signed in to change notification settings - Fork 86
Site PHP runtime & File Access options #3786
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
eea3a72
Add per-site mode and file access settings (RSM-3958)
bcotrim e1cfcd8
Let users pick the PHP runtime at site creation, rename mode to PHP r…
bcotrim 92c50fe
Validate CLI runtime/file-access flags with zod, centralize the defau…
bcotrim 9b42fb1
Reword the native file-access explainer to avoid overstating isolation
bcotrim 84fa29e
Merge remote-tracking branch 'origin/trunk' into rsm-3958-add-php-mod…
bcotrim 6ae6876
Track weekly active sites by PHP runtime
bcotrim b173b0f
Default new sites to native PHP, remove the beta toggle, and track ru…
bcotrim 36d7686
Run native blueprint WP-CLI steps with the bundled PHP
bcotrim f3f6dd2
Default existing sites to native PHP and apply runtime/file-access re…
bcotrim 6ea9513
Move runtime adoption tracking into the CLI start path
bcotrim 3678052
Fix prettier formatting in the server-manager wiring test
bcotrim 6f34ea1
No custom types
fredrikekelund 179150d
Use a loose CLI config schema and render runtime copy as components
bcotrim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -30,7 +30,19 @@ import { | |||||||||||||||||||||||||||||||||
| removeDbConstants, | ||||||||||||||||||||||||||||||||||
| } from '@studio/common/lib/remove-default-db-constants'; | ||||||||||||||||||||||||||||||||||
| import { readSharedConfig } from '@studio/common/lib/shared-config'; | ||||||||||||||||||||||||||||||||||
| import { SITE_RUNTIME_NATIVE_PHP } from '@studio/common/lib/site-runtime'; | ||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||
| isFileAccessAllowedForRuntime, | ||||||||||||||||||||||||||||||||||
| SITE_FILE_ACCESS_ALL_FILES, | ||||||||||||||||||||||||||||||||||
| SITE_FILE_ACCESS_SITE_DIRECTORY, | ||||||||||||||||||||||||||||||||||
| type SiteFileAccess, | ||||||||||||||||||||||||||||||||||
| } from '@studio/common/lib/site-file-access'; | ||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||
| SITE_MODE_NATIVE, | ||||||||||||||||||||||||||||||||||
| SITE_MODE_SANDBOX, | ||||||||||||||||||||||||||||||||||
| SITE_RUNTIME_NATIVE_PHP, | ||||||||||||||||||||||||||||||||||
| siteRuntimeFromMode, | ||||||||||||||||||||||||||||||||||
| type SiteRuntime, | ||||||||||||||||||||||||||||||||||
| } from '@studio/common/lib/site-runtime'; | ||||||||||||||||||||||||||||||||||
| import { sortSites } from '@studio/common/lib/sort-sites'; | ||||||||||||||||||||||||||||||||||
| import { getServerFilesPath } from '@studio/common/lib/well-known-paths'; | ||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||
|
|
@@ -39,7 +51,11 @@ import { | |||||||||||||||||||||||||||||||||
| } from '@studio/common/lib/wordpress-version-utils'; | ||||||||||||||||||||||||||||||||||
| import { fetchWordPressVersions } from '@studio/common/lib/wordpress-versions'; | ||||||||||||||||||||||||||||||||||
| import { SiteCommandLoggerAction as LoggerAction } from '@studio/common/logger-actions'; | ||||||||||||||||||||||||||||||||||
| import { type SupportedPHPVersion } from '@studio/common/types/php-versions'; | ||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||
| RecommendedPHPVersion, | ||||||||||||||||||||||||||||||||||
| SupportedPHPVersions, | ||||||||||||||||||||||||||||||||||
| type SupportedPHPVersion, | ||||||||||||||||||||||||||||||||||
| } from '@studio/common/types/php-versions'; | ||||||||||||||||||||||||||||||||||
| import { __, sprintf } from '@wordpress/i18n'; | ||||||||||||||||||||||||||||||||||
| import { isStepDefinition, type BlueprintV1Declaration } from '@wp-playground/blueprints'; | ||||||||||||||||||||||||||||||||||
| import { bumpStat, getPlatformMetric } from 'cli/lib/bump-stat'; | ||||||||||||||||||||||||||||||||||
|
|
@@ -62,13 +78,8 @@ import { | |||||||||||||||||||||||||||||||||
| } from 'cli/lib/dependency-management/paths'; | ||||||||||||||||||||||||||||||||||
| import { updateServerFiles } from 'cli/lib/dependency-management/setup'; | ||||||||||||||||||||||||||||||||||
| import { downloadWordPress } from 'cli/lib/dependency-management/wordpress'; | ||||||||||||||||||||||||||||||||||
| import { getSiteRuntime } from 'cli/lib/feature-flags'; | ||||||||||||||||||||||||||||||||||
| import { copyLanguagePackToSite } from 'cli/lib/language-packs'; | ||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||
| getRecommendedPhpVersionForSiteRuntime, | ||||||||||||||||||||||||||||||||||
| getSupportedPhpVersionsForSiteRuntime, | ||||||||||||||||||||||||||||||||||
| validatePhpVersionForSiteRuntime, | ||||||||||||||||||||||||||||||||||
| } from 'cli/lib/php-versions'; | ||||||||||||||||||||||||||||||||||
| import { validateSupportedPhpVersion } from 'cli/lib/php-versions'; | ||||||||||||||||||||||||||||||||||
| import { getPreferredSiteLanguage } from 'cli/lib/site-language'; | ||||||||||||||||||||||||||||||||||
| import { generateSiteName } from 'cli/lib/site-name'; | ||||||||||||||||||||||||||||||||||
| import { getDefaultSitePath } from 'cli/lib/site-paths'; | ||||||||||||||||||||||||||||||||||
|
|
@@ -88,6 +99,8 @@ export type CreateCommandOptions = { | |||||||||||||||||||||||||||||||||
| siteId?: string; | ||||||||||||||||||||||||||||||||||
| wpVersion: string; | ||||||||||||||||||||||||||||||||||
| phpVersion: SupportedPHPVersion; | ||||||||||||||||||||||||||||||||||
| runtime: SiteRuntime; | ||||||||||||||||||||||||||||||||||
| fileAccess: SiteFileAccess; | ||||||||||||||||||||||||||||||||||
| customDomain?: string; | ||||||||||||||||||||||||||||||||||
| enableHttps: boolean; | ||||||||||||||||||||||||||||||||||
| blueprint?: { | ||||||||||||||||||||||||||||||||||
|
|
@@ -106,8 +119,15 @@ export async function runCommand( | |||||||||||||||||||||||||||||||||
| sitePath: string, | ||||||||||||||||||||||||||||||||||
| options: CreateCommandOptions | ||||||||||||||||||||||||||||||||||
| ): Promise< void > { | ||||||||||||||||||||||||||||||||||
| const phpVersion = validatePhpVersionForSiteRuntime( options.phpVersion ); | ||||||||||||||||||||||||||||||||||
| const siteRuntime = getSiteRuntime(); | ||||||||||||||||||||||||||||||||||
| const siteRuntime = options.runtime; | ||||||||||||||||||||||||||||||||||
| if ( ! isFileAccessAllowedForRuntime( siteRuntime, options.fileAccess ) ) { | ||||||||||||||||||||||||||||||||||
| throw new LoggerError( | ||||||||||||||||||||||||||||||||||
| __( | ||||||||||||||||||||||||||||||||||
| 'File access "all-files" requires the native PHP runtime. The sandbox only has access to the site directory.' | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| const phpVersion = validateSupportedPhpVersion( options.phpVersion ); | ||||||||||||||||||||||||||||||||||
| const isOnlineStatus = await isOnline(); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||
|
|
@@ -308,6 +328,8 @@ export async function runCommand( | |||||||||||||||||||||||||||||||||
| adminEmail, | ||||||||||||||||||||||||||||||||||
| port, | ||||||||||||||||||||||||||||||||||
| phpVersion, | ||||||||||||||||||||||||||||||||||
| runtime: siteRuntime, | ||||||||||||||||||||||||||||||||||
| fileAccess: options.fileAccess, | ||||||||||||||||||||||||||||||||||
| running: false, | ||||||||||||||||||||||||||||||||||
| isWpAutoUpdating: options.wpVersion === DEFAULT_WORDPRESS_VERSION, | ||||||||||||||||||||||||||||||||||
| customDomain: options.customDomain, | ||||||||||||||||||||||||||||||||||
|
|
@@ -498,8 +520,6 @@ export const registerCommand = ( yargs: StudioArgv ) => { | |||||||||||||||||||||||||||||||||
| command: 'create', | ||||||||||||||||||||||||||||||||||
| describe: __( 'Create a new site' ), | ||||||||||||||||||||||||||||||||||
| builder: ( yargs ) => { | ||||||||||||||||||||||||||||||||||
| const supportedPhpVersions = getSupportedPhpVersionsForSiteRuntime(); | ||||||||||||||||||||||||||||||||||
| const recommendedPhpVersion = getRecommendedPhpVersionForSiteRuntime(); | ||||||||||||||||||||||||||||||||||
| return yargs | ||||||||||||||||||||||||||||||||||
| .option( 'id', { | ||||||||||||||||||||||||||||||||||
| type: 'string', | ||||||||||||||||||||||||||||||||||
|
|
@@ -520,8 +540,24 @@ export const registerCommand = ( yargs: StudioArgv ) => { | |||||||||||||||||||||||||||||||||
| .option( 'php', { | ||||||||||||||||||||||||||||||||||
| type: 'string', | ||||||||||||||||||||||||||||||||||
| describe: __( 'PHP version' ), | ||||||||||||||||||||||||||||||||||
| choices: supportedPhpVersions, | ||||||||||||||||||||||||||||||||||
| defaultDescription: recommendedPhpVersion, | ||||||||||||||||||||||||||||||||||
| choices: SupportedPHPVersions, | ||||||||||||||||||||||||||||||||||
| defaultDescription: RecommendedPHPVersion, | ||||||||||||||||||||||||||||||||||
| } ) | ||||||||||||||||||||||||||||||||||
| .option( 'runtime', { | ||||||||||||||||||||||||||||||||||
| type: 'string', | ||||||||||||||||||||||||||||||||||
| describe: __( | ||||||||||||||||||||||||||||||||||
| 'Run the site with native PHP ("native") or in the Playground sandbox ("sandbox")' | ||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||
| choices: [ SITE_MODE_NATIVE, SITE_MODE_SANDBOX ] as const, | ||||||||||||||||||||||||||||||||||
| default: SITE_MODE_NATIVE, | ||||||||||||||||||||||||||||||||||
| } ) | ||||||||||||||||||||||||||||||||||
| .option( 'file-access', { | ||||||||||||||||||||||||||||||||||
| type: 'string', | ||||||||||||||||||||||||||||||||||
| describe: __( | ||||||||||||||||||||||||||||||||||
| 'Which files PHP can access with the native PHP runtime: the site directory only, or all files' | ||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||
| choices: [ SITE_FILE_ACCESS_SITE_DIRECTORY, SITE_FILE_ACCESS_ALL_FILES ] as const, | ||||||||||||||||||||||||||||||||||
| default: SITE_FILE_ACCESS_SITE_DIRECTORY, | ||||||||||||||||||||||||||||||||||
| } ) | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+554
to
561
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Same thing as for |
||||||||||||||||||||||||||||||||||
| .option( 'domain', { | ||||||||||||||||||||||||||||||||||
| type: 'string', | ||||||||||||||||||||||||||||||||||
|
|
@@ -580,8 +616,18 @@ export const registerCommand = ( yargs: StudioArgv ) => { | |||||||||||||||||||||||||||||||||
| let adminUsername = argv.adminUsername; | ||||||||||||||||||||||||||||||||||
| let adminPassword = argv.adminPassword; | ||||||||||||||||||||||||||||||||||
| let adminEmail = argv.adminEmail; | ||||||||||||||||||||||||||||||||||
| const supportedPhpVersions = getSupportedPhpVersionsForSiteRuntime(); | ||||||||||||||||||||||||||||||||||
| const recommendedPhpVersion = getRecommendedPhpVersionForSiteRuntime(); | ||||||||||||||||||||||||||||||||||
| const runtime = siteRuntimeFromMode( argv.runtime ); | ||||||||||||||||||||||||||||||||||
| const fileAccess = argv.fileAccess; | ||||||||||||||||||||||||||||||||||
| if ( ! isFileAccessAllowedForRuntime( runtime, fileAccess ) ) { | ||||||||||||||||||||||||||||||||||
| logger.reportError( | ||||||||||||||||||||||||||||||||||
| new LoggerError( | ||||||||||||||||||||||||||||||||||
| __( | ||||||||||||||||||||||||||||||||||
| 'File access "all-files" requires the native PHP runtime. The sandbox only has access to the site directory.' | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Validate and resolve the WordPress version against available versions before prompting | ||||||||||||||||||||||||||||||||||
| if ( wpVersion && wpVersion !== 'latest' && wpVersion !== 'nightly' ) { | ||||||||||||||||||||||||||||||||||
|
|
@@ -680,11 +726,11 @@ export const registerCommand = ( yargs: StudioArgv ) => { | |||||||||||||||||||||||||||||||||
| if ( ! phpVersion ) { | ||||||||||||||||||||||||||||||||||
| phpVersion = await select( { | ||||||||||||||||||||||||||||||||||
| message: __( 'PHP version:' ), | ||||||||||||||||||||||||||||||||||
| choices: supportedPhpVersions.map( ( v ) => ( { | ||||||||||||||||||||||||||||||||||
| name: v === recommendedPhpVersion ? sprintf( __( '%s (recommended)' ), v ) : v, | ||||||||||||||||||||||||||||||||||
| choices: SupportedPHPVersions.map( ( v ) => ( { | ||||||||||||||||||||||||||||||||||
| name: v === RecommendedPHPVersion ? sprintf( __( '%s (recommended)' ), v ) : v, | ||||||||||||||||||||||||||||||||||
| value: v, | ||||||||||||||||||||||||||||||||||
| } ) ), | ||||||||||||||||||||||||||||||||||
| default: recommendedPhpVersion, | ||||||||||||||||||||||||||||||||||
| default: RecommendedPHPVersion, | ||||||||||||||||||||||||||||||||||
| } ); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
@@ -741,15 +787,14 @@ export const registerCommand = ( yargs: StudioArgv ) => { | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Apply defaults for non-interactive mode when flags weren't provided | ||||||||||||||||||||||||||||||||||
| wpVersion = wpVersion ?? DEFAULT_WORDPRESS_VERSION; | ||||||||||||||||||||||||||||||||||
| const resolvedPhpVersion = validatePhpVersionForSiteRuntime( | ||||||||||||||||||||||||||||||||||
| phpVersion ?? recommendedPhpVersion | ||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const config: CreateCommandOptions = { | ||||||||||||||||||||||||||||||||||
| name: siteName, | ||||||||||||||||||||||||||||||||||
| siteId: argv.id, | ||||||||||||||||||||||||||||||||||
| wpVersion, | ||||||||||||||||||||||||||||||||||
| phpVersion: resolvedPhpVersion, | ||||||||||||||||||||||||||||||||||
| phpVersion: phpVersion ?? RecommendedPHPVersion, | ||||||||||||||||||||||||||||||||||
| runtime, | ||||||||||||||||||||||||||||||||||
| fileAccess, | ||||||||||||||||||||||||||||||||||
| customDomain, | ||||||||||||||||||||||||||||||||||
| enableHttps, | ||||||||||||||||||||||||||||||||||
| adminUsername, | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this behavior is already the intent here, but we aren't actually getting the type guarantees because of a few missing tweaks. We need this and a small tweak in
tools/common/lib/site-runtime.ts– see my comment there