Compare commits

..

17 Commits

Author SHA1 Message Date
858751035e 添加 code-server 插件 2025-05-05 16:59:25 +08:00
035ab0e209 更新 README 2025-05-02 20:52:32 +08:00
aa8b4f386d 优化模板用户提示 2025-05-02 20:52:16 +08:00
f01641d3fe 添加荆棘鸟官方仓库克隆选项 2025-05-02 20:51:38 +08:00
eed5ddb2eb 更新 README 2025-05-02 17:43:38 +08:00
93e73e8ff1 优化 git 全局配置脚本 2025-05-01 11:56:12 +08:00
e7dba754eb 在容器初始化时自动设置 git 用户名和邮箱 2025-05-01 11:37:33 +08:00
e72777d6fd 在工作区元数据中实时展示 NodeJS 和 pnpm 版本 2025-05-01 11:24:14 +08:00
a52f914df5 取消 code-server 自动安装中文语言包 2025-05-01 11:01:26 +08:00
7764128f31 设置 code-server 默认文件夹路径 2025-05-01 11:00:28 +08:00
c35022b2b7 在 Dockerfile 中创建 jingjiniao 文件夹并设置权限 2025-05-01 10:55:44 +08:00
386f0c55fe 移除 Node.js 和包管理器版本信息的展示,简化启动脚本 2025-05-01 10:49:10 +08:00
331cb4197d 添加 VS Code 扩展和设置 2025-05-01 10:31:15 +08:00
e76d426a38 添加 SSH 密钥对生成和配置 2025-05-01 10:29:34 +08:00
b630ca1eaa 移除 JetBrains Gateway 模块配置 2025-04-30 12:49:53 +08:00
0261a58077 添加 README.md 文件,提供 Jingji Coder 开发模板的介绍和使用指南 2025-04-30 12:29:59 +08:00
993748db9d 更新Dockerfile,替换yarn为pnpm作为全局安装的包管理器 2025-04-30 12:29:49 +08:00
3 changed files with 210 additions and 38 deletions

View File

@@ -5,7 +5,7 @@ USER root
# 安装Node.js # 安装Node.js
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \ RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get install -y nodejs && \ apt-get install -y nodejs && \
npm install -g npm@latest yarn npm install -g npm@latest pnpm
# 可以添加其他开发工具 # 可以添加其他开发工具
RUN apt-get update && apt-get install -y \ RUN apt-get update && apt-get install -y \
@@ -17,5 +17,8 @@ RUN apt-get update && apt-get install -y \
&& apt-get clean \ && apt-get clean \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# 创建jingjiniao文件夹
RUN mkdir -p /home/coder/jingjiniao && chown -R coder:coder /home/coder/jingjiniao
# 设置回普通用户 # 设置回普通用户
USER coder USER coder

77
README.md Normal file
View File

@@ -0,0 +1,77 @@
# 荆棘鸟 Coder 开发环境模板
## 概述
这是一个基于 [Coder](https://coder.com/) 的开发环境模板,专为荆棘鸟文学社设计。该模板提供了一个预配置的 Node.js 开发环境,使开发者可以在任何设备上通过浏览器或远程 IDE 连接进行开发工作。
## 特性
- 基于 Docker 的隔离开发环境
- 预装 Node.js 20.x 和开发工具
- 自动配置 VS Code (code-server) 开发环境
- 自动生成 SSH 密钥对用于 Git 操作
- 持久化存储确保工作空间数据安全保存
- 系统资源监控仪表板
## 技术栈
- Node.js 20.x
- npm 最新版
- pnpm 包管理器
- Git 版本控制
- VS Code (通过 code-server)
## 预安装的 VS Code 扩展
- redhat.vscode-yamlYAML 文件支持
- mhutchie.git-graphGit 图形化界面
## 自动配置
工作区第一次启动时会自动完成以下配置:
1. 创建 SSH 密钥对,用于 Git 操作
2. 配置 SSH 连接到代码库服务器
3. 配置全局 Git 用户信息
4. 自动克隆已选择的代码仓库
## 使用方法
### 创建工作区
1. 登录到 Coder 平台
2. 选择此模板创建新工作区
3. 等待工作区启动完成
### 连接到工作区
可通过以下方式连接到工作区:
1. **浏览器访问** - 通过 Coder 界面打开内置 VS Code
2. **VS Code Remote** - 使用本地 VS Code 连接到远程工作区
3. **SSH 连接** - 使用终端直接 SSH 连接到工作区
### 项目目录结构
所有项目文件应存储在 `/home/coder/jingjiniao` 目录中,此目录会自动在 VS Code 中打开。
## 系统资源监控
工作区提供以下系统资源监控指标:
- CPU 使用率(容器内和宿主机)
- 内存使用情况(容器内和宿主机)
- 磁盘使用情况
- 宿主机负载平均值
- 宿主机交换内存使用情况
- Node.js 和 pnpm 版本信息
## 注意事项
- 工作区中的 `/home/coder` 目录是持久化的,数据会在工作区重启后保留
- 第一次启动会自动生成 SSH 密钥,密钥保存在 `~/.ssh/git` 文件中
- 公钥显示在首次启动日志中,可用于设置 Git 仓库访问权限
## 技术支持
如有任何问题或需要帮助,请联系管理员或参考 [Coder 官方文档](https://coder.com/docs)。

166
main.tf
View File

@@ -14,6 +14,33 @@ locals {
image_name = "coder-nodejs-base:latest" image_name = "coder-nodejs-base:latest"
} }
data "coder_parameter" "clone_reference" {
name = "初始化荆棘鸟文学社参考文档"
type = "bool"
description = "是否初始化荆棘鸟参考文档"
mutable = true
default = "true"
icon = "/emojis/1f4d6.png"
}
data "coder_parameter" "clone_spbook" {
name = "初始化荆棘鸟文学社高三特刊"
type = "bool"
description = "是否初始化荆棘鸟文学社高三特刊"
mutable = true
default = "false"
icon = "/emojis/1f4da.png"
}
data "coder_parameter" "clone_main" {
name = "初始化荆棘鸟文学社主站点"
type = "bool"
description = "是否初始化荆棘鸟文学社主站点"
mutable = true
default = "false"
icon = "/emojis/1f3e0.png"
}
variable "docker_socket" { variable "docker_socket" {
default = "" default = ""
description = "(Optional) Docker socket URI" description = "(Optional) Docker socket URI"
@@ -50,27 +77,74 @@ resource "coder_agent" "main" {
# Prepare user home with default files on first start. # Prepare user home with default files on first start.
if [ ! -f ~/.init_done ]; then if [ ! -f ~/.init_done ]; then
cp -rT /etc/skel ~ cp -rT /etc/skel ~
# 创建 .ssh 目录并设置权限
mkdir -p ~/.ssh
chmod 700 ~/.ssh
# 生成 SSH 密钥对
ssh-keygen -t ed25519 -f ~/.ssh/git -N "" -C "${data.coder_workspace_owner.me.name}(${data.coder_workspace_owner.me.email})-${data.coder_workspace.me.name}"
# 创建 SSH 配置文件
cat > ~/.ssh/config <<EOF
Host ssh.lionhao.top
StrictHostKeyChecking accept-new
Port 4022
User git
IdentityFile ~/.ssh/git
EOF
# 设置适当的权限
chmod 600 ~/.ssh/config
chmod 600 ~/.ssh/git
chmod 644 ~/.ssh/git.pub
echo "SSH 密钥对创建成功,你的公钥是:"
cat ~/.ssh/git.pub
echo "请将以上公钥添加到 Gitea 个人 SSH 密钥中"
# 添加 git 全局配置
git config --global user.name "${data.coder_workspace_owner.me.name}"
git config --global user.email "${data.coder_workspace_owner.me.email}"
cd /home/coder/jingjiniao
# 拉取仓库
if [ "${data.coder_parameter.clone_reference.value}" = "true" ]; then
echo "正在克隆 荆棘鸟文学社参考文档站点仓库..."
git clone https://gitea.lionhao.top/jjnwxs/jingji_reference.git
echo "荆棘鸟文学社参考文档站点仓库 克隆完成"
cd jingji_reference
git remote set-url origin git@ssh.lionhao.top:jjnwxs/jingji_reference.git
echo "荆棘鸟文学社参考文档站点仓库 远程地址设置成功"
cd ..
fi
if [ "${data.coder_parameter.clone_spbook.value}" = "true" ]; then
echo "正在克隆 荆棘鸟文学社高三特刊站点仓库..."
git clone https://gitea.lionhao.top/jjnwxs/jingji_spbook.git
echo "荆棘鸟文学社高三特刊站点仓库 克隆完成"
cd jingji_spbook
git remote set-url origin git@ssh.lionhao.top:jjnwxs/jingji_spbook.git
echo " 荆棘鸟文学社高三特刊站点仓库 远程地址设置成功"
cd ..
fi
if [ "${data.coder_parameter.clone_main.value}" = "true" ]; then
echo "正在克隆 荆棘鸟文学社主站点仓库..."
git clone https://gitea.lionhao.top/jjnwxs/jingji_main.git
echo "荆棘鸟文学社主站点仓库 克隆完成"
cd jingji_main
git remote set-url origin git@ssh.lionhao.top:jjnwxs/jingji_main.git
echo "荆棘鸟文学社主站点仓库 远程地址设置成功"
cd ..
fi
touch ~/.init_done touch ~/.init_done
fi fi
# Node.js 已经在镜像中安装,展示版本信息
echo "Node.js version:"
node -v
echo "npm version:"
npm -v
echo "yarn version:"
yarn -v
# 可以在这里添加额外的启动命令
EOT EOT
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}"
}
metadata { metadata {
display_name = "CPU Usage" display_name = "CPU Usage"
key = "0_cpu_usage" key = "0_cpu_usage"
@@ -131,6 +205,22 @@ resource "coder_agent" "main" {
interval = 10 interval = 10
timeout = 1 timeout = 1
} }
metadata {
display_name = "NodeJS Version"
key = "8_nodejs_version"
script = "node -v"
interval = 1800
timeout = 1
}
metadata {
display_name = "pnpm Version"
key = "9_pnpm_version"
script = "pnpm -v"
interval = 1800
timeout = 1
}
} }
# See https://registry.coder.com/modules/code-server # See https://registry.coder.com/modules/code-server
@@ -140,31 +230,33 @@ module "code-server" {
# This ensures that the latest version of the module gets downloaded, you can also pin the module version to prevent breaking changes in production. # This ensures that the latest version of the module gets downloaded, you can also pin the module version to prevent breaking changes in production.
version = ">= 1.0.0" version = ">= 1.0.0"
agent_id = coder_agent.main.id agent_id = coder_agent.main.id
extensions = [
"redhat.vscode-yaml",
"mhutchie.git-graph",
"Vue.volar",
"yzhang.markdown-all-in-one",
]
settings = {
"workbench.colorTheme": "Default Dark Modern",
"git.autofetch": true,
"workbench.startupEditor": "none",
"chat.commandCenter.enabled": false,
"editor.fontSize": 16,
"redhat.telemetry.enabled": true,
"editor.cursorStyle": "block",
"editor.cursorBlinking": "smooth",
"workbench.activityBar.location": "top",
"diffEditor.hideUnchangedRegions.enabled": true,
"diffEditor.experimental.showMoves": true,
"diffEditor.renderSideBySide": true
}
auto_install_extensions = true
folder = "/home/coder/jingjiniao"
order = 1 order = 1
} }
# See https://registry.coder.com/modules/jetbrains-gateway
module "jetbrains_gateway" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/modules/jetbrains-gateway/coder"
# JetBrains IDEs to make available for the user to select
jetbrains_ides = ["IU", "PS", "WS", "PY", "CL", "GO", "RM", "RD", "RR"]
default = "IU"
# Default folder to open when starting a JetBrains IDE
folder = "/home/coder"
# This ensures that the latest version of the module gets downloaded, you can also pin the module version to prevent breaking changes in production.
version = ">= 1.0.0"
agent_id = coder_agent.main.id
agent_name = "main"
order = 2
}
resource "docker_volume" "home_volume" { resource "docker_volume" "home_volume" {
name = "coder-${data.coder_workspace.me.id}-home" name = "coder-${data.coder_workspace.me.id}-home"
# Protect the volume from being deleted due to changes in attributes. # Protect the volume from being deleted due to changes in attributes.