Skip to content

Commit

Permalink
服务端构造部各种部署状态
Browse files Browse the repository at this point in the history
  • Loading branch information
donknap committed Dec 1, 2023
1 parent 84c578e commit 395d075
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 56 deletions.
16 changes: 5 additions & 11 deletions app/application/http/controller/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"github.com/donknap/dpanel/app/application/logic"
"github.com/donknap/dpanel/common/accessor"
"github.com/donknap/dpanel/common/dao"
"github.com/donknap/dpanel/common/entity"
"github.com/donknap/dpanel/common/function"
Expand All @@ -24,26 +25,21 @@ func (self Site) CreateByImage(http *gin.Context) {
SiteName string `form:"siteName" binding:"required"`
SiteUrl string `form:"siteUrl" binding:"required,url"`
Image string `json:"image" binding:"required"`
logic.ContainerRunParams
accessor.SiteEnvOption
}

params := ParamsValidate{}
if !self.Validate(http, &params) {
return
}

runParams := &logic.ContainerRunParams{
runParams := accessor.SiteEnvOption{
Environment: params.Environment,
Volumes: params.Volumes,
Ports: params.Ports,
Links: params.Links,
}

siteEnv, err := json.Marshal(runParams)
if err != nil {
self.JsonResponseWithError(http, err, 500)
return
}
siteUrlExt, err := json.Marshal(
[]string{
params.SiteUrl,
Expand All @@ -58,7 +54,7 @@ func (self Site) CreateByImage(http *gin.Context) {
SiteName: params.SiteName,
SiteURL: params.SiteUrl,
SiteURLExt: string(siteUrlExt),
Env: string(siteEnv),
Env: &runParams,
Status: logic.STATUS_STOP,
}
err = dao.Q.Transaction(
Expand Down Expand Up @@ -93,7 +89,6 @@ func (self Site) CreateByImage(http *gin.Context) {

siteRow.SiteID = fmt.Sprintf("dpanel-app-%d-%s", siteRow.ID, function.GetRandomString(10))
dao.Site.Where(dao.Site.ID.Eq(siteRow.ID)).Updates(siteRow)

if err_handler.Found(err) {
self.JsonResponseWithError(http, err, 500)
return
Expand All @@ -103,7 +98,7 @@ func (self Site) CreateByImage(http *gin.Context) {
Name: siteRow.SiteID,
SiteId: siteRow.ID,
Image: params.Image,
RunParams: runParams,
RunParams: &runParams,
}
task.QueueCreate <- runTaskRow
if err != nil {
Expand Down Expand Up @@ -154,7 +149,6 @@ func (self Site) GetList(http *gin.Context) {
}
query = query.Order(dao.Site.ID.Desc())
list, total, _ := query.FindByPage((params.Page-1)*params.PageSize, params.PageSize)

self.JsonResponseWithoutError(http, gin.H{
"total": total,
"page": params.Page,
Expand Down
3 changes: 2 additions & 1 deletion app/application/logic/container-task.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"github.com/docker/docker/api/types"
"github.com/donknap/dpanel/common/accessor"
"github.com/donknap/dpanel/common/service/docker"
"github.com/we7coreteam/w7-rangine-go-support/src/facade"
"io"
Expand Down Expand Up @@ -42,7 +43,7 @@ type CreateMessage struct {
Name string
Image string
SiteId int32
RunParams *ContainerRunParams
RunParams *accessor.SiteEnvOption
}

type ContainerTask struct {
Expand Down
22 changes: 0 additions & 22 deletions app/application/logic/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,3 @@ var StepStatusValue = map[string]int{
STEP_CONTAINER_BUILD: 3,
STEP_CONTAINER_RUN: 4,
}

type MappingItem struct {
Host string `json:"host"`
Dest string `json:"dest"`
}

type LinkItem struct {
Name string `json:"name"`
Alise string `json:"alise"`
}

type EnvItem struct {
Name string `json:"name"`
Value string `json:"value"`
}

type ContainerRunParams struct {
Environment []EnvItem `json:"environment"`
Links []LinkItem `json:"links"`
Ports []MappingItem `json:"ports"`
Volumes []MappingItem `json:"volumes"`
}
23 changes: 23 additions & 0 deletions common/accessor/site_env_option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package accessor

type MappingItem struct {
Host string `json:"host"`
Dest string `json:"dest"`
}

type LinkItem struct {
Name string `json:"name"`
Alise string `json:"alise"`
}

type EnvItem struct {
Name string `json:"name"`
Value string `json:"value"`
}

type SiteEnvOption struct {
Environment []EnvItem `json:"environment"`
Links []LinkItem `json:"links"`
Ports []MappingItem `json:"ports"`
Volumes []MappingItem `json:"volumes"`
}
6 changes: 3 additions & 3 deletions common/dao/ims_site.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 14 additions & 10 deletions common/entity/ims_site.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions database/gen-model.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ relation:
- table: ims_site
column:
env:
tag:
gorm:
serializer: json
serializer: json
type: SiteEnvOption
relate:
- table: ims_container
references: container_id
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/docker/docker v24.0.7+incompatible
github.com/docker/go-connections v0.4.0
github.com/gin-gonic/gin v1.9.1
github.com/goccy/go-json v0.10.2
github.com/gookit/color v1.5.4
github.com/gorilla/websocket v1.5.1
github.com/opencontainers/image-spec v1.0.2
Expand Down Expand Up @@ -37,7 +38,6 @@ require (
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.16.0 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golobby/container/v3 v3.0.2 // indirect
github.com/gorilla/context v1.1.2 // indirect
Expand Down Expand Up @@ -76,7 +76,7 @@ require (
github.com/subosito/gotenv v1.6.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/we7coreteam/gorm-gen-yaml v1.0.4 // indirect
github.com/we7coreteam/gorm-gen-yaml v1.0.6 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
Expand Down Expand Up @@ -312,8 +310,8 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/we7coreteam/gorm-gen-yaml v1.0.4 h1:9wxd4IIXk0nq53NPb5WIqmniOKHiOoug0AsUm/Bf/rk=
github.com/we7coreteam/gorm-gen-yaml v1.0.4/go.mod h1:WAFKkK+958PFd5SBLRlIrUySrJeqUriFaiP31duc8eQ=
github.com/we7coreteam/gorm-gen-yaml v1.0.6 h1:c5NulZy+EvjjmlVRtab5K/Th41Yv9/JpjVmIWh4kieI=
github.com/we7coreteam/gorm-gen-yaml v1.0.6/go.mod h1:WAFKkK+958PFd5SBLRlIrUySrJeqUriFaiP31duc8eQ=
github.com/we7coreteam/w7-rangine-go v1.0.21 h1:MrFzZuCB0C7hfvc/OTgzSkD2jaIHeJ0ihZccNHZoRAQ=
github.com/we7coreteam/w7-rangine-go v1.0.21/go.mod h1:Ai3EHVOub3du3vFUmg2E4m+7/8GJWJqyjW1K8myfsPY=
github.com/we7coreteam/w7-rangine-go-support v1.0.1 h1:u9/gNmtPJMekvNI3zYzFbgqwD46Lpeib3StTTpwrVuM=
Expand Down

0 comments on commit 395d075

Please sign in to comment.