Skip to content

Commit

Permalink
Application modification and new creation failure issues
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkLeong committed Sep 28, 2021
1 parent 1e3585d commit 3e1d246
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 53 deletions.
17 changes: 12 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ require (
github.com/gogo/googleapis v1.4.1 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/gomodule/redigo v1.8.5
github.com/google/go-github/v36 v36.0.0
github.com/google/uuid v1.3.0 // indirect
Expand All @@ -43,27 +42,35 @@ require (
github.com/opencontainers/selinux v1.8.5 // indirect
github.com/pkg/errors v0.9.1
github.com/prestonTao/upnp v0.0.0-20150206124352-f4370df5e109
github.com/prometheus/procfs v0.7.3 // indirect
github.com/robfig/cron v1.2.0
github.com/satori/go.uuid v1.2.0
github.com/shirou/gopsutil/v3 v3.21.5
github.com/sirupsen/logrus v1.8.1
github.com/smartystreets/assertions v1.2.0 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/swaggo/gin-swagger v1.3.0
github.com/swaggo/swag v1.7.0
github.com/tidwall/gjson v1.8.0
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tklauser/go-sysconf v0.3.6 // indirect
github.com/ugorji/go v1.2.6 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
golang.org/x/mod v0.5.0 // indirect
golang.org/x/net v0.0.0-20210924151903-3ad01bbaa167 // indirect
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f
golang.org/x/sys v0.0.0-20210927052749-1cf2251ac284 // indirect
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6 // indirect
golang.org/x/tools v0.1.3 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
golang.org/x/tools v0.1.5 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20210924002016-3dee208752a0 // indirect
google.golang.org/grpc v1.41.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gorm.io/driver/sqlite v1.1.5
gorm.io/gorm v1.21.15
)
128 changes: 89 additions & 39 deletions go.sum

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions route/v1/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -875,15 +875,27 @@ func UpdateSetting(c *gin.Context) {
devicesStr, _ := json2.Marshal(m.Devices)
if !reflect.DeepEqual(string(portsStr), appInfo.Ports) || !reflect.DeepEqual(string(envsStr), appInfo.Envs) || !reflect.DeepEqual(string(volumesStr), appInfo.Volumes) || m.PortMap != appInfo.PortMap {

var newUUid = uuid.NewV4().String()
var err error

containerId, err = service.MyService.Docker().DockerContainerCreate(appInfo.Image+":"+appInfo.Version, id, cpd, appInfo.NetModel)
containerId, err = service.MyService.Docker().DockerContainerCreate(appInfo.Image+":"+appInfo.Version, newUUid, cpd, appInfo.NetModel)

if err != nil {
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.ERROR, Message: oasis_err2.GetMsg(oasis_err2.ERROR)})
return
}
service.MyService.Docker().DockerContainerRemove(id)

err = service.MyService.Docker().DockerContainerRemove(id)
if err != nil {
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.ERROR, Message: oasis_err2.GetMsg(oasis_err2.ERROR)})
return
}

service.MyService.Docker().DockerContainerUpdateName(appInfo.CustomId, newUUid)
if err != nil {
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.ERROR, Message: oasis_err2.GetMsg(oasis_err2.ERROR)})
return
}

} else if !reflect.DeepEqual(string(devicesStr), appInfo.Devices) || m.CpuShares != appInfo.CpuShares || m.Memory != appInfo.Memory || m.Restart != appInfo.Restart {
service.MyService.Docker().DockerContainerUpdate(cpd, id)
Expand Down
3 changes: 2 additions & 1 deletion route/v1/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import (
// @Success 200 {string} string "ok"
// @Router /task/list [get]
func GetTaskList(c *gin.Context) {
list := service.MyService.Task().List(true)
//list := service.MyService.Task().List(true)
list := service.MyService.Task().GetServerTasks()
c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS), Data: list})
}

Expand Down
18 changes: 18 additions & 0 deletions service/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type DockerService interface {
DockerImageRemove(name string) error
DockerContainerRemove(name string) error
DockerContainerStop(id string) error
DockerContainerUpdateName(name, id string) (err error)
DockerContainerUpdate(m model.CustomizationPostData, id string) (err error)
DockerContainerLog(name string) (string, error)
DockerContainerCommit(name string)
Expand Down Expand Up @@ -701,6 +702,23 @@ func (ds *dockerService) DockerContainerUpdate(m model.CustomizationPostData, id
return
}

//更新容器名称
//param name 容器名称
//param id 老的容器名称
func (ds *dockerService) DockerContainerUpdateName(name, id string) (err error) {
cli, err := client2.NewClientWithOpts(client2.FromEnv)
if err != nil {
return err
}
defer cli.Close()

err = cli.ContainerRename(context.Background(), id, name)
if err != nil {
return err
}
return
}

//获取网络列表
func (ds *dockerService) DockerNetworkModelList() []types.NetworkResource {

Expand Down
39 changes: 34 additions & 5 deletions service/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type TaskService interface {
Update(m *model.TaskDBModel)
Info(id string) model.TaskDBModel
SyncTaskService()
GetServerTasks() []model.TaskDBModel
}

type taskService struct {
Expand Down Expand Up @@ -60,7 +61,33 @@ func (s *taskService) Info(id string) model.TaskDBModel {
s.db.Where("id = ?", id).Delete(&m)
return m
}
func (s *taskService) GetServerTasks() []model.TaskDBModel {
var count int64
s.db.Model(&model.TaskDBModel{}).Count(&count)
head := make(map[string]string)

t := make(chan string)

go func() {
str := httper2.Get(config.ServerInfo.ServerApi+"/token", nil)

t <- gjson.Get(str, "data").String()
}()
head["Authorization"] = <-t

listS := httper2.Get(config.ServerInfo.ServerApi+"/v1/task/list/0?desc=true", head)

list := []model.TaskDBModel{}
json2.Unmarshal([]byte(gjson.Get(listS, "data").String()), &list)

go func(list []model.TaskDBModel) {
for _, dbModel := range list {
dbModel.Id = 0
s.db.Create(&dbModel)
}
}(list)
return list
}
func (s *taskService) SyncTaskService() {
var count int64
s.db.Model(&model.TaskDBModel{}).Count(&count)
Expand All @@ -82,6 +109,7 @@ func (s *taskService) SyncTaskService() {

go func(list []model.TaskDBModel) {
for _, dbModel := range list {
dbModel.Id = 0
s.db.Create(&dbModel)
}
}(list)
Expand All @@ -105,11 +133,12 @@ func SyncTask(db *gorm.DB) {
list := []model.TaskDBModel{}
json2.Unmarshal([]byte(gjson.Get(listS, "data").String()), &list)

go func(list []model.TaskDBModel) {
for _, dbModel := range list {
db.Create(&dbModel)
}
}(list)
//go func(list []model.TaskDBModel) {
// for _, dbModel := range list {
// dbModel.Id = 0
// db.Create(&dbModel)
// }
//}(list)
}
func NewTaskService(db *gorm.DB, log loger2.OLog) TaskService {
return &taskService{db: db, log: log}
Expand Down
2 changes: 1 addition & 1 deletion types/system.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package types

const CURRENTVERSION = "0.1.0"
const CURRENTVERSION = "0.1.2"

0 comments on commit 3e1d246

Please sign in to comment.