-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c226a94
commit 1f74774
Showing
12 changed files
with
194 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package cloud | ||
|
||
import "github.com/flipped-aurora/gin-vue-admin/server/service" | ||
|
||
type ApiGroup struct { | ||
ServerApi | ||
} | ||
|
||
// 一键环境检测 | ||
|
||
// 一键安装环境 | ||
|
||
// 一键发布 | ||
|
||
var ( | ||
cloudServiceGroup = service.ServiceGroupApp.CloudServiceGroup | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package cloud | ||
|
||
import ( | ||
"context" | ||
"github.com/flipped-aurora/gin-vue-admin/server/model/cloud/request" | ||
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
type ServerApi struct{} | ||
|
||
// 环境检测 | ||
func (s *ServerApi) Check(c *gin.Context) { | ||
var checkRequest request.SSHRequest | ||
msg := make(chan string, 1) | ||
err := c.ShouldBindJSON(&checkRequest) | ||
if err != nil { | ||
response.FailWithMessage(err.Error(), c) | ||
} | ||
|
||
ctx := context.Background() | ||
|
||
connect, err := checkRequest.Connection(ctx) | ||
|
||
go cloudServiceGroup.Cmd("docker-compose version", msg, *connect) | ||
|
||
var remsg string | ||
|
||
for { | ||
select { | ||
case msg := <-msg: | ||
remsg += msg | ||
case <-connect.CTX.Done(): | ||
response.OkWithMessage(remsg, c) | ||
return | ||
default: | ||
break | ||
} | ||
} | ||
} | ||
|
||
// 安装环境 | ||
func (s *ServerApi) Install() { | ||
|
||
} | ||
|
||
// 发布 | ||
func (s *ServerApi) Deploy() { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
package v1 | ||
|
||
import ( | ||
"github.com/flipped-aurora/gin-vue-admin/server/api/v1/cloud" | ||
"github.com/flipped-aurora/gin-vue-admin/server/api/v1/example" | ||
"github.com/flipped-aurora/gin-vue-admin/server/api/v1/system" | ||
) | ||
|
||
type ApiGroup struct { | ||
SystemApiGroup system.ApiGroup | ||
ExampleApiGroup example.ApiGroup | ||
CloudApiGroup cloud.ApiGroup | ||
} | ||
|
||
var ApiGroupApp = new(ApiGroup) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package request | ||
|
||
import ( | ||
"context" | ||
"github.com/flipped-aurora/gin-vue-admin/server/model/cloud" | ||
"golang.org/x/crypto/ssh" | ||
"time" | ||
) | ||
|
||
type SSHRequest struct { | ||
Host string `json:"host"` | ||
Port string `json:"port"` | ||
Username string `json:"username"` | ||
Password string `json:"password"` | ||
} | ||
|
||
func (s *SSHRequest) Connection(ctx context.Context) (*cloud.Context, error) { | ||
var cloudCtx cloud.Context | ||
ctx, cancel := context.WithCancel(ctx) | ||
config := &ssh.ClientConfig{ | ||
User: s.Username, | ||
Auth: []ssh.AuthMethod{ | ||
ssh.Password(s.Password), | ||
}, | ||
HostKeyCallback: ssh.InsecureIgnoreHostKey(), | ||
Timeout: 30 * time.Second, | ||
} | ||
cloudCtx.CTX = ctx | ||
cloudCtx.Cancel = cancel | ||
client, err := ssh.Dial("tcp", s.Host+":"+s.Port, config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
cloudCtx.Client = client | ||
return &cloudCtx, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package cloud | ||
|
||
import ( | ||
"context" | ||
"golang.org/x/crypto/ssh" | ||
) | ||
|
||
type SSH interface { | ||
Connection(ctx context.Context) (*Context, error) | ||
} | ||
|
||
type Context struct { | ||
Client *ssh.Client | ||
CTX context.Context | ||
Cancel context.CancelFunc | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package cloud | ||
|
||
type RouterGroup struct { | ||
ServerRouter | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package cloud | ||
|
||
import ( | ||
v1 "github.com/flipped-aurora/gin-vue-admin/server/api/v1" | ||
"github.com/flipped-aurora/gin-vue-admin/server/middleware" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
type ServerRouter struct{} | ||
|
||
func (e *ServerRouter) InitServerRouter(Router *gin.RouterGroup) { | ||
customerRouter := Router.Group("server").Use(middleware.OperationRecord()) | ||
serverApi := v1.ApiGroupApp.CloudApiGroup.ServerApi | ||
{ | ||
customerRouter.GET("check", serverApi.Check) // 创建客户 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
package router | ||
|
||
import ( | ||
"github.com/flipped-aurora/gin-vue-admin/server/router/cloud" | ||
"github.com/flipped-aurora/gin-vue-admin/server/router/example" | ||
"github.com/flipped-aurora/gin-vue-admin/server/router/system" | ||
) | ||
|
||
type RouterGroup struct { | ||
System system.RouterGroup | ||
Example example.RouterGroup | ||
Cloud cloud.RouterGroup | ||
} | ||
|
||
var RouterGroupApp = new(RouterGroup) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package cloud | ||
|
||
type ServiceGroup struct { | ||
ServerService | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package cloud | ||
|
||
import ( | ||
"bufio" | ||
"github.com/flipped-aurora/gin-vue-admin/server/model/cloud" | ||
) | ||
|
||
type ServerService struct{} | ||
|
||
// 环境检测 | ||
func (s *ServerService) Cmd(cmd string, msg chan string, connect cloud.Context) error { | ||
client := connect.Client | ||
defer client.Close() | ||
|
||
session, err := client.NewSession() | ||
if err != nil { | ||
return err | ||
} | ||
defer session.Close() | ||
stdout, err := session.StdoutPipe() | ||
if err != nil { | ||
return err | ||
} | ||
reader := bufio.NewReader(stdout) | ||
|
||
err = session.Start(cmd) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
for { | ||
line, err := reader.ReadString('\n') | ||
if err != nil { | ||
connect.Cancel() | ||
break | ||
} | ||
msg <- line | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
package service | ||
|
||
import ( | ||
"github.com/flipped-aurora/gin-vue-admin/server/service/cloud" | ||
"github.com/flipped-aurora/gin-vue-admin/server/service/example" | ||
"github.com/flipped-aurora/gin-vue-admin/server/service/system" | ||
) | ||
|
||
type ServiceGroup struct { | ||
SystemServiceGroup system.ServiceGroup | ||
ExampleServiceGroup example.ServiceGroup | ||
CloudServiceGroup cloud.ServiceGroup | ||
} | ||
|
||
var ServiceGroupApp = new(ServiceGroup) |