diff --git a/sh/ollama-monitor.sh b/sh/ollama-monitor.sh new file mode 100644 index 0000000..fbba818 --- /dev/null +++ b/sh/ollama-monitor.sh @@ -0,0 +1 @@ +#!/bin/bash echo "Starting Ollama monitor service..." # 無限迴圈來持續監控 while true; do # 檢查 ollama 服務的日誌,看看最近是否有新請求或活動 # 'tail -n 1' 抓取最新的日誌行 # 'grep -E' 搜尋包含 'generating' 或 'loading' 的行,代表有活動 if docker logs ollama --since 2m 2>&1 | grep -E -q 'generating|loading'; then echo "$(date) - Ollama is active. Not unloading models." # 如果有活動,等待 1 分鐘後再次檢查 sleep 60 else # 如果 10 分鐘內沒有活動,執行卸載指令 echo "$(date) - Ollama is idle. Unloading models..." docker exec ollama ollama unload -a echo "$(date) - Models unloaded." # 等待 1 分鐘後再次檢查 sleep 60 fi done \ No newline at end of file diff --git a/sh/vllm-monitor.sh b/sh/vllm-monitor.sh new file mode 100644 index 0000000..e69de29 diff --git a/stack/vllm-webui.yml b/stack/vllm-webui.yml new file mode 100644 index 0000000..e7659af --- /dev/null +++ b/stack/vllm-webui.yml @@ -0,0 +1,65 @@ +version: '3.8' + +services: + vllm: + container_name: vllm + image: vllm/vllm:latest + restart: always + volumes: + - vllm-data:/root/.vllm + - /mnt/970_Containers/ollama_model:/models + # Persist only conversation logs to a host folder (example relative path) + - ./data/vllm_convos:/root/.vllm/conversations + # Default HTTP port for the vllm server - adjust if your image uses a different port + ports: + - "8000:8000" + environment: + # Informational env for other services; change if your webui expects a different var + - VLLM_API_URL=http://vllm:8000 + deploy: + resources: + reservations: + devices: + - driver: nvidia + count: 2 # adjust to your GPU count + capabilities: [gpu] + + open-webui: + container_name: open-webui + image: ghcr.io/open-webui/open-webui:main + restart: always + volumes: + - open-webui-data:/app/backend/data + ports: + - "9070:8080" + # Many web frontends accept a backend URL env; adjust the variable name if needed. + environment: + - VLLM_BASE_URL=http://vllm:8000 + networks: + - stack_bridge + + vllm-monitor: + image: docker:cli + container_name: vllm-monitor + restart: always + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - /mnt/data/External/ollama_monitor/monitor.sh:/monitor.sh:ro + entrypoint: ["/bin/sh", "/monitor.sh"] + depends_on: + - vllm + +volumes: + vllm-data: + open-webui-data: + +networks: + stack_bridge: + external: true + +# NOTES: +# - This compose file is a starting point. It assumes the vllm image exposes an HTTP API on port 8000 +# and that conversation logs live under /root/.vllm/conversations inside the container. +# - If the real vllm image uses different paths or ports, update the paths/ports accordingly. +# - Keep the named volume `vllm-data` to hold other vllm internal state; the host mount +# ./data/vllm_convos will persist conversations specifically on the host. \ No newline at end of file diff --git a/vs-code-server/template/main.tf b/vs-code-server/template/main.tf index 16066d6..f2699be 100644 --- a/vs-code-server/template/main.tf +++ b/vs-code-server/template/main.tf @@ -3,62 +3,57 @@ terraform { coder = { source = "coder/coder" } - docker = { - source = "kreuzwerker/docker" - } } } locals { username = data.coder_workspace_owner.me.name -} - -variable "docker_socket" { - default = "" - description = "(Optional) Docker socket URI" - type = string -} - -provider "docker" { - # Defaulting to null if the variable is an empty string lets us have an optional variable without having to set our own default - host = var.docker_socket != "" ? var.docker_socket : null + user_id = data.coder_workspace_owner.me.id } data "coder_provisioner" "me" {} data "coder_workspace" "me" {} data "coder_workspace_owner" "me" {} +# 環境變數:GitHub token for Copilot +variable "github_token" { + description = "GitHub token for Copilot authentication (optional)" + type = string + sensitive = true + default = "" +} + resource "coder_agent" "main" { arch = data.coder_provisioner.me.arch os = "linux" startup_script = <<-EOT set -e - # Prepare user home with default files on first start. + # 初始化使用者目錄 if [ ! -f ~/.init_done ]; then - cp -rT /etc/skel ~ + cp -rT /etc/skel ~ || true touch ~/.init_done fi - # Add any commands that should be executed at workspace startup (e.g install requirements, start a program, etc) here + # 確保必要目錄存在 + mkdir -p ~/.config ~/.cache ~/.local/share + + # 安裝 VSCode Server extensions(可選) + # code-server --install-extension github.copilot + # code-server --install-extension ms-vscode.cpptools EOT - # These environment variables allow you to make Git commits right away after creating a - # workspace. Note that they take precedence over configuration defined in ~/.gitconfig! - # You can remove this block if you'd prefer to configure Git manually or using - # dotfiles. (see docs/dotfiles.md) + # Git 認證配置 env = { - GIT_AUTHOR_NAME = coalesce(data.coder_workspace_owner.me.full_name, data.coder_workspace_owner.me.name) - GIT_AUTHOR_EMAIL = "${data.coder_workspace_owner.me.email}" - GIT_COMMITTER_NAME = coalesce(data.coder_workspace_owner.me.full_name, data.coder_workspace_owner.me.name) - GIT_COMMITTER_EMAIL = "${data.coder_workspace_owner.me.email}" + GIT_AUTHOR_NAME = coalesce(data.coder_workspace_owner.me.full_name, data.coder_workspace_owner.me.name) + GIT_AUTHOR_EMAIL = "${data.coder_workspace_owner.me.email}" + GIT_COMMITTER_NAME = coalesce(data.coder_workspace_owner.me.full_name, data.coder_workspace_owner.me.name) + GIT_COMMITTER_EMAIL = "${data.coder_workspace_owner.me.email}" + # GitHub Copilot 認證 + GITHUB_TOKEN = var.github_token != "" ? var.github_token : "" } - # The following metadata blocks are optional. They are used to display - # information about your workspace in the dashboard. You can remove them - # if you don't want to display any information. - # For basic resources, you can use the `coder stat` command. - # If you need more control, you can write your own script. + # 監控指標 metadata { display_name = "CPU Usage" key = "0_cpu_usage" @@ -102,7 +97,6 @@ resource "coder_agent" "main" { metadata { display_name = "Load Average (Host)" key = "6_load_host" - # get load avg scaled by number of cores script = <