run method

LogStream<ContainerRunResult> run({
  1. required String image,
  2. String? command,
  3. Map<String, String> env = const {},
  4. String? mountPath,
  5. String? mountSubpath,
  6. String? role,
  7. String? participantName,
  8. Map<int, int> ports = const {},
  9. Map<String, String>? variables,
  10. List<DockerSecret> credentials = const [],
  11. bool detach = true,
})

Implementation

LogStream<ContainerRunResult> run({
  required String image,
  String? command,
  Map<String, String> env = const {},
  String? mountPath,
  String? mountSubpath,
  String? role,
  String? participantName,
  Map<int, int> ports = const {},
  Map<String, String>? variables,
  List<DockerSecret> credentials = const [],
  bool detach = true,
}) {
  final requestId = Uuid().v4().toString();
  final controller = StreamController<String>();
  final completer = Completer<ContainerRunResult>();
  final progress = StreamController<LogProgress>();

  final stream = LogStream<ContainerRunResult>._(completer, controller.stream, progress.stream, () async {
    await room.sendRequest('containers.stop_container', {'request_id': requestId});
  });
  _loggers[requestId] = controller;
  _progress[requestId] = progress;

  final req = _RunRequest(
    requestId: requestId,
    image: image,
    command: command,
    env: env,
    mountPath: mountPath,
    mountSubpath: mountSubpath,
    role: role,
    participantName: participantName,
    ports: ports,
    credentials: credentials,
    detach: detach,
    variables: variables,
  );

  room
      .sendRequest("containers.run", req.toJson())
      .then(
        (result) {
          final json = result as JsonResponse;

          controller.close();
          completer.complete(
            ContainerRunResult(status: json.json["status"], logs: (result.json["logs"] as List).map((l) => l as String).toList()),
          );
          _loggers.remove(requestId);
        },
        onError: (error) {
          controller.close();
          completer.completeError(error);
          _loggers.remove(requestId);
        },
      );

  return stream;
}