From 0f7f5eb6af1293a4a8fdcb7dd82d3f2d27da1add Mon Sep 17 00:00:00 2001 From: Volodymyr Kolesnykov Date: Wed, 9 Aug 2023 19:22:03 +0300 Subject: [PATCH 1/5] feat(dev-env): add PHP 8.3 image --- .../dev-environment/dev-environment-cli.js | 8 +++--- src/bin/vip-dev-env-update.js | 4 ++- src/lib/constants/dev-environment.ts | 25 +++++++++++++++---- .../dev-environment/dev-environment-cli.ts | 22 +++++++++------- .../dev-environment/dev-environment-core.ts | 4 +++ 5 files changed, 44 insertions(+), 19 deletions(-) diff --git a/__tests__/lib/dev-environment/dev-environment-cli.js b/__tests__/lib/dev-environment/dev-environment-cli.js index e6779a916..1a29f019a 100644 --- a/__tests__/lib/dev-environment/dev-environment-cli.js +++ b/__tests__/lib/dev-environment/dev-environment-cli.js @@ -584,10 +584,10 @@ describe( 'lib/dev-environment/dev-environment-cli', () => { describe( 'resolvePhpVersion', () => { it.each( [ - [ '7.4', DEV_ENVIRONMENT_PHP_VERSIONS[ '7.4' ] ], - [ '8.0', DEV_ENVIRONMENT_PHP_VERSIONS[ '8.0' ] ], - [ '8.1', DEV_ENVIRONMENT_PHP_VERSIONS[ '8.1' ] ], - [ '8.2', DEV_ENVIRONMENT_PHP_VERSIONS[ '8.2' ] ], + [ '7.4', DEV_ENVIRONMENT_PHP_VERSIONS[ '7.4' ].image ], + [ '8.0', DEV_ENVIRONMENT_PHP_VERSIONS[ '8.0' ].image ], + [ '8.1', DEV_ENVIRONMENT_PHP_VERSIONS[ '8.1' ].image ], + [ '8.2', DEV_ENVIRONMENT_PHP_VERSIONS[ '8.2' ].image ], [ 'image:php:8.0', 'image:php:8.0' ], [ 'ghcr.io/automattic/vip-container-images/php-fpm-ubuntu:8.0', diff --git a/src/bin/vip-dev-env-update.js b/src/bin/vip-dev-env-update.js index b60e43879..4e218f6f4 100755 --- a/src/bin/vip-dev-env-update.js +++ b/src/bin/vip-dev-env-update.js @@ -85,7 +85,9 @@ cmd.argv( process.argv, async ( arg, opt ) => { muPlugins: currentInstanceData.muPlugins.dir || currentInstanceData.muPlugins.tag || 'latest', wordpress: currentInstanceData.wordpress.tag || 'trunk', elasticsearch: currentInstanceData.elasticsearch, - php: currentInstanceData.php || DEV_ENVIRONMENT_PHP_VERSIONS.default, + php: + currentInstanceData.php || + DEV_ENVIRONMENT_PHP_VERSIONS[ Object.keys( DEV_ENVIRONMENT_PHP_VERSIONS )[ 0 ] ].image, mariadb: currentInstanceData.mariadb, phpmyadmin: currentInstanceData.phpmyadmin, xdebug: currentInstanceData.xdebug, diff --git a/src/lib/constants/dev-environment.ts b/src/lib/constants/dev-environment.ts index 02534f07a..13968eefd 100644 --- a/src/lib/constants/dev-environment.ts +++ b/src/lib/constants/dev-environment.ts @@ -28,11 +28,26 @@ export const DEV_ENVIRONMENT_WORDPRESS_CACHE_KEY = 'wordpress-versions.json'; export const DEV_ENVIRONMENT_WORDPRESS_VERSION_TTL = 86400; // once per day -export const DEV_ENVIRONMENT_PHP_VERSIONS: Record< string, string | undefined > = { - '8.0': 'ghcr.io/automattic/vip-container-images/php-fpm:8.0', - 8.2: 'ghcr.io/automattic/vip-container-images/php-fpm:8.2', - 8.1: 'ghcr.io/automattic/vip-container-images/php-fpm:8.1', - 7.4: 'ghcr.io/automattic/vip-container-images/php-fpm:7.4', +interface PhpImage { + image: string; + label: string; +} + +export const DEV_ENVIRONMENT_PHP_VERSIONS: Record< string, PhpImage > = { + '8.0': { + image: 'ghcr.io/automattic/vip-container-images/php-fpm:8.0', + label: '8.0 (recommended)', + }, + 8.2: { + image: 'ghcr.io/automattic/vip-container-images/php-fpm:8.2', + label: '8.2 (experimental)', + }, + 8.1: { image: 'ghcr.io/automattic/vip-container-images/php-fpm:8.1', label: '8.1' }, + 7.4: { image: 'ghcr.io/automattic/vip-container-images/php-fpm:7.4', label: '7.4 (outdated)' }, + 8.3: { + image: 'ghcr.io/automattic/vip-container-images/php-fpm:8.3', + label: '8.3 (experimental, not officially supported)', + }, } as const; export const DEV_ENVIRONMENT_VERSION = '2.0.0'; diff --git a/src/lib/dev-environment/dev-environment-cli.ts b/src/lib/dev-environment/dev-environment-cli.ts index ca02475ca..f456a91dc 100644 --- a/src/lib/dev-environment/dev-environment-cli.ts +++ b/src/lib/dev-environment/dev-environment-cli.ts @@ -665,11 +665,11 @@ export function resolvePhpVersion( version: string ): string { } let result: string; - if ( DEV_ENVIRONMENT_PHP_VERSIONS[ version ] === undefined ) { - const images = Object.values( DEV_ENVIRONMENT_PHP_VERSIONS ) as string[]; - const image = images.find( value => value === version ); + if ( ! ( version in DEV_ENVIRONMENT_PHP_VERSIONS ) ) { + const images = Object.values( DEV_ENVIRONMENT_PHP_VERSIONS ); + const image = images.find( value => value.image === version ); if ( image ) { - result = image; + result = image.image; } else if ( version.includes( '/' ) ) { // Assuming this is a Docker image // This can happen when we first called `vip dev-env update -P image:ghcr.io/...` @@ -677,10 +677,10 @@ export function resolvePhpVersion( version: string ): string { // but we still want to use it. result = version; } else { - result = images[ 0 ]; + result = images[ 0 ].image; } } else { - result = DEV_ENVIRONMENT_PHP_VERSIONS[ version ] as string; + result = DEV_ENVIRONMENT_PHP_VERSIONS[ version ].image; } debug( 'Resolved PHP image: %j', result ); @@ -692,11 +692,15 @@ export async function promptForPhpVersion( initialValue: string ): Promise< stri let answer = initialValue; if ( isStdinTTY ) { - const choices = Object.keys( DEV_ENVIRONMENT_PHP_VERSIONS ); + const choices = []; + Object.keys( DEV_ENVIRONMENT_PHP_VERSIONS ).forEach( version => { + const phpImage = DEV_ENVIRONMENT_PHP_VERSIONS[ version ]; + choices.push( { message: phpImage.label, value: version } ); + } ); const images = Object.values( DEV_ENVIRONMENT_PHP_VERSIONS ); - let initial = images.findIndex( version => version === initialValue ); + let initial = images.findIndex( version => version.image === initialValue ); if ( initial === -1 ) { - choices.push( initialValue ); + choices.push( { message: initialValue, value: initialValue } ); initial = choices.length - 1; } diff --git a/src/lib/dev-environment/dev-environment-core.ts b/src/lib/dev-environment/dev-environment-core.ts index 419d890e3..5c0c787a5 100644 --- a/src/lib/dev-environment/dev-environment-core.ts +++ b/src/lib/dev-environment/dev-environment-core.ts @@ -192,7 +192,11 @@ function preProcessInstanceData( instanceData: InstanceData ): InstanceData { newInstanceData.php = instanceData.php || +<<<<<<< HEAD ( DEV_ENVIRONMENT_PHP_VERSIONS[ Object.keys( DEV_ENVIRONMENT_PHP_VERSIONS )[ 0 ] ] as string ); +======= + DEV_ENVIRONMENT_PHP_VERSIONS[ Object.keys( DEV_ENVIRONMENT_PHP_VERSIONS )[ 0 ] ].image; +>>>>>>> 5d41aa3a (feat(dev-env): add PHP 8.3 image) if ( newInstanceData.php.startsWith( 'image:' ) ) { newInstanceData.php = newInstanceData.php.slice( 'image:'.length ); } From 6268cbee41bbc99d31c0eb95179b41393ae93785 Mon Sep 17 00:00:00 2001 From: Volodymyr Kolesnykov Date: Fri, 8 Sep 2023 22:42:08 +0300 Subject: [PATCH 2/5] Update src/lib/constants/dev-environment.ts Co-authored-by: Mohammad Jangda --- src/lib/constants/dev-environment.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lib/constants/dev-environment.ts b/src/lib/constants/dev-environment.ts index 13968eefd..a4c0d4cdb 100644 --- a/src/lib/constants/dev-environment.ts +++ b/src/lib/constants/dev-environment.ts @@ -34,20 +34,20 @@ interface PhpImage { } export const DEV_ENVIRONMENT_PHP_VERSIONS: Record< string, PhpImage > = { - '8.0': { - image: 'ghcr.io/automattic/vip-container-images/php-fpm:8.0', - label: '8.0 (recommended)', - }, + 8.1: { image: 'ghcr.io/automattic/vip-container-images/php-fpm:8.1', label: '8.1 (recommended)' }, 8.2: { image: 'ghcr.io/automattic/vip-container-images/php-fpm:8.2', label: '8.2 (experimental)', }, - 8.1: { image: 'ghcr.io/automattic/vip-container-images/php-fpm:8.1', label: '8.1' }, - 7.4: { image: 'ghcr.io/automattic/vip-container-images/php-fpm:7.4', label: '7.4 (outdated)' }, 8.3: { image: 'ghcr.io/automattic/vip-container-images/php-fpm:8.3', - label: '8.3 (experimental, not officially supported)', + label: '8.3 (experimental, not supported)', + }, + '8.0': { + image: 'ghcr.io/automattic/vip-container-images/php-fpm:8.0', + label: '8.0 (EOL soon)', }, + 7.4: { image: 'ghcr.io/automattic/vip-container-images/php-fpm:7.4', label: '7.4 (EOL; not supported)' }, } as const; export const DEV_ENVIRONMENT_VERSION = '2.0.0'; From 2113763b8816f6a28f0b40fcf4367558b5bb953d Mon Sep 17 00:00:00 2001 From: Volodymyr Kolesnykov Date: Mon, 11 Sep 2023 11:58:17 +0300 Subject: [PATCH 3/5] style: fix eslint issues --- src/lib/constants/dev-environment.ts | 5 ++++- src/lib/dev-environment/dev-environment-core.ts | 4 ---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/lib/constants/dev-environment.ts b/src/lib/constants/dev-environment.ts index a4c0d4cdb..a7d5d1e6d 100644 --- a/src/lib/constants/dev-environment.ts +++ b/src/lib/constants/dev-environment.ts @@ -47,7 +47,10 @@ export const DEV_ENVIRONMENT_PHP_VERSIONS: Record< string, PhpImage > = { image: 'ghcr.io/automattic/vip-container-images/php-fpm:8.0', label: '8.0 (EOL soon)', }, - 7.4: { image: 'ghcr.io/automattic/vip-container-images/php-fpm:7.4', label: '7.4 (EOL; not supported)' }, + 7.4: { + image: 'ghcr.io/automattic/vip-container-images/php-fpm:7.4', + label: '7.4 (EOL; not supported)', + }, } as const; export const DEV_ENVIRONMENT_VERSION = '2.0.0'; diff --git a/src/lib/dev-environment/dev-environment-core.ts b/src/lib/dev-environment/dev-environment-core.ts index 5c0c787a5..40ba7cdb0 100644 --- a/src/lib/dev-environment/dev-environment-core.ts +++ b/src/lib/dev-environment/dev-environment-core.ts @@ -192,11 +192,7 @@ function preProcessInstanceData( instanceData: InstanceData ): InstanceData { newInstanceData.php = instanceData.php || -<<<<<<< HEAD - ( DEV_ENVIRONMENT_PHP_VERSIONS[ Object.keys( DEV_ENVIRONMENT_PHP_VERSIONS )[ 0 ] ] as string ); -======= DEV_ENVIRONMENT_PHP_VERSIONS[ Object.keys( DEV_ENVIRONMENT_PHP_VERSIONS )[ 0 ] ].image; ->>>>>>> 5d41aa3a (feat(dev-env): add PHP 8.3 image) if ( newInstanceData.php.startsWith( 'image:' ) ) { newInstanceData.php = newInstanceData.php.slice( 'image:'.length ); } From 1d5ea625d806154ba53ba132dee398f28be45756 Mon Sep 17 00:00:00 2001 From: Volodymyr Kolesnykov Date: Fri, 20 Oct 2023 14:55:19 +0300 Subject: [PATCH 4/5] Address code review comments --- src/lib/constants/dev-environment.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/constants/dev-environment.ts b/src/lib/constants/dev-environment.ts index a7d5d1e6d..ac79c10aa 100644 --- a/src/lib/constants/dev-environment.ts +++ b/src/lib/constants/dev-environment.ts @@ -34,11 +34,11 @@ interface PhpImage { } export const DEV_ENVIRONMENT_PHP_VERSIONS: Record< string, PhpImage > = { - 8.1: { image: 'ghcr.io/automattic/vip-container-images/php-fpm:8.1', label: '8.1 (recommended)' }, 8.2: { image: 'ghcr.io/automattic/vip-container-images/php-fpm:8.2', - label: '8.2 (experimental)', + label: '8.2 (recommended)', }, + 8.1: { image: 'ghcr.io/automattic/vip-container-images/php-fpm:8.1', label: '8.1' }, 8.3: { image: 'ghcr.io/automattic/vip-container-images/php-fpm:8.3', label: '8.3 (experimental, not supported)', From ddfabd9def4f06ea5e4ef7dc274f2af12681a7fb Mon Sep 17 00:00:00 2001 From: Volodymyr Kolesnykov Date: Mon, 6 Nov 2023 10:29:09 +0200 Subject: [PATCH 5/5] test: address code review comments --- __tests__/lib/dev-environment/dev-environment-cli.js | 1 + 1 file changed, 1 insertion(+) diff --git a/__tests__/lib/dev-environment/dev-environment-cli.js b/__tests__/lib/dev-environment/dev-environment-cli.js index 1a29f019a..e28a94dbd 100644 --- a/__tests__/lib/dev-environment/dev-environment-cli.js +++ b/__tests__/lib/dev-environment/dev-environment-cli.js @@ -588,6 +588,7 @@ describe( 'lib/dev-environment/dev-environment-cli', () => { [ '8.0', DEV_ENVIRONMENT_PHP_VERSIONS[ '8.0' ].image ], [ '8.1', DEV_ENVIRONMENT_PHP_VERSIONS[ '8.1' ].image ], [ '8.2', DEV_ENVIRONMENT_PHP_VERSIONS[ '8.2' ].image ], + [ '8.3', DEV_ENVIRONMENT_PHP_VERSIONS[ '8.3' ].image ], [ 'image:php:8.0', 'image:php:8.0' ], [ 'ghcr.io/automattic/vip-container-images/php-fpm-ubuntu:8.0',