Compare commits

...

4 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
2 changed files with 71 additions and 5 deletions

View File

@@ -33,6 +33,7 @@
1. 创建 SSH 密钥对,用于 Git 操作
2. 配置 SSH 连接到代码库服务器
3. 配置全局 Git 用户信息
4. 自动克隆已选择的代码仓库
## 使用方法

75
main.tf
View File

@@ -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"
@@ -55,12 +82,13 @@ resource "coder_agent" "main" {
mkdir -p ~/.ssh
chmod 700 ~/.ssh
# 生成 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
@@ -71,12 +99,46 @@ EOF
chmod 600 ~/.ssh/git
chmod 644 ~/.ssh/git.pub
echo "SSH key pair created. Your public key is:"
echo "SSH 密钥对创建成功,你的公钥是:"
cat ~/.ssh/git.pub
echo "请将以上公钥添加到 Gitea 个人 SSH 密钥中"
# 添加 git 全局配置
git config set --global user.name "${data.coder_workspace_owner.me.name}"
git config set --global user.email "${data.coder_workspace_owner.me.email}"
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
@@ -171,7 +233,10 @@ module "code-server" {
agent_id = coder_agent.main.id
extensions = [
"redhat.vscode-yaml",
"mhutchie.git-graph"
"mhutchie.git-graph",
"Vue.volar",
"yzhang.markdown-all-in-one",
]
settings = {
"workbench.colorTheme": "Default Dark Modern",