# Go 1.25 + VS Code Server (ARM64/AMD64) Dev Container
FROM golang:1.25-bookworm

# 安装常用工具
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
       git sudo ca-certificates curl unzip \
    && rm -rf /var/lib/apt/lists/*

# 创建 vscode 用户
RUN useradd -m -s /bin/bash vscode \
    && echo "vscode ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-vscode \
    && chmod 0440 /etc/sudoers.d/90-vscode

WORKDIR /workspaces

# 预装 VS Code Server，避免运行时下载卡顿
ARG VSCODE_COMMIT="994fd12f8d3a5aa16f17d42c041e5809167e845a"
RUN set -eux; \
  arch=$(dpkg --print-architecture); \
  case "$arch" in \
    amd64) server_arch=linux-x64 ;; \
    arm64) server_arch=linux-arm64 ;; \
    *) echo "Unsupported architecture: $arch"; exit 1 ;; \
  esac; \
  mkdir -p /home/vscode/.vscode-server/bin/${VSCODE_COMMIT}; \
  curl -fsSL "https://update.code.visualstudio.com/commit:${VSCODE_COMMIT}/server-${server_arch}/stable" -o /tmp/vscode-server.tar.gz; \
  tar -xzf /tmp/vscode-server.tar.gz -C /home/vscode/.vscode-server/bin/${VSCODE_COMMIT} --strip-components=1; \
  chown -R vscode:vscode /home/vscode/.vscode-server

# 容器启动后自动安装 dlv 并下载依赖
USER vscode
RUN go install github.com/go-delve/delve/cmd/dlv@latest
