Deployment Configuration

This document describes the deployment configuration for dart_cloud_cli.

Configuration Overview

All deployment restrictions and validation rules are centralized in lib/config/deployment_config.dart.

Size Limits

LimitValueDescription
Maximum size5 MBFunctions exceeding this cannot be deployed
Warning threshold4 MBFunctions between 4-5 MB trigger a warning

Reducing Function Size

If your function exceeds 5 MB:

1. Remove unnecessary directories:

bash
rm -rf .git .dart_tool build node_modules

2. Use .gitignore to exclude files:

.dart_tool/
build/
.git/
node_modules/

3. Minimize dependencies:

  • Only include required packages in pubspec.yaml
  • Use dart pub get to install only production dependencies

4. Remove build artifacts:

bash
dart pub get
dart pub upgrade

Forbidden Directories

The following directories cannot be deployed:

DirectoryReason
.gitVersion control
.githubGitHub workflows
.vscodeVS Code settings
.ideaIntelliJ settings
node_modulesNode.js dependencies
.dart_toolDart build artifacts
buildBuild output
.gradleGradle build files
.cocoapodsCocoaPods files

Why? These directories:

  • Contain unnecessary files that increase size
  • May contain sensitive information
  • Are not needed for function execution

Forbidden Files

Exact Matches

FileReason
.envEnvironment variables
.env.localLocal environment overrides
secrets.jsonSecrets configuration
credentials.jsonCredentials file

Patterns

PatternReason
*.pemPrivate keys (PEM format)
*.keyPrivate keys
*.p12PKCS12 certificates
*.pfxPKCS12 certificates
.env.*.localEnvironment overrides

Why? These files:

  • Contain sensitive credentials
  • Should never be committed to version control
  • Could expose secrets if deployed

Required Files

FilePurpose
pubspec.yamlDart package manifest

Required Entry Points

One of the following must exist:

FileDescription
main.dartFunction entry point in root
bin/main.dart Function entry point in bin directory

Security Configuration

Forbidden Imports

ImportReason
dart:mirrorsReflection
dart:ffiForeign Function Interface

Dangerous Operations

OperationDescription
Process.run()Execute processes
Process.start()Start processes
Process.runSync()Synchronous process execution

Dangerous Patterns

PatternDescription
ShellShell execution
bashBash execution
Platform.executablePlatform executable access
Platform.scriptPlatform script access
SocketRaw socket operations
ServerSocketServer socket operations

Deployment Validation Flow

Flow
1. Check function size
   ├─ If > 5 MB → ERROR
   └─ If 4-5 MB → WARNING

2. Check for forbidden directories
   └─ If found → ERROR

3. Check for forbidden files
   └─ If found → ERROR

4. Verify required files exist
   └─ If missing → ERROR

5. Analyze code
   ├─ Check CloudDartFunction structure
   ├─ Verify @cloudFunction annotation
   ├─ Check for main() function
   └─ Scan for security risks

6. If all pass → Create archive and upload
   If any fail → Display errors and abort

Common Issues

"Function size exceeds 5 MB limit"

Solution:

  • Remove .git, .dart_tool, build directories
  • Check for large files (images, videos, etc.)
  • Minimize dependencies

"Forbidden directories found: .git"

Solution:

  • Run: rm -rf .git
  • Or add to .gitignore if using version control

"Forbidden files found: .env"

Solution:

  • Remove .env file
  • Use environment variables instead
  • Store secrets in secure configuration

"pubspec.yaml not found"

Solution:

  • Ensure pubspec.yaml exists in function root
  • Run: dart pub get to initialize

"main.dart or bin/main.dart not found"

Solution:

  • Create main.dart in function root
  • Or create bin/main.dart
  • Must contain your @cloudFunction class

Modifying Configuration

To change deployment restrictions:

  • Edit lib/config/deployment_config.dart
  • Update the constants in DeploymentConfig class
  • Rebuild the CLI

Example - Change maximum size to 10 MB:

dart
class DeploymentConfig {
  static const int maxFunctionSizeMB = 10;  // Changed from 5
  static const int sizeWarningThresholdMB = 8;  // Changed from 4
  // ... rest of config
}

Best Practices

  • Keep it minimal - Only include necessary files
  • Use .gitignore - Exclude build artifacts
  • No secrets - Never commit .env or credentials
  • Clean before deploy - Remove build directories
  • Check size - Monitor function size growth
  • Test locally - Verify before deployment

See Also