Feature add test containers workflow service (#24666)
This commit is contained in:
@@ -45,6 +45,7 @@ class DifyTestContainers:
|
||||
self.postgres: Optional[PostgresContainer] = None
|
||||
self.redis: Optional[RedisContainer] = None
|
||||
self.dify_sandbox: Optional[DockerContainer] = None
|
||||
self.dify_plugin_daemon: Optional[DockerContainer] = None
|
||||
self._containers_started = False
|
||||
logger.info("DifyTestContainers initialized - ready to manage test containers")
|
||||
|
||||
@@ -110,6 +111,25 @@ class DifyTestContainers:
|
||||
except Exception as e:
|
||||
logger.warning("Failed to install uuid-ossp extension: %s", e)
|
||||
|
||||
# Create plugin database for dify-plugin-daemon
|
||||
logger.info("Creating plugin database...")
|
||||
try:
|
||||
conn = psycopg2.connect(
|
||||
host=db_host,
|
||||
port=db_port,
|
||||
user=self.postgres.username,
|
||||
password=self.postgres.password,
|
||||
database=self.postgres.dbname,
|
||||
)
|
||||
conn.autocommit = True
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("CREATE DATABASE dify_plugin;")
|
||||
cursor.close()
|
||||
conn.close()
|
||||
logger.info("Plugin database created successfully")
|
||||
except Exception as e:
|
||||
logger.warning("Failed to create plugin database: %s", e)
|
||||
|
||||
# Set up storage environment variables
|
||||
os.environ["STORAGE_TYPE"] = "opendal"
|
||||
os.environ["OPENDAL_SCHEME"] = "fs"
|
||||
@@ -151,6 +171,62 @@ class DifyTestContainers:
|
||||
wait_for_logs(self.dify_sandbox, "config init success", timeout=60)
|
||||
logger.info("Dify Sandbox container is ready and accepting connections")
|
||||
|
||||
# Start Dify Plugin Daemon container for plugin management
|
||||
# Dify Plugin Daemon provides plugin lifecycle management and execution
|
||||
logger.info("Initializing Dify Plugin Daemon container...")
|
||||
self.dify_plugin_daemon = DockerContainer(image="langgenius/dify-plugin-daemon:0.2.0-local")
|
||||
self.dify_plugin_daemon.with_exposed_ports(5002)
|
||||
self.dify_plugin_daemon.env = {
|
||||
"DB_HOST": db_host,
|
||||
"DB_PORT": str(db_port),
|
||||
"DB_USERNAME": self.postgres.username,
|
||||
"DB_PASSWORD": self.postgres.password,
|
||||
"DB_DATABASE": "dify_plugin",
|
||||
"REDIS_HOST": redis_host,
|
||||
"REDIS_PORT": str(redis_port),
|
||||
"REDIS_PASSWORD": "",
|
||||
"SERVER_PORT": "5002",
|
||||
"SERVER_KEY": "test_plugin_daemon_key",
|
||||
"MAX_PLUGIN_PACKAGE_SIZE": "52428800",
|
||||
"PPROF_ENABLED": "false",
|
||||
"DIFY_INNER_API_URL": f"http://{db_host}:5001",
|
||||
"DIFY_INNER_API_KEY": "test_inner_api_key",
|
||||
"PLUGIN_REMOTE_INSTALLING_HOST": "0.0.0.0",
|
||||
"PLUGIN_REMOTE_INSTALLING_PORT": "5003",
|
||||
"PLUGIN_WORKING_PATH": "/app/storage/cwd",
|
||||
"FORCE_VERIFYING_SIGNATURE": "false",
|
||||
"PYTHON_ENV_INIT_TIMEOUT": "120",
|
||||
"PLUGIN_MAX_EXECUTION_TIMEOUT": "600",
|
||||
"PLUGIN_STDIO_BUFFER_SIZE": "1024",
|
||||
"PLUGIN_STDIO_MAX_BUFFER_SIZE": "5242880",
|
||||
"PLUGIN_STORAGE_TYPE": "local",
|
||||
"PLUGIN_STORAGE_LOCAL_ROOT": "/app/storage",
|
||||
"PLUGIN_INSTALLED_PATH": "plugin",
|
||||
"PLUGIN_PACKAGE_CACHE_PATH": "plugin_packages",
|
||||
"PLUGIN_MEDIA_CACHE_PATH": "assets",
|
||||
}
|
||||
|
||||
try:
|
||||
self.dify_plugin_daemon.start()
|
||||
plugin_daemon_host = self.dify_plugin_daemon.get_container_host_ip()
|
||||
plugin_daemon_port = self.dify_plugin_daemon.get_exposed_port(5002)
|
||||
os.environ["PLUGIN_DAEMON_URL"] = f"http://{plugin_daemon_host}:{plugin_daemon_port}"
|
||||
os.environ["PLUGIN_DAEMON_KEY"] = "test_plugin_daemon_key"
|
||||
logger.info(
|
||||
"Dify Plugin Daemon container started successfully - Host: %s, Port: %s",
|
||||
plugin_daemon_host,
|
||||
plugin_daemon_port,
|
||||
)
|
||||
|
||||
# Wait for Dify Plugin Daemon to be ready
|
||||
logger.info("Waiting for Dify Plugin Daemon to be ready to accept connections...")
|
||||
wait_for_logs(self.dify_plugin_daemon, "start plugin manager daemon", timeout=60)
|
||||
logger.info("Dify Plugin Daemon container is ready and accepting connections")
|
||||
except Exception as e:
|
||||
logger.warning("Failed to start Dify Plugin Daemon container: %s", e)
|
||||
logger.info("Continuing without plugin daemon - some tests may be limited")
|
||||
self.dify_plugin_daemon = None
|
||||
|
||||
self._containers_started = True
|
||||
logger.info("All test containers started successfully")
|
||||
|
||||
@@ -166,7 +242,7 @@ class DifyTestContainers:
|
||||
return
|
||||
|
||||
logger.info("Stopping and cleaning up test containers...")
|
||||
containers = [self.redis, self.postgres, self.dify_sandbox]
|
||||
containers = [self.redis, self.postgres, self.dify_sandbox, self.dify_plugin_daemon]
|
||||
for container in containers:
|
||||
if container:
|
||||
try:
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user