diff --git a/packages/gcp-cloud-run/src/executors/deploy/deploy.impl.ts b/packages/gcp-cloud-run/src/executors/deploy/deploy.impl.ts index 9a337c53..419a5140 100644 --- a/packages/gcp-cloud-run/src/executors/deploy/deploy.impl.ts +++ b/packages/gcp-cloud-run/src/executors/deploy/deploy.impl.ts @@ -1,4 +1,4 @@ -import { ExecutorContext, readJsonFile } from '@nx/devkit' +import { ExecutorContext, logger, readJsonFile } from '@nx/devkit' import { buildCommand, execCommand, getOutputDirectoryFromBuildTarget } from '@nx-extend/core' import { existsSync, readFileSync, writeFileSync } from 'fs' import { join } from 'path' @@ -23,7 +23,6 @@ export interface ExecutorSchema extends ContainerFlags { tagWithVersion?: string revisionSuffix?: string buildWith?: 'artifact-registry' - autoCreateArtifactsRepo?: boolean noTraffic?: boolean timeout?: number cpuBoost?: boolean @@ -32,6 +31,10 @@ export interface ExecutorSchema extends ContainerFlags { vpcConnector?: string vpcEgress?: 'all-traffic' | 'private-ranges-only' + // VOLUME_NAME,type=cloud-storage,bucket=BUCKET_NAME + // VOLUME_NAME,type=in-memory,size=SIZE_LIMIT + volumeName?: string + sidecars?: ContainerFlags[] } @@ -66,11 +69,12 @@ export async function deployExecutor( vpcEgress, revisionSuffix = false, - autoCreateArtifactsRepo = true, timeout, cpuBoost, ingress, + // VOLUME_NAME,type=VOLUME_TYPE,size=SIZE_LIMIT' + volumeName, sidecars = [] } = options @@ -102,8 +106,15 @@ export async function deployExecutor( } } + let gcloudDeploy = 'gcloud run deploy' + if (options.volumeName) { + logger.warn('Volumes are still in beta, using "gcloud beta" to deploy.\n') + + gcloudDeploy = 'gcloud beta run deploy' + } + const deployCommand = buildCommand([ - `gcloud run deploy ${name}`, + `${gcloudDeploy} ${name}`, `--project=${project}`, '--platform=managed', `--region=${region}`, @@ -123,6 +134,7 @@ export async function deployExecutor( typeof cpuBoost === 'boolean' && !cpuBoost && '--no-cpu-boost', noTraffic && '--no-traffic', allowUnauthenticated && '--allow-unauthenticated', + volumeName && `--add-volume=name=${volumeName}`, // Add the primary container ...getContainerFlags(options, sidecars.length > 0), @@ -130,8 +142,7 @@ export async function deployExecutor( // Add all sidecars ...sidecars.flatMap((sidecarOptions) => getContainerFlags(sidecarOptions, true)), - // There can be a question if a repo should be created - autoCreateArtifactsRepo && '--quiet' + '--quiet' ]) return execCommand(deployCommand, { diff --git a/packages/gcp-cloud-run/src/executors/deploy/schema.json b/packages/gcp-cloud-run/src/executors/deploy/schema.json index d19a92f6..9d88b0f3 100644 --- a/packages/gcp-cloud-run/src/executors/deploy/schema.json +++ b/packages/gcp-cloud-run/src/executors/deploy/schema.json @@ -54,6 +54,14 @@ "internal", "internal-and-cloud-load-balancing" ] + }, + "volumeName": { + "type": "string", + "description": "Should be in format 'VOLUME_NAME,type=VOLUME_TYPE,'" + }, + "volumeMount": { + "type": "string", + "description": "Should be in format 'VOLUME_NAME,mount-path=MOUNT_PATH'" } } } diff --git a/packages/gcp-cloud-run/src/executors/deploy/utils/get-container-flags.ts b/packages/gcp-cloud-run/src/executors/deploy/utils/get-container-flags.ts index 543ddbfb..f3eafac7 100644 --- a/packages/gcp-cloud-run/src/executors/deploy/utils/get-container-flags.ts +++ b/packages/gcp-cloud-run/src/executors/deploy/utils/get-container-flags.ts @@ -29,14 +29,15 @@ export interface ContainerFlags { // removeLabels?: string[] // List of label keys to remove. labels?: string[] // List of label KEY=VALUE pairs to add. // updateLabels?: Record // List of label KEY=VALUE pairs to update. + volumeMount?: string // VOLUME_NAME,mount-path=MOUNT_PATH } export function getContainerFlags(options: ContainerFlags, containerRequired: boolean): string[] { if (containerRequired && !options.container) { - throw new Error('Option "container" is not set!') + throw new Error('Option "container" is not set! This is required when using sidecars.') } - const setEnvVars = Object.keys(options.envVars).reduce((env, envVar) => { + const setEnvVars = Object.keys(options.envVars || {}).reduce((env, envVar) => { env.push(`${envVar}=${options.envVars[envVar]}`) return env @@ -76,7 +77,8 @@ export function getContainerFlags(options: ContainerFlags, containerRequired: bo // options.clearSecrets && `--clear-secrets=${options.clearSecrets}`, // options.clearLabels && `--clear-labels=${options.clearLabels}`, // options.removeLabels && `--remove-labels=${options.removeLabels}`, - options.labels && `--clear-labels --labels=${options.labels.join(',')}` - // options.updateLabels && `--update-labels=${options.updateLabels}` + options.labels && `--clear-labels --labels=${options.labels.join(',')}`, + // options.updateLabels && `--update-labels=${options.updateLabels}`, + options.volumeMount && `--add-volume-mount=volume=${options.volumeMount}`, ] }