@puls-atlas/cli
Version:
The Puls Atlas CLI tool for managing Atlas projects
66 lines • 3.31 kB
JavaScript
import { isPlainObject } from 'es-toolkit/compat';
import { normalizeOptionalString } from '../../utils/value.js';
import { SYNC_BACKFILL_JOB_NAME, SYNC_SERVICE_NAME } from './resourceNames.js';
import { resolveSyncMapperManifestUri, resolveSyncRuntimeConfigUri } from './artifactBucket.js';
import { DEFAULT_SYNC_CLOUD_RUN_ARTIFACT_REGISTRY_LOCATION, DEFAULT_SYNC_CLOUD_RUN_ARTIFACT_REGISTRY_PROJECT, DEFAULT_SYNC_CLOUD_RUN_REGION, DEFAULT_SYNC_CLOUD_RUN_REPOSITORY } from './config/syncConfig.js';
const DEFAULT_SYNC_RUNTIME_IMAGE_TAG = 'latest';
const DEFAULT_SYNC_CLOUD_RUN_VPC_EGRESS = 'private-ranges-only';
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_SYNC_CLOUD_RUN_VPC_EGRESS,
network,
subnetwork
};
};
const resolveSyncRuntimeImage = (imageName, options = {}) => {
const {
artifactRegistryProject = DEFAULT_SYNC_CLOUD_RUN_ARTIFACT_REGISTRY_PROJECT,
artifactRegistryLocation = DEFAULT_SYNC_CLOUD_RUN_ARTIFACT_REGISTRY_LOCATION,
repository = DEFAULT_SYNC_CLOUD_RUN_REPOSITORY,
tag = DEFAULT_SYNC_RUNTIME_IMAGE_TAG
} = options;
return `${artifactRegistryLocation}-docker.pkg.dev/${artifactRegistryProject}/${repository}/${imageName}:${tag}`;
};
export const resolveSyncCloudRunDeployConfig = context => {
const cloudRunConfig = getCloudRunDeployConfig(context.config);
const artifactRegistryProject = cloudRunConfig.artifactRegistryProject ?? DEFAULT_SYNC_CLOUD_RUN_ARTIFACT_REGISTRY_PROJECT;
const artifactRegistryLocation = cloudRunConfig.artifactRegistryLocation ?? DEFAULT_SYNC_CLOUD_RUN_ARTIFACT_REGISTRY_LOCATION;
const mapperManifestUri = resolveSyncMapperManifestUri(context.projectId, context.config);
const runtimeConfigUri = resolveSyncRuntimeConfigUri(context.projectId, context.config);
const repository = cloudRunConfig.repository ?? DEFAULT_SYNC_CLOUD_RUN_REPOSITORY;
const region = normalizeOptionalString(cloudRunConfig.region) ?? DEFAULT_SYNC_CLOUD_RUN_REGION;
const serviceAccountEmail = normalizeOptionalString(cloudRunConfig.serviceAccountEmail) ?? `${context.projectId}@appspot.gserviceaccount.com`;
const tag = cloudRunConfig.tag ?? DEFAULT_SYNC_RUNTIME_IMAGE_TAG;
const vpcAccess = normalizeCloudRunVpcAccessConfig(cloudRunConfig);
const imageOptions = {
artifactRegistryProject,
artifactRegistryLocation,
repository,
tag
};
return {
artifactRegistryLocation,
artifactRegistryProject,
backfillJobImage: normalizeOptionalString(cloudRunConfig.backfillJobImage) ?? resolveSyncRuntimeImage(SYNC_BACKFILL_JOB_NAME, imageOptions),
mapperManifestUri,
region,
repository,
runtimeConfigUri,
serviceAccountEmail,
serviceImage: normalizeOptionalString(cloudRunConfig.serviceImage) ?? resolveSyncRuntimeImage(SYNC_SERVICE_NAME, imageOptions),
tag,
vpcAccess
};
};
export default {
resolveSyncCloudRunDeployConfig
};