diff --git a/route/init.go b/route/init.go index 14ab707..8ea6bf7 100644 --- a/route/init.go +++ b/route/init.go @@ -103,9 +103,10 @@ func installSyncthing(appId string) { m.Ports = appInfo.Ports m.Restart = "always" m.Volumes = appInfo.Volumes + m.NetworkModel = appInfo.NetworkModel m.Label = id m.CustomId = id - containerId, err := service.MyService.Docker().DockerContainerCreate(dockerImage+":"+dockerImageVersion, m, appInfo.NetworkModel) + containerId, err := service.MyService.Docker().DockerContainerCreate(dockerImage+":"+dockerImageVersion, m) if err != nil { fmt.Println("container create error", err) // create container error diff --git a/route/v1/docker.go b/route/v1/docker.go index d440c73..94ce469 100644 --- a/route/v1/docker.go +++ b/route/v1/docker.go @@ -327,7 +327,7 @@ func InstallApp(c *gin.Context) { time.Sleep(time.Second) } - _, err = service.MyService.Docker().DockerContainerCreate(dockerImage+":"+dockerImageVersion, m, appInfo.NetworkModel) + _, err = service.MyService.Docker().DockerContainerCreate(dockerImage+":"+dockerImageVersion, m) if err != nil { //service.MyService.Redis().Set(id, "{\"id\"\""+id+"\",\"state\":false,\"message\":\""+err.Error()+"\",\"speed\":80}", 100) notify := notify.Application{} @@ -901,7 +901,7 @@ func UpdateSetting(c *gin.Context) { service.MyService.Docker().DockerContainerUpdateName(id, id) //service.MyService.Docker().DockerContainerRemove(id, true) - containerId, err := service.MyService.Docker().DockerContainerCreate(m.Image, m, m.NetworkModel) + containerId, err := service.MyService.Docker().DockerContainerCreate(m.Image, m) if err != nil { service.MyService.Docker().DockerContainerUpdateName(m.Label, id) service.MyService.Docker().DockerContainerStart(id) diff --git a/service/app.go b/service/app.go index b08bcc8..b2d4686 100644 --- a/service/app.go +++ b/service/app.go @@ -479,10 +479,10 @@ func (a *appStruct) GetHardwareUsageSteam() { if err != nil { loger.Error("Failed to get container_list", zap.Any("err", err)) } + var temp sync.Map var wg sync.WaitGroup for _, v := range containers { if v.State != "running" { - dataStats.Delete(v.ID) continue } wg.Add(1) @@ -490,7 +490,6 @@ func (a *appStruct) GetHardwareUsageSteam() { defer wg.Done() stats, err := cli.ContainerStats(ctx, v.ID, true) if err != nil { - dataStats.Delete(v.ID) return } decode := json.NewDecoder(stats.Body) @@ -507,14 +506,16 @@ func (a *appStruct) GetHardwareUsageSteam() { dockerStats.Icon = v.Labels["icon"] dockerStats.Title = strings.ReplaceAll(v.Names[0], "/", "") - dataStats.Store(v.ID, dockerStats) + temp.Store(v.ID, dockerStats) if i == 99 { stats.Body.Close() } }(v, i) } wg.Wait() + dataStats = temp isFinish = true + time.Sleep(time.Second * 1) } isFinish = false diff --git a/service/docker.go b/service/docker.go index 69a87fd..593794c 100644 --- a/service/docker.go +++ b/service/docker.go @@ -45,7 +45,7 @@ import ( type DockerService interface { DockerPullImage(imageName string, icon, name string) error IsExistImage(imageName string) bool - DockerContainerCreate(imageName string, m model.CustomizationPostData, net string) (containerId string, err error) + DockerContainerCreate(imageName string, m model.CustomizationPostData) (containerId string, err error) DockerContainerCopyCreate(info *types.ContainerJSON) (containerId string, err error) DockerContainerStart(name string) error DockerContainerStats(name string) (string, error) @@ -376,9 +376,9 @@ func (ds *dockerService) DockerContainerCopyCreate(info *types.ContainerJSON) (c //param mapPort 容器主端口映射到外部的端口 //param tcp 容器其他tcp端口 //param udp 容器其他udp端口 -func (ds *dockerService) DockerContainerCreate(imageName string, m model.CustomizationPostData, net string) (containerId string, err error) { - if len(net) == 0 { - net = "bridge" +func (ds *dockerService) DockerContainerCreate(imageName string, m model.CustomizationPostData) (containerId string, err error) { + if len(m.NetworkModel) == 0 { + m.NetworkModel = "bridge" } cli, err := client2.NewClientWithOpts(client2.FromEnv) @@ -402,7 +402,7 @@ func (ds *dockerService) DockerContainerCreate(imageName string, m model.Customi tContainer, _ := strconv.Atoi(portMap.ContainerPort) if tContainer > 0 { ports[nat.Port(portMap.ContainerPort+"/tcp")] = struct{}{} - if net != "host" { + if m.NetworkModel != "host" { portMaps[nat.Port(portMap.ContainerPort+"/tcp")] = []nat.PortBinding{{HostPort: portMap.CommendPort}} } } @@ -411,7 +411,7 @@ func (ds *dockerService) DockerContainerCreate(imageName string, m model.Customi tContainer, _ := strconv.Atoi(portMap.ContainerPort) if tContainer > 0 { ports[nat.Port(portMap.ContainerPort+"/tcp")] = struct{}{} - if net != "host" { + if m.NetworkModel != "host" { portMaps[nat.Port(portMap.ContainerPort+"/tcp")] = []nat.PortBinding{{HostPort: portMap.CommendPort}} } } @@ -419,7 +419,7 @@ func (ds *dockerService) DockerContainerCreate(imageName string, m model.Customi uContainer, _ := strconv.Atoi(portMap.ContainerPort) if uContainer > 0 { ports[nat.Port(portMap.ContainerPort+"/udp")] = struct{}{} - if net != "host" { + if m.NetworkModel != "host" { portMaps[nat.Port(portMap.ContainerPort+"/udp")] = []nat.PortBinding{{HostPort: portMap.CommendPort}} } } @@ -428,7 +428,7 @@ func (ds *dockerService) DockerContainerCreate(imageName string, m model.Customi uContainer, _ := strconv.Atoi(portMap.ContainerPort) if uContainer > 0 { ports[nat.Port(portMap.ContainerPort+"/udp")] = struct{}{} - if net != "host" { + if m.NetworkModel != "host" { portMaps[nat.Port(portMap.ContainerPort+"/udp")] = []nat.PortBinding{{HostPort: portMap.CommendPort}} } } @@ -541,7 +541,7 @@ func (ds *dockerService) DockerContainerCreate(imageName string, m model.Customi config.Labels["protocol"] = m.Protocol config.Labels["host"] = m.Host //config.Labels["order"] = strconv.Itoa(MyService.App().GetCasaOSCount() + 1) - hostConfig := &container.HostConfig{Resources: res, Mounts: volumes, RestartPolicy: rp, NetworkMode: container.NetworkMode(net), Privileged: m.Privileged, CapAdd: m.CapAdd} + hostConfig := &container.HostConfig{Resources: res, Mounts: volumes, RestartPolicy: rp, NetworkMode: container.NetworkMode(m.NetworkModel), Privileged: m.Privileged, CapAdd: m.CapAdd} //if net != "host" { config.ExposedPorts = ports hostConfig.PortBindings = portMaps @@ -550,7 +550,7 @@ func (ds *dockerService) DockerContainerCreate(imageName string, m model.Customi containerDb, err := cli.ContainerCreate(context.Background(), config, hostConfig, - &network.NetworkingConfig{EndpointsConfig: map[string]*network.EndpointSettings{net: {NetworkID: "", Aliases: []string{}}}}, + &network.NetworkingConfig{EndpointsConfig: map[string]*network.EndpointSettings{m.NetworkModel: {NetworkID: "", Aliases: []string{}}}}, nil, m.Label) if err != nil { diff --git a/web/index.html b/web/index.html index 395f8b2..84e74cf 100644 --- a/web/index.html +++ b/web/index.html @@ -20,7 +20,7 @@ CasaOS - +