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): automatically enable Elasticsearch when Enterprise Search integration is enabled #2206

Merged
merged 1 commit into from
Jan 29, 2025
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
2 changes: 1 addition & 1 deletion src/bin/vip-dev-env-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ cmd.argv( process.argv, async ( arg, opt ) => {

/** @type {import('../lib/dev-environment/types').InstanceOptions} */
let defaultOptions = {};
/** @type {Record<string,unknown>} */
/** @type {Record<string,import('../lib/dev-environment/types').IntegrationConfig>} */
let integrationsConfig = {};

try {
Expand Down
4 changes: 4 additions & 0 deletions src/lib/dev-environment/dev-environment-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,17 @@ export function processComponentOptionInput(
}

export function getOptionsFromAppInfo( appInfo: AppInfo ): InstanceOptions {
const integrationsConfig = appInfo.environment?.integrations ?? {};
const hasES = integrationsConfig[ 'enterprise-search' ]?.env?.status === 'enabled';

return {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
title: appInfo.environment?.name || appInfo.name || '', // NOSONAR
multisite: Boolean( appInfo.environment?.isMultisite ),
mediaRedirectDomain: appInfo.environment?.primaryDomain,
php: appInfo.environment?.php ?? '',
wordpress: appInfo.environment?.wordpress ?? '',
elasticsearch: hasES,
};
}

Expand Down
15 changes: 12 additions & 3 deletions src/lib/dev-environment/dev-environment-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ import { createProxyAgent } from '../http/proxy-agent';
import { searchAndReplace } from '../search-and-replace';
import UserError from '../user-error';

import type { AppInfo, ComponentConfig, InstanceData, WordPressConfig } from './types';
import type {
AppInfo,
ComponentConfig,
InstanceData,
IntegrationConfig,
WordPressConfig,
} from './types';
import type Lando from 'lando';

const debug = debugLib( '@automattic/vip:bin:dev-environment' );
Expand Down Expand Up @@ -151,9 +157,10 @@ export async function stopEnvironment( lando: Lando, slug: string ): Promise< vo
export async function createEnvironment(
lando: Lando,
instanceData: InstanceData,
integrationsConfig?: Record< string, unknown > | undefined
integrationsConfig?: Record< string, IntegrationConfig > | undefined
): Promise< void > {
const slug = instanceData.siteSlug;
integrationsConfig ??= {};
debug( 'Will process an environment', slug, 'with instanceData for creation: ', instanceData );

const instancePath = getEnvironmentPath( slug );
Expand All @@ -167,6 +174,7 @@ export async function createEnvironment(
}

const preProcessedInstanceData = preProcessInstanceData( instanceData );

debug( 'Will create an environment', slug, 'with instanceData: ', preProcessedInstanceData );

await prepareLandoEnv( lando, preProcessedInstanceData, instancePath, integrationsConfig );
Expand Down Expand Up @@ -682,7 +690,8 @@ export async function getApplicationInformation(
php: envData.softwareSettings?.php?.current.version ?? '',
wordpress: envData.softwareSettings?.wordpress?.current.version ?? '',
integrations:
( envData.getIntegrationsDevEnvConfig?.data as Record< string, unknown > ) ?? {},
( envData.getIntegrationsDevEnvConfig?.data as Record< string, IntegrationConfig > ) ??
{},
};
}
}
Expand Down
14 changes: 13 additions & 1 deletion src/lib/dev-environment/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ export interface InstanceOptions {
[ index: string ]: unknown;
}

export interface IntergrationSettings {
status: string;
config?: Record< string, unknown >;
}

export interface IntegrationConfig {
type?: string;
org?: IntergrationSettings;
env?: IntergrationSettings;
network_sites?: IntergrationSettings;
}

export interface AppInfo {
id?: number | null;
name?: string | null;
Expand All @@ -32,7 +44,7 @@ export interface AppInfo {
primaryDomain: string;
php: string;
wordpress: string;
integrations: Record< string, unknown >;
integrations: Record< string, IntegrationConfig >;
};
}

Expand Down