Compare commits
11 Commits
8b5cdd1f93
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 2850fc7cd8 | |||
| df59ebf0b4 | |||
| 74a06e9982 | |||
| caf99f962e | |||
| f11eadb0e8 | |||
| ed87f5a72e | |||
| e00b0be83d | |||
| cbf98bf556 | |||
| b648ee3d92 | |||
| 907980c85c | |||
| 75b8c315db |
34
.gitea/workflows/deploy.yml
Normal file
34
.gitea/workflows/deploy.yml
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
name: 全局K3s部署
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [master]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
# 从组织级Secrets读取,不用在仓库重复配置
|
||||||
|
K3S_HOST: ${{ secrets.K3S_HOST }}
|
||||||
|
APP_NAME: ${{ gitea.repo_name }}
|
||||||
|
steps:
|
||||||
|
- name: 拉取代码
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: SSH部署K3s
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
# 写入组织配置的SSH私钥
|
||||||
|
echo "${{ secrets.K3S_SSH_KEY }}" > k3s.pem
|
||||||
|
chmod 600 k3s.pem
|
||||||
|
# 调试:验证私钥是否正确写入
|
||||||
|
echo "私钥文件权限:"
|
||||||
|
ls -l k3s.pem
|
||||||
|
echo "私钥头部(仅前5行):"
|
||||||
|
head -5 k3s.pem
|
||||||
|
# 测试连接(会输出服务器主机名和kubectl版本)
|
||||||
|
ssh -i k3s.pem -o StrictHostKeyChecking=no -o ConnectTimeout=10 root@${K3S_HOST} "hostname && kubectl version --client"
|
||||||
|
# 正式执行部署命令
|
||||||
|
ssh -i k3s.pem -o StrictHostKeyChecking=no root@${K3S_HOST} << CMD
|
||||||
|
kubectl apply -f /k8s/deploy.yaml
|
||||||
|
kubectl rollout restart deployment ${APP_NAME}
|
||||||
|
CMD
|
||||||
@@ -10,7 +10,7 @@ ENV GOTOOLCHAIN=auto
|
|||||||
ENV GOPRIVATE=gitea.com/red-future/common
|
ENV GOPRIVATE=gitea.com/red-future/common
|
||||||
|
|
||||||
# 配置git使用私有Gitea仓库(带Token认证)
|
# 配置git使用私有Gitea仓库(带Token认证)
|
||||||
RUN git config --global url."http://x-token-auth:9b31146aa8c10a7cb4f2e49dcee0934a223be1076289810e1ad98b968066c2bc@116.204.74.41:3000/red-future/common.git".insteadOf "https://gitea.com/red-future/common.git" && \
|
RUN git config --global url."http://x-token-auth:619679cd366aefea3a50f0622d842a41f2209e08595767bba49c3836ef57d415@116.204.74.41:3000/red-future/common.git".insteadOf "https://gitea.com/red-future/common.git" && \
|
||||||
git config --global credential.helper store
|
git config --global credential.helper store
|
||||||
|
|
||||||
WORKDIR /build
|
WORKDIR /build
|
||||||
|
|||||||
4
go.mod
4
go.mod
@@ -3,11 +3,11 @@ module gateway
|
|||||||
go 1.26.0
|
go 1.26.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gitea.com/red-future/common v0.0.18
|
gitea.com/red-future/common v0.0.19
|
||||||
github.com/gogf/gf/v2 v2.10.0
|
github.com/gogf/gf/v2 v2.10.0
|
||||||
)
|
)
|
||||||
|
|
||||||
//replace gitea.com/red-future/common v0.0.12 => ../common
|
//replace gitea.com/red-future/common v0.0.19 => ../common
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/BurntSushi/toml v1.5.0 // indirect
|
github.com/BurntSushi/toml v1.5.0 // indirect
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -1,7 +1,7 @@
|
|||||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
gitea.com/red-future/common v0.0.18 h1:RwpnnWmDTCnFtKfmlp9BOnDd4r9eUnx7YT6Zst3VJqY=
|
gitea.com/red-future/common v0.0.19 h1:9/WrfCFUCeFUYwuhBYF+JOQi5F5xuOy+gVnf2ZvHZu4=
|
||||||
gitea.com/red-future/common v0.0.18/go.mod h1:6/nqIucVzmjOyqDTIq71feYBXXFNBy0rFwzaQ0/Ueoo=
|
gitea.com/red-future/common v0.0.19/go.mod h1:6/nqIucVzmjOyqDTIq71feYBXXFNBy0rFwzaQ0/Ueoo=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
|
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
|
||||||
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
||||||
|
|||||||
42
main.go
42
main.go
@@ -61,25 +61,25 @@ func StartServerProxy() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 1. 解析 consul 配置地址
|
// 1. 解析 consul 配置地址
|
||||||
consulAddr := g.Cfg().MustGet(r.GetCtx(), "consul.address").String()
|
//consulAddr := g.Cfg().MustGet(r.GetCtx(), "consul.address").String()
|
||||||
consulAddrList := strings.Split(consulAddr, ":")
|
//consulAddrList := strings.Split(consulAddr, ":")
|
||||||
if len(consulAddrList) < 1 {
|
//if len(consulAddrList) < 1 {
|
||||||
g.Log().Error(r.GetCtx(), "consul.address 配置格式错误")
|
// g.Log().Error(r.GetCtx(), "consul.address 配置格式错误")
|
||||||
r.Response.WriteJsonExit(map[string]interface{}{
|
// r.Response.WriteJsonExit(map[string]interface{}{
|
||||||
"success": false,
|
// "success": false,
|
||||||
"code": 500,
|
// "code": 500,
|
||||||
"message": fmt.Sprintf("consul.address 配置格式错误:%s", consulAddr),
|
// "message": fmt.Sprintf("consul.address 配置格式错误:%s", consulAddr),
|
||||||
})
|
// })
|
||||||
return
|
// return
|
||||||
}
|
//}
|
||||||
ipStr := instanceAddr
|
//ipStr := instanceAddr
|
||||||
if strings.Contains(instanceAddr, ":") {
|
//if strings.Contains(instanceAddr, ":") {
|
||||||
ipStr = strings.Split(instanceAddr, ":")[0]
|
// ipStr = strings.Split(instanceAddr, ":")[0]
|
||||||
}
|
//}
|
||||||
// 2. 如果不是本地IP,则替换为consul配置的IP
|
//// 2. 如果不是本地IP,则替换为consul配置的IP
|
||||||
if !utils.IsLocalIP(ipStr) {
|
//if !utils.IsLocalIP(ipStr) {
|
||||||
instanceAddr = strings.Replace(instanceAddr, ipStr, consulAddrList[0], 1)
|
// instanceAddr = strings.Replace(instanceAddr, ipStr, consulAddrList[0], 1)
|
||||||
}
|
//}
|
||||||
|
|
||||||
r.Request.URL.Path = strings.Replace(r.Request.URL.Path, fmt.Sprintf("%s/", serverName), "", 1)
|
r.Request.URL.Path = strings.Replace(r.Request.URL.Path, fmt.Sprintf("%s/", serverName), "", 1)
|
||||||
r.MakeBodyRepeatableRead(false)
|
r.MakeBodyRepeatableRead(false)
|
||||||
@@ -92,10 +92,10 @@ func StartServerProxy() {
|
|||||||
user, err := utils.GetUserInfo(r.GetCtx())
|
user, err := utils.GetUserInfo(r.GetCtx())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Log().Errorf(r.GetCtx(), "获取用户信息失败: %v", err)
|
g.Log().Errorf(r.GetCtx(), "获取用户信息失败: %v", err)
|
||||||
r.Response.Status = 500
|
r.Response.Status = 401
|
||||||
r.Response.WriteJsonExit(map[string]interface{}{
|
r.Response.WriteJsonExit(map[string]interface{}{
|
||||||
"success": false,
|
"success": false,
|
||||||
"code": 500,
|
"code": 401,
|
||||||
"message": "获取用户信息失败",
|
"message": "获取用户信息失败",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user