Compare commits
17 Commits
5e25b3f4e1
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 858751035e | |||
| 035ab0e209 | |||
| aa8b4f386d | |||
| f01641d3fe | |||
| eed5ddb2eb | |||
| 93e73e8ff1 | |||
| e7dba754eb | |||
| e72777d6fd | |||
| a52f914df5 | |||
| 7764128f31 | |||
| c35022b2b7 | |||
| 386f0c55fe | |||
| 331cb4197d | |||
| e76d426a38 | |||
| b630ca1eaa | |||
| 0261a58077 | |||
| 993748db9d |
@@ -5,7 +5,7 @@ USER root
|
||||
# 安装Node.js
|
||||
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
|
||||
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 \
|
||||
@@ -17,5 +17,8 @@ RUN apt-get update && apt-get install -y \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# 创建jingjiniao文件夹
|
||||
RUN mkdir -p /home/coder/jingjiniao && chown -R coder:coder /home/coder/jingjiniao
|
||||
|
||||
# 设置回普通用户
|
||||
USER coder
|
||||
77
README.md
Normal file
77
README.md
Normal 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-yaml:YAML 文件支持
|
||||
- mhutchie.git-graph:Git 图形化界面
|
||||
|
||||
## 自动配置
|
||||
|
||||
工作区第一次启动时会自动完成以下配置:
|
||||
|
||||
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
166
main.tf
@@ -14,6 +14,33 @@ locals {
|
||||
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" {
|
||||
default = ""
|
||||
description = "(Optional) Docker socket URI"
|
||||
@@ -50,27 +77,74 @@ resource "coder_agent" "main" {
|
||||
# Prepare user home with default files on first start.
|
||||
if [ ! -f ~/.init_done ]; then
|
||||
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
|
||||
fi
|
||||
|
||||
# Node.js 已经在镜像中安装,展示版本信息
|
||||
echo "Node.js version:"
|
||||
node -v
|
||||
echo "npm version:"
|
||||
npm -v
|
||||
echo "yarn version:"
|
||||
yarn -v
|
||||
|
||||
# 可以在这里添加额外的启动命令
|
||||
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 {
|
||||
display_name = "CPU Usage"
|
||||
key = "0_cpu_usage"
|
||||
@@ -131,6 +205,22 @@ resource "coder_agent" "main" {
|
||||
interval = 10
|
||||
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
|
||||
@@ -140,29 +230,31 @@ 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.
|
||||
version = ">= 1.0.0"
|
||||
|
||||
agent_id = coder_agent.main.id
|
||||
order = 1
|
||||
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
|
||||
}
|
||||
|
||||
# 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
|
||||
auto_install_extensions = true
|
||||
folder = "/home/coder/jingjiniao"
|
||||
order = 1
|
||||
}
|
||||
|
||||
resource "docker_volume" "home_volume" {
|
||||
|
||||
Reference in New Issue
Block a user