@puls-atlas/cli
Version:
The Puls Atlas CLI tool for managing Atlas projects
93 lines • 4.89 kB
JavaScript
import { isPlainObject } from 'es-toolkit/compat';
import { resolveSearchMapperManifestUri, resolveSearchRuntimeConfigUri } from './artifactBucket.js';
import { resolveSearchCloudRunServiceAccountEmail } from './config/searchConfig.js';
import { resolveAtlasPlatformRegion } from '../../utils/index.js';
import { ATLAS_SEARCH_TASK_QUEUE_NAME } from '../../utils/taskQueue.js';
import { normalizeOptionalString, spreadIf } from '../../utils/value.js';
import { hasScheduledSearchSources } from './sources/scheduled.js';
const DEFAULT_SEARCH_ARTIFACT_REGISTRY_PROJECT = 'puls-atlas-core';
const DEFAULT_SEARCH_ARTIFACT_REGISTRY_LOCATION = 'europe-west1';
const DEFAULT_SEARCH_ARTIFACT_REGISTRY_REPOSITORY = 'atlas-runtime-containers';
const DEFAULT_SEARCH_RUNTIME_IMAGE_TAG = 'latest';
const DEFAULT_SEARCH_CLOUD_RUN_VPC_EGRESS = 'private-ranges-only';
const SEARCH_RUNTIME_IMAGE_NAMES = {
backfillJob: 'puls-atlas-search-backfill',
sourceRunnerJob: 'puls-atlas-search-source-runner',
searchApiService: 'puls-atlas-search-api',
searchSyncService: 'puls-atlas-search-sync'
};
export const SHARED_REQUEST_AUTH_SECRET = 'puls-gcr-auth-token';
const getCloudRunDeployConfig = config => config.deploy?.cloudRun ?? {};
const normalizeCloudRunVpcAccessConfig = cloudRunConfig => {
if (!cloudRunConfig?.vpcAccess || !isPlainObject(cloudRunConfig.vpcAccess)) {
return null;
}
const network = normalizeOptionalString(cloudRunConfig.vpcAccess.network);
const subnetwork = normalizeOptionalString(cloudRunConfig.vpcAccess.subnetwork);
if (!network) {
return null;
}
return {
egress: cloudRunConfig.vpcAccess.egress ?? DEFAULT_SEARCH_CLOUD_RUN_VPC_EGRESS,
network,
subnetwork
};
};
const resolveSearchConfigTransport = cloudRunConfig => {
const configuredTransport = normalizeOptionalString(cloudRunConfig.searchConfigTransport);
if (!configuredTransport || configuredTransport === 'artifact') {
return 'artifact';
}
throw new Error('Atlas search inline runtime config transport is no longer supported. ' + 'Remove deploy.cloudRun.searchConfigTransport or set it to "artifact".');
};
const resolveSearchRuntimeImage = (imageName, options = {}) => {
const {
artifactRegistryProject = DEFAULT_SEARCH_ARTIFACT_REGISTRY_PROJECT,
artifactRegistryLocation = DEFAULT_SEARCH_ARTIFACT_REGISTRY_LOCATION,
repository = DEFAULT_SEARCH_ARTIFACT_REGISTRY_REPOSITORY,
tag = DEFAULT_SEARCH_RUNTIME_IMAGE_TAG
} = options;
return `${artifactRegistryLocation}-docker.pkg.dev/${artifactRegistryProject}/${repository}/${imageName}:${tag}`;
};
export const resolveSearchCloudRunDeployConfig = context => {
const cloudRunConfig = getCloudRunDeployConfig(context.config);
const artifactRegistryProject = cloudRunConfig.artifactRegistryProject ?? DEFAULT_SEARCH_ARTIFACT_REGISTRY_PROJECT;
const artifactRegistryLocation = cloudRunConfig.artifactRegistryLocation ?? DEFAULT_SEARCH_ARTIFACT_REGISTRY_LOCATION;
const mapperManifestUri = resolveSearchMapperManifestUri(context);
const runtimeConfigUri = resolveSearchRuntimeConfigUri(context);
const repository = cloudRunConfig.repository ?? DEFAULT_SEARCH_ARTIFACT_REGISTRY_REPOSITORY;
const region = resolveAtlasPlatformRegion(context.config);
const searchConfigTransport = resolveSearchConfigTransport(cloudRunConfig);
const scheduledSourcesEnabled = hasScheduledSearchSources(context.config);
const serviceAccountEmail = resolveSearchCloudRunServiceAccountEmail(context.config, context.projectId);
const tag = cloudRunConfig.tag ?? DEFAULT_SEARCH_RUNTIME_IMAGE_TAG;
const vpcAccess = normalizeCloudRunVpcAccessConfig(cloudRunConfig);
const imageOptions = {
artifactRegistryProject,
artifactRegistryLocation,
repository,
tag
};
return {
artifactRegistryLocation,
artifactRegistryProject,
jobImage: cloudRunConfig.jobImage ?? resolveSearchRuntimeImage(SEARCH_RUNTIME_IMAGE_NAMES.backfillJob, imageOptions),
mapperManifestUri,
region,
repository,
runtimeConfigUri,
searchConfigTransport,
serviceAccountEmail,
serviceImage: cloudRunConfig.serviceImage ?? resolveSearchRuntimeImage(SEARCH_RUNTIME_IMAGE_NAMES.searchApiService, imageOptions),
...spreadIf(scheduledSourcesEnabled, {
sourceRunnerJobImage: cloudRunConfig.sourceRunnerJobImage ?? resolveSearchRuntimeImage(SEARCH_RUNTIME_IMAGE_NAMES.sourceRunnerJob, imageOptions)
}),
syncServiceImage: cloudRunConfig.syncServiceImage ?? resolveSearchRuntimeImage(SEARCH_RUNTIME_IMAGE_NAMES.searchSyncService, imageOptions),
tag,
vpcAccess
};
};
export const resolveSearchTaskQueueConfig = context => ({
location: normalizeOptionalString(context?.config?.deploy?.taskQueue?.region) ?? resolveSearchCloudRunDeployConfig(context).region,
name: normalizeOptionalString(context?.config?.deploy?.taskQueue?.name) ?? ATLAS_SEARCH_TASK_QUEUE_NAME
});