Skip to content

Commit

Permalink
feat(dev-env): automatically enable Elasticsearch when Enterprise Sea…
Browse files Browse the repository at this point in the history
…rch integration is enabled
  • Loading branch information
sjinks committed Jan 29, 2025
1 parent 8e14bb3 commit 9f29b2d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
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

0 comments on commit 9f29b2d

Please sign in to comment.