From eaaece158bb33d215aeed21d22b7a12a78a0d8dc Mon Sep 17 00:00:00 2001 From: Jeremy Beale <88258057+jrbe228@users.noreply.github.com> Date: Sun, 16 Mar 2025 22:02:24 -0400 Subject: [PATCH 1/4] Create main.py --- python/samples/argocd_install/main.py | 111 ++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 python/samples/argocd_install/main.py diff --git a/python/samples/argocd_install/main.py b/python/samples/argocd_install/main.py new file mode 100644 index 000000000000..776844a6b403 --- /dev/null +++ b/python/samples/argocd_install/main.py @@ -0,0 +1,111 @@ +from dotenv import load_dotenv +import os +import asyncio +from pathlib import Path + +from autogen_agentchat.agents import AssistantAgent, UserProxyAgent, CodeExecutorAgent +from autogen_agentchat.conditions import TextMentionTermination +from autogen_agentchat.teams import RoundRobinGroupChat +from autogen_agentchat.ui import Console +from autogen_ext.models.openai import AzureOpenAIChatCompletionClient +from autogen_ext.code_executors.local import LocalCommandLineCodeExecutor + +# Load environment variables +load_dotenv("./.env") + +async def main() -> None: + """Main function to run Autogen agents and execute tasks sequentially.""" + + # Initialize Model Client + model_client = AzureOpenAIChatCompletionClient( + model=os.getenv("model"), + azure_endpoint=os.getenv("AZURE_API_BASE"), + api_key=os.getenv("AZURE_API_KEY"), + api_version=os.getenv("AZURE_API_VERSION"), + ) + + # Retrieve GitHub credentials from environment variables + repo_url = os.getenv("REPO_URL", "https://github.com/example/repo") # Default if not set + repo_pat = os.getenv("REPO_PAT", "your-pat-token") + + # Setup Code Execution Environment + work_dir = Path("coding") + work_dir.mkdir(exist_ok=True) + #local_executor = LocalCommandLineCodeExecutor(timeout=120, work_dir=work_dir) + local_executor = LocalCommandLineCodeExecutor(work_dir=work_dir) + code_executor_agent = CodeExecutorAgent("code_executor", code_executor=local_executor) + + # Define Agents + assistant = AssistantAgent( + name="assistant", + model_client=model_client, + system_message="""Use the code_executor_agent to solve tasks. + When writing code, provide at least one markdown-encoded code block to execute. + That is, quoting code in ```python or ```sh code blocks). + """, + reflect_on_tool_use=True, + ) + user_proxy = UserProxyAgent("user_proxy") + + # Termination condition + termination = TextMentionTermination("exit") # Type 'exit' to end the conversation. + + # Define Team + team = RoundRobinGroupChat( + [assistant, user_proxy, code_executor_agent], + termination_condition=termination + ) + + # Task 1: Install ArgoCD on Kubernetes using Helm + argocd_install_task = """ + Install ArgoCD on Kubernetes using Helm, if not yet installed. + Install to the 'argocd' namespace. + Assume kubectl and Helm are pre-configured in the local environment. + Wait for ArgoCD pods to become responsive. + """ + await Console(team.run_stream(task=argocd_install_task)) + + + # Task 2: Ensure local access to ArgoCD server + argocd_access_task = """ + Ensure local access to ArgoCD server + You may need port forwarding and / or a load balancer for ArgoCD server using kubectl. + """ + await Console(team.run_stream(task=argocd_access_task)) + + + # Task 3: Install ArgoCD CLI and login to server + argocd_cli_install_task = """ + Ensure the ArgoCD CLI is installed locally. Login to the server. + """ + await Console(team.run_stream(task=argocd_cli_install_task)) + + + # Task 4: Test repo access + repo_access_task = f""" + Use this GitHub repository: {repo_url} + Access the repository with this fine-grained token: {repo_pat} + + Test repo read/write access. + """ + await Console(team.run_stream(task=repo_access_task)) + + + # Task 5: Configure ArgoCD to Deploy Argo Workflows via GitOps + argocd_config_task = f""" + Use ArgoCD's GitOps capabilities to deploy Argo Workflows (ArgoWF) to the argowf namespace, if not yet installed. + Store the ArgoWF config files in a GitHub repository for ArgoCD to scan. + Store Helm values rather than simple K8s manifests. + + Retrieve the ArgoCD admin secret using: + ```sh + kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{{.data.password}}" | base64 -d + ``` + + Use this GitHub repository: {repo_url} + Access the repository with this fine-grained token: {repo_pat} + """ + await Console(team.run_stream(task=argocd_config_task)) + +# Run the script +asyncio.run(main()) From f69e45916b4a1007ae04b38e436c0f0ba1aa3c6e Mon Sep 17 00:00:00 2001 From: Jeremy Beale <88258057+jrbe228@users.noreply.github.com> Date: Sun, 16 Mar 2025 22:07:05 -0400 Subject: [PATCH 2/4] Create README.md --- python/samples/argocd_install/README.md | 40 +++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 python/samples/argocd_install/README.md diff --git a/python/samples/argocd_install/README.md b/python/samples/argocd_install/README.md new file mode 100644 index 000000000000..fd526ee644a8 --- /dev/null +++ b/python/samples/argocd_install/README.md @@ -0,0 +1,40 @@ +# ArgoCD Install Example + +Agentic installation of ArgoCD on Kubernetes using local Kubectl/Helm CLIs. + +## Prerequisites + +First, you need a shell with AutoGen core and required dependencies installed. +- Use VSCode to start the DevContainer defined in `/.devcontainer/`. + +- Then install Python dependencies: +```bash +pip install "autogen-ext[openai,azure]" +python3 -m pip install python-dotenv +pip install autogen_agentchat playwright +``` + +## LLM Configuration + +The LLM configuration should be defined in a `.env` file. +Use `.env_example.yml` as a template. + +## Other Environment Variables + +In your `.env` file, also include the following: +- REPO_URL - Git repo used for storing ArgoCD App configs +- REPO_PAT - Token (Fine-grained recommended) for accessing your Git repo at REPO_URL. +- KUBECONFIG - path to your kubeconfig file in the following section + +## Kubernetes Configuration + +The cluster configuration should be defined in a `kubeconfig` file. +Use `kubeconfig_example` as a template. + +## Running the example + +- Navigate to `/workspaces/autogen/python/samples/argocd_install/` and execute: + +```bash +python main.py +``` From b6f99b14416b0a87b8a8dde052c93985a9ca39b2 Mon Sep 17 00:00:00 2001 From: Jeremy Beale <88258057+jrbe228@users.noreply.github.com> Date: Sun, 16 Mar 2025 22:07:23 -0400 Subject: [PATCH 3/4] Create .env_example --- python/samples/argocd_install/.env_example | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 python/samples/argocd_install/.env_example diff --git a/python/samples/argocd_install/.env_example b/python/samples/argocd_install/.env_example new file mode 100644 index 000000000000..e771db22d2f7 --- /dev/null +++ b/python/samples/argocd_install/.env_example @@ -0,0 +1,7 @@ +model=gpt-4o-mini +AZURE_API_KEY= +AZURE_API_BASE=https://.openai.azure.com/ +AZURE_API_VERSION=2024-08-01-preview +KUBECONFIG=/workspaces/autogen/python/samples/gitea_install/kubeconfig +REPO_URL=https://github.com// +REPO_PAT=11AVBLMCI0RB9l4J3GBnAC From b8e51451e31a5f31f273cfc30731f89757b0036b Mon Sep 17 00:00:00 2001 From: Jeremy Beale <88258057+jrbe228@users.noreply.github.com> Date: Sun, 16 Mar 2025 22:07:45 -0400 Subject: [PATCH 4/4] Create kubeconfig_example --- .../samples/argocd_install/kubeconfig_example | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 python/samples/argocd_install/kubeconfig_example diff --git a/python/samples/argocd_install/kubeconfig_example b/python/samples/argocd_install/kubeconfig_example new file mode 100644 index 000000000000..58e8dcb33833 --- /dev/null +++ b/python/samples/argocd_install/kubeconfig_example @@ -0,0 +1,22 @@ +apiVersion: v1 +kind: Config +clusters: + - name: rancher-desktop + cluster: + #server: https://127.0.0.1:6443 + server: https://host.docker.internal:6443 + certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJkakNDQVIyZ0F3SUJBZ0lCQURBS0JnZ3Foa2pPUFFRREFqQWpNU0V3SHdZRFZRUUREQmhyTTNNdGMyVnkKZG1WeUxXTmhRREUzTXpnd09USTRPVGd3SGhjTk1qVXdNVEk0TVRrek5EVTRXaGNOTXpVd01USTJNVGt6TkRVNApXakFqTVNFd0h3WURWUVFEREJock0zTXRjMlZ5ZG1WeUxXTmhRREUzTXpnd09USTRPVGd3V1RBVEJnY3Foa2pPClBRSUJCZ2dxaGtqT1BRTUJCd05DQUFUaUZGanRWcXIxY0dIdUlTZjl1ZHRRTE9henlQbUVJaUsvLzZkdjJma3YKZDRXeE8vNlovN0lHbkhZMEQ4aW13dFI4OTVrVjEyNHFXeGNLQlhJMnVJTXRvMEl3UURBT0JnTlZIUThCQWY4RQpCQU1DQXFRd0R3WURWUjBUQVFIL0JBVXdBd0VCL3pBZEJnTlZIUTRFRmdRVXc0NDRTZmtqb3VtV2Z2Qi9UTVNyClY0VUd3VHd3Q2dZSUtvWkl6ajBFQXdJRFJ3QXdSQUln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yZ0F3SUJBZ0lCQURBS0JnZ3Foa2pPUFFRREFqQWpNU0V3SHdZRFZRUUREQmhyTTNNdFkyeHAKWlc1MExXTmhRREUzTXpnd09USTRPVGd3SGhjTk1qVXdNVEk0TVRrek5EVTRXaGNOTXpVd01USTJNVGt6TkRVNApXakFqTVNFd0h3WURWUVFEREJock0zTXRZMnhwWlc1MExXTmhRREUzTXpnd09USTRPVGd3V1RBVEJnY3Foa2pPClBRSUJCZ2dxaGtqT1BRTUJCd05DQUFTdmZMYmN1eDNSVWhLT0lzSVU2VTdrRWNUZTB6cDBlb2tvdVpzT04wb2cKR3JwR2xLekFsaVNuck1FajF6RU9wVHRmT3hRZVlDS1FhOHo4V2pWQzFaTHdvMEl3UURBT0JnTlZIUThCQWY4RQpCQU1DQXFRd0R3WURWUjBUQVFIL0JBVXdBd0VCL3pBZEJnTlZIUTRFRmdRVU9LMTUxZldDTUhzWnBxNzlOWDNpCjR0TVVELzR3Q2dZSUtvWkl6ajBFQXdJRFJ3QXdSQUlnUzR3ODc5YUY3SnMvd1hVNlVqSDFaM3NvZitoRWxCM0gKaHpjbTc1akRxendDSUhlZTl4RklXSm9wdTBjOTVCMDdOVTJHR0M1WXkzNXhWdys1U29KVHZRZTkKLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo= + client-key-data: LS0tLS1CRUdJTiBFQyBQUklWQVRFIEtFWS0tLS0tCk1IY0NBUUVFSUN3TzhYbnhUbnhsQjR6YVdDRGZYRk1YWG5YZzhTV0FHa0g5ZEpDTEUyZkpvQW9HQ0NxR1NNNDkKQXdFSG9VUURRZ0FFbnFZOWF3ZXM4MDBMcmRVWktpNVczamRMd0dzYkZuMm03VTczbWhhcnBpT3lxaFcvQ2xMdgpJOGpBR1E5NkUrNmo4NzdIbTVPVFFXbXplRUVIM2plbm5nPT0KLS0tLS1FTkQgRUMgUFJJVkFURSBLRVktLS0tLQo= +contexts: + - name: rancher-desktop + context: + cluster: rancher-desktop + name: rancher-desktop + user: rancher-desktop +preferences: {} +current-context: rancher-desktop