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

feat(dev-env): add PHP 8.3 image #1485

Merged
merged 5 commits into from
Nov 6, 2023
Merged
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
9 changes: 5 additions & 4 deletions __tests__/lib/dev-environment/dev-environment-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,10 +584,11 @@ 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 ],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add 8.3 to the test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

[ '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',
Expand Down
4 changes: 3 additions & 1 deletion src/bin/vip-dev-env-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 23 additions & 5 deletions src/lib/constants/dev-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,29 @@ 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.2: {
image: 'ghcr.io/automattic/vip-container-images/php-fpm:8.2',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should mark 8.2 as recommended at this point now given that we're moving towards everyone being on it now, yeah?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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)',
},
'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';
22 changes: 13 additions & 9 deletions src/lib/dev-environment/dev-environment-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,22 +665,22 @@ 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/...`
// and then called `vip dev-env update` again. The custom image won't match our images
// 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 );
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/dev-environment/dev-environment-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ function preProcessInstanceData( instanceData: InstanceData ): InstanceData {

newInstanceData.php =
instanceData.php ||
( 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;
if ( newInstanceData.php.startsWith( 'image:' ) ) {
newInstanceData.php = newInstanceData.php.slice( 'image:'.length );
}
Expand Down