Compare commits
9 Commits
5e25b3f4e1
...
a52f914df5
| Author | SHA1 | Date | |
|---|---|---|---|
| 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
|
||||
97
README.md
Normal file
97
README.md
Normal file
@@ -0,0 +1,97 @@
|
||||
# Jingji Coder 开发模板
|
||||
|
||||
这是一个基于 [Coder](https://coder.com/) 的 Node.js 开发环境模板,用于快速设置一致的开发环境。
|
||||
|
||||
## 简介
|
||||
|
||||
该模板使用 Docker 容器创建一个预配置的 Node.js 开发环境,包含常用开发工具和 IDE 支持。通过 Terraform 配置,可以快速部署并管理这些开发环境。
|
||||
|
||||
## 环境配置
|
||||
|
||||
### 预装软件
|
||||
|
||||
- Node.js 20.x
|
||||
- npm (最新版)
|
||||
- yarn
|
||||
- Git
|
||||
- 基本开发工具 (curl, wget, vim, build-essential)
|
||||
|
||||
### 开发工具集成
|
||||
|
||||
- VS Code (通过 code-server)
|
||||
- JetBrains IDEs 支持 (通过 JetBrains Gateway),包括:
|
||||
- IntelliJ IDEA Ultimate (IU)
|
||||
- PhpStorm (PS)
|
||||
- WebStorm (WS)
|
||||
- PyCharm (PY)
|
||||
- CLion (CL)
|
||||
- GoLand (GO)
|
||||
- RubyMine (RM)
|
||||
- Rider (RD)
|
||||
- RustrRover (RR)
|
||||
|
||||
## 设置指南
|
||||
|
||||
### 前提条件
|
||||
|
||||
- 安装 [Docker](https://www.docker.com/get-started)
|
||||
- 安装 [Terraform](https://www.terraform.io/downloads)
|
||||
- 安装 [Coder](https://coder.com/docs/coder-oss/latest/install)
|
||||
|
||||
### 部署步骤
|
||||
|
||||
1. 克隆此仓库到本地
|
||||
2. 初始化 Terraform 配置
|
||||
```
|
||||
terraform init
|
||||
```
|
||||
3. 应用 Terraform 配置创建工作空间
|
||||
```
|
||||
terraform apply
|
||||
```
|
||||
|
||||
## 使用说明
|
||||
|
||||
### 工作空间管理
|
||||
|
||||
工作空间创建后,您可以通过以下方式访问:
|
||||
|
||||
1. 通过 Web 浏览器访问 VS Code
|
||||
2. 使用 JetBrains Gateway 连接到您喜欢的 JetBrains IDE
|
||||
3. 使用 SSH 直接连接到工作空间
|
||||
|
||||
### 持久化存储
|
||||
|
||||
工作空间使用 Docker 卷 (`coder-{workspace-id}-home`) 来保存您的所有文件和配置,确保在工作空间重启后数据不会丢失。
|
||||
|
||||
### 监控资源
|
||||
|
||||
工作空间包含以下监控指标:
|
||||
|
||||
- CPU 使用率(容器和宿主机)
|
||||
- 内存使用率(容器和宿主机)
|
||||
- 磁盘使用情况
|
||||
- 宿主机负载平均值
|
||||
- 宿主机交换空间使用情况
|
||||
|
||||
## 自定义配置
|
||||
|
||||
### 修改 Docker 镜像
|
||||
|
||||
如需添加其他工具或依赖,请编辑 `Dockerfile` 并重新构建镜像。
|
||||
|
||||
### 修改 Terraform 配置
|
||||
|
||||
可以通过编辑 `main.tf` 文件来调整工作空间配置,例如添加更多的环境变量或修改启动脚本。
|
||||
|
||||
## 故障排除
|
||||
|
||||
如遇问题,请检查:
|
||||
|
||||
1. Docker 服务是否正常运行
|
||||
2. Terraform 配置是否有错误
|
||||
3. Coder 服务器状态
|
||||
|
||||
## 许可证
|
||||
|
||||
请参阅项目许可证文件以了解使用条款。
|
||||
74
main.tf
74
main.tf
@@ -50,18 +50,33 @@ 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.email}"
|
||||
|
||||
# 创建 SSH 配置文件
|
||||
cat > ~/.ssh/config <<EOF
|
||||
Host ssh.lionhao.top
|
||||
Port 4022
|
||||
User git
|
||||
IdentityFile ~/.ssh/git
|
||||
EOF
|
||||
|
||||
# 设置适当的权限
|
||||
chmod 600 ~/.ssh/config
|
||||
chmod 600 ~/.ssh/git
|
||||
chmod 644 ~/.ssh/git.pub
|
||||
|
||||
echo "SSH key pair created. Your public key is:"
|
||||
cat ~/.ssh/git.pub
|
||||
|
||||
touch ~/.init_done
|
||||
fi
|
||||
|
||||
# Node.js 已经在镜像中安装,展示版本信息
|
||||
echo "Node.js version:"
|
||||
node -v
|
||||
echo "npm version:"
|
||||
npm -v
|
||||
echo "yarn version:"
|
||||
yarn -v
|
||||
|
||||
# 可以在这里添加额外的启动命令
|
||||
EOT
|
||||
|
||||
env = {
|
||||
@@ -140,29 +155,28 @@ 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"
|
||||
]
|
||||
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