feat: add Control Room with containers and stacks management
- Add Control Room page with stacks sidebar and containers list - Implement container actions (start/stop/restart) with snackbars - Add container logs viewer dialog - Add search/filter for both stacks and containers lists - Add external links for Portainer and Netdata (url_launcher) - Add VS Code launch configuration for Flutter web debugging 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.5
parent
dd6bcbdbda
commit
3b89ed8c18
@@ -0,0 +1,171 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'container.freezed.dart';
|
||||
|
||||
/// Docker container entity.
|
||||
@freezed
|
||||
class Container with _$Container {
|
||||
const factory Container({
|
||||
/// Container ID (short form).
|
||||
required String id,
|
||||
|
||||
/// Full container ID.
|
||||
required String fullId,
|
||||
|
||||
/// Container name (without leading slash).
|
||||
required String name,
|
||||
|
||||
/// Image name with tag.
|
||||
required String image,
|
||||
|
||||
/// Current container state.
|
||||
required ContainerState state,
|
||||
|
||||
/// Container status string (e.g., "Up 2 hours").
|
||||
required String status,
|
||||
|
||||
/// Stack/project this container belongs to.
|
||||
String? stackName,
|
||||
|
||||
/// Stack ID if part of a stack.
|
||||
String? stackId,
|
||||
|
||||
/// Mapped ports.
|
||||
@Default([]) List<PortMapping> ports,
|
||||
|
||||
/// Environment variables (key-value pairs).
|
||||
@Default({}) Map<String, String> environment,
|
||||
|
||||
/// Container labels.
|
||||
@Default({}) Map<String, String> labels,
|
||||
|
||||
/// Mounted volumes.
|
||||
@Default([]) List<VolumeMount> mounts,
|
||||
|
||||
/// Networks the container is connected to.
|
||||
@Default([]) List<String> networks,
|
||||
|
||||
/// When the container was created.
|
||||
DateTime? createdAt,
|
||||
|
||||
/// When the container was started.
|
||||
DateTime? startedAt,
|
||||
|
||||
/// CPU usage percentage (0-100).
|
||||
double? cpuPercent,
|
||||
|
||||
/// Memory usage in bytes.
|
||||
int? memoryUsage,
|
||||
|
||||
/// Memory limit in bytes.
|
||||
int? memoryLimit,
|
||||
}) = _Container;
|
||||
|
||||
const Container._();
|
||||
|
||||
/// Whether the container is running.
|
||||
bool get isRunning => state == ContainerState.running;
|
||||
|
||||
/// Whether the container can be started.
|
||||
bool get canStart =>
|
||||
state == ContainerState.exited ||
|
||||
state == ContainerState.created ||
|
||||
state == ContainerState.paused;
|
||||
|
||||
/// Whether the container can be stopped.
|
||||
bool get canStop => state == ContainerState.running;
|
||||
|
||||
/// Whether the container can be restarted.
|
||||
bool get canRestart =>
|
||||
state == ContainerState.running || state == ContainerState.exited;
|
||||
|
||||
/// Memory usage as a percentage of the limit.
|
||||
double? get memoryPercent {
|
||||
if (memoryUsage == null || memoryLimit == null || memoryLimit == 0) {
|
||||
return null;
|
||||
}
|
||||
return (memoryUsage! / memoryLimit!) * 100;
|
||||
}
|
||||
|
||||
/// Formatted memory usage string.
|
||||
String get memoryFormatted {
|
||||
if (memoryUsage == null) return '--';
|
||||
return _formatBytes(memoryUsage!);
|
||||
}
|
||||
|
||||
/// Formatted memory limit string.
|
||||
String get memoryLimitFormatted {
|
||||
if (memoryLimit == null) return '--';
|
||||
return _formatBytes(memoryLimit!);
|
||||
}
|
||||
|
||||
String _formatBytes(int bytes) {
|
||||
if (bytes < 1024) return '$bytes B';
|
||||
if (bytes < 1024 * 1024) return '${(bytes / 1024).toStringAsFixed(1)} KB';
|
||||
if (bytes < 1024 * 1024 * 1024) {
|
||||
return '${(bytes / (1024 * 1024)).toStringAsFixed(1)} MB';
|
||||
}
|
||||
return '${(bytes / (1024 * 1024 * 1024)).toStringAsFixed(2)} GB';
|
||||
}
|
||||
}
|
||||
|
||||
/// Container state.
|
||||
enum ContainerState {
|
||||
created,
|
||||
running,
|
||||
paused,
|
||||
restarting,
|
||||
removing,
|
||||
exited,
|
||||
dead,
|
||||
}
|
||||
|
||||
/// Port mapping configuration.
|
||||
@freezed
|
||||
class PortMapping with _$PortMapping {
|
||||
const factory PortMapping({
|
||||
/// Host IP (usually 0.0.0.0).
|
||||
String? hostIp,
|
||||
|
||||
/// Port on the host.
|
||||
int? hostPort,
|
||||
|
||||
/// Port inside the container.
|
||||
required int containerPort,
|
||||
|
||||
/// Protocol (tcp/udp).
|
||||
@Default('tcp') String protocol,
|
||||
}) = _PortMapping;
|
||||
|
||||
const PortMapping._();
|
||||
|
||||
/// Formatted string representation.
|
||||
String get formatted {
|
||||
if (hostPort == null) return '$containerPort/$protocol';
|
||||
final ip = hostIp == '0.0.0.0' ? '' : '$hostIp:';
|
||||
return '$ip$hostPort->$containerPort/$protocol';
|
||||
}
|
||||
}
|
||||
|
||||
/// Volume mount configuration.
|
||||
@freezed
|
||||
class VolumeMount with _$VolumeMount {
|
||||
const factory VolumeMount({
|
||||
/// Mount type (bind, volume, tmpfs).
|
||||
required String type,
|
||||
|
||||
/// Source path or volume name.
|
||||
required String source,
|
||||
|
||||
/// Destination path in container.
|
||||
required String destination,
|
||||
|
||||
/// Mount mode (rw, ro).
|
||||
@Default('rw') String mode,
|
||||
}) = _VolumeMount;
|
||||
|
||||
const VolumeMount._();
|
||||
|
||||
/// Whether the mount is read-only.
|
||||
bool get isReadOnly => mode == 'ro';
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import '../entities/container.dart';
|
||||
|
||||
/// Repository interface for container operations.
|
||||
abstract class ContainerRepository {
|
||||
/// Gets all containers.
|
||||
Future<List<Container>> getContainers();
|
||||
|
||||
/// Gets containers filtered by stack.
|
||||
Future<List<Container>> getContainersByStack(String stackId);
|
||||
|
||||
/// Gets a single container by ID.
|
||||
Future<Container> getContainer(String id);
|
||||
|
||||
/// Starts a container.
|
||||
Future<void> startContainer(String id);
|
||||
|
||||
/// Stops a container.
|
||||
Future<void> stopContainer(String id);
|
||||
|
||||
/// Restarts a container.
|
||||
Future<void> restartContainer(String id);
|
||||
|
||||
/// Pauses a container.
|
||||
Future<void> pauseContainer(String id);
|
||||
|
||||
/// Unpauses a container.
|
||||
Future<void> unpauseContainer(String id);
|
||||
|
||||
/// Removes a container.
|
||||
Future<void> removeContainer(String id, {bool force = false});
|
||||
|
||||
/// Gets container logs.
|
||||
Future<String> getContainerLogs(
|
||||
String id, {
|
||||
int? tail,
|
||||
bool timestamps = false,
|
||||
});
|
||||
|
||||
/// Streams container logs in real-time.
|
||||
Stream<String> streamContainerLogs(
|
||||
String id, {
|
||||
bool timestamps = false,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user