tourze / digital-ocean-droplet-bundle
DigitalOcean Droplet管理包
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/tourze/digital-ocean-droplet-bundle
Requires
- php: ^8.1
- doctrine/dbal: ^4.0
- doctrine/doctrine-bundle: ^2.13
- doctrine/orm: ^3.0
- doctrine/persistence: ^3.1 || ^4
- easycorp/easyadmin-bundle: ^4
- knplabs/knp-menu: ^3.7
- psr/log: ^3|^2|^1
- symfony/config: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/doctrine-bridge: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/http-foundation: ^6.4
- symfony/http-kernel: ^6.4
- symfony/yaml: ^6.4 || ^7.1
- tourze/arrayable: 0.0.*
- tourze/bundle-dependency: 0.0.*
- tourze/digital-ocean-account-bundle: 0.1.*
- tourze/doctrine-indexed-bundle: 0.0.*
- tourze/doctrine-timestamp-bundle: 0.0.*
- tourze/easy-admin-attribute: 0.1.*
- tourze/easy-admin-menu-bundle: 0.1.*
- tourze/enum-extra: 0.1.*
- tourze/symfony-aop-doctrine-bundle: 0.0.*
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-11-01 19:13:32 UTC
README
A Symfony bundle for managing DigitalOcean Droplets with comprehensive API integration and admin interface.
Features
- Droplet Management: Create, list, retrieve, and delete DigitalOcean droplets
- Actions Support: Perform droplet actions (reboot, power cycle, shutdown, etc.)
- SSH Key Management: List and manage SSH keys for droplet access
- Admin Interface: EasyAdmin integration for web-based management
- Database Integration: Doctrine ORM integration with local droplet storage
- Comprehensive API: Full support for DigitalOcean API v2
Installation
composer require tourze/digital-ocean-droplet-bundle
Add the bundle to your config/bundles.php:
<?php return [ // ... other bundles DigitalOceanDropletBundle\DigitalOceanDropletBundle::class => ['all' => true], ];
Dependencies
This bundle requires:
tourze/digital-ocean-account-bundle- For DigitalOcean API authenticationeasycorp/easyadmin-bundle- For admin interface integrationdoctrine/orm- For database persistence
Quick Start
Basic Usage
<?php use DigitalOceanDropletBundle\Service\DropletService; use DigitalOceanDropletBundle\Request\CreateDropletRequest; class MyController { public function __construct( private readonly DropletService $dropletService ) {} public function createDroplet(): void { $droplet = $this->dropletService->createDroplet( name: 'my-droplet', region: 'nyc3', size: 's-1vcpu-1gb', tags: ['production'] ); // Droplet created successfully } public function listDroplets(): array { return $this->dropletService->listDroplets(page: 1, perPage: 20); } }
Service Configuration
The bundle requires DigitalOcean API configuration through the tourze/digital-ocean-account-bundle.
Admin Interface
The bundle provides an EasyAdmin CRUD controller for managing droplets through the web interface. Access it through your admin panel.
Available Services
DropletService- Main service for droplet operationsDropletActionService- Service for performing droplet actionsSSHKeyService- Service for SSH key managementAdminMenu- EasyAdmin menu integration
API Methods
Droplet Operations
listDroplets(int $page = 1, int $perPage = 20, ?string $tagName = null)getDroplet(int $dropletId)createDroplet(string $name, string $region, string $size, array $tags = [])deleteDroplet(int $dropletId)syncDroplets()waitForDropletStatus(int $dropletId, string $expectedStatus, int $maxAttempts = 60, int $interval = 10)
Droplet Actions
getDropletAction(int $dropletId, int $actionId)listDropletActions(int $dropletId, int $page = 1, int $perPage = 20)rebootDroplet(int $dropletId)powerOnDroplet(int $dropletId)powerOffDroplet(int $dropletId)shutdownDroplet(int $dropletId)rebootDropletsByTag(string $tagName)powerOnDropletsByTag(string $tagName)powerOffDropletsByTag(string $tagName)waitForActionCompletion(int $dropletId, int $actionId, array $expectedStatus = ['completed'], int $maxAttempts = 60, int $interval = 10)
SSH Key Management
getSSHKeyIds()
Entity Structure
The Droplet entity includes:
- Basic droplet information (name, memory, vcpus, disk)
- Network and volume configurations
- Status and metadata
- Timestamps and tags
Testing
Run the test suite:
./vendor/bin/phpunit packages/digital-ocean-droplet-bundle/tests
Advanced Usage
Synchronizing Droplets
Sync all droplets from DigitalOcean to your local database:
$droplets = $this->dropletService->syncDroplets();
Waiting for Droplet Status
Wait for a droplet to reach a specific status and get its public IP:
$publicIp = $this->dropletService->waitForDropletStatus( dropletId: 123456, expectedStatus: 'active', maxAttempts: 60, interval: 10 );
Custom Droplet Actions
// Reboot a droplet $action = $this->dropletActionService->rebootDroplet(123456); // Perform action on all droplets with a tag $actions = $this->dropletActionService->powerOffDropletsByTag('production'); // Wait for action completion $completedAction = $this->dropletActionService->waitForActionCompletion( dropletId: 123456, actionId: $action['id'], expectedStatus: ['completed'] );
Requirements
- PHP 8.1+
- Symfony 6.4+
- Doctrine ORM 3.0+
- EasyAdmin 4+
License
MIT License. See LICENSE for details.