Development Guide#
Learn how to develop, build, and deploy Dart functions with ContainerPub.
Getting Started#
Prerequisites#
- Dart SDK 3.x or higher
- Bun or pub for package management
- Podman (for local testing)
Installation#
Automated Installation (Recommended):
curl -fsSL https://raw.githubusercontent.com/liodali/ContainerPub/main/scripts/install.sh | bash
Or compile from source:
./scripts/install-cli.sh
CLI Usage#
Login#
dart_cloud login
Deploy a Function#
dart_cloud deploy ./my_function
List Functions#
dart_cloud list
View Logs#
dart_cloud logs <function-id>
Delete Function#
dart_cloud delete <function-id>
Function Structure#
A ContainerPub function requires:
my_function/
├── main.dart # Entry point with main() function
├── pubspec.yaml # Dependencies
└── lib/ # Additional code (optional)
Example Function#
// main.dart
void main() {
print('Hello from ContainerPub!');
}
Building Functions#
Local Build#
cd my_function
dart pub get
dart run main.dart
Build Process#
- Upload function archive
- Extract to container
- Build Docker/Podman image
- Store metadata
- Ready for execution
Environment Variables#
Configure environment variables in your function:
dart_cloud deploy ./my_function \
--env DATABASE_URL=postgresql://... \
--env API_KEY=secret
Monitoring#
View Function Metrics#
dart_cloud metrics <function-id>
Check Function Status#
dart_cloud status <function-id>
Stream Logs#
dart_cloud logs <function-id> --follow
Best Practices#
Security#
- Never hardcode secrets
- Use environment variables
- Validate all inputs
- Keep dependencies updated
Performance#
- Minimize cold start time
- Optimize dependencies
- Use efficient algorithms
- Cache when possible
Reliability#
- Handle errors gracefully
- Use proper logging
- Test thoroughly
- Monitor in production
Troubleshooting#
Function Won't Deploy#
- Check Dart SDK version
- Verify pubspec.yaml
- Ensure main() exists
- Check network connectivity
Slow Execution#
- Optimize dependencies
- Reduce function size
- Check resource limits
- Profile your code
Build Failures#
- Check build logs
- Verify dependencies
- Test locally first
- Check Podman status
Next Steps#
- Read the Architecture Overview
- Explore CLI Commands
- Check Best Practices