diff --git a/apps/mysql/5.7.39/docker-compose.yml b/apps/mysql/5.7.39/docker-compose.yml index f1bd8dab6..9e5b59dd3 100644 --- a/apps/mysql/5.7.39/docker-compose.yml +++ b/apps/mysql/5.7.39/docker-compose.yml @@ -11,7 +11,7 @@ services: networks: - 1panel ports: - - ${PANEL_APP_PORT}:3306 + - ${PANEL_APP_PORT_HTTP}:3306 volumes: - ./data/:/var/lib/mysql - ./conf/my.cnf:/etc/mysql/my.cnf diff --git a/apps/mysql/5.7.39/params.json b/apps/mysql/5.7.39/params.json index 273f6a9ed..fee421333 100644 --- a/apps/mysql/5.7.39/params.json +++ b/apps/mysql/5.7.39/params.json @@ -14,7 +14,7 @@ "labelEn": "Port", "required": true, "default": 3306, - "envKey": "PANEL_APP_PORT" + "envKey": "PANEL_APP_PORT_HTTP" } ] } \ No newline at end of file diff --git a/apps/mysql/8.0.30/docker-compose.yml b/apps/mysql/8.0.30/docker-compose.yml index e7727b6aa..75d9f2cfd 100644 --- a/apps/mysql/8.0.30/docker-compose.yml +++ b/apps/mysql/8.0.30/docker-compose.yml @@ -11,7 +11,7 @@ services: networks: - 1panel ports: - - ${PANEL_APP_PORT}:3306 + - ${PANEL_APP_PORT_HTTP}:3306 volumes: - ./data/:/var/lib/mysql - ./conf/my.cnf:/etc/my.cnf diff --git a/apps/mysql/8.0.30/params.json b/apps/mysql/8.0.30/params.json index 273f6a9ed..fee421333 100644 --- a/apps/mysql/8.0.30/params.json +++ b/apps/mysql/8.0.30/params.json @@ -14,7 +14,7 @@ "labelEn": "Port", "required": true, "default": 3306, - "envKey": "PANEL_APP_PORT" + "envKey": "PANEL_APP_PORT_HTTP" } ] } \ No newline at end of file diff --git a/apps/nginx/1.23.1/READEME.md b/apps/nginx/1.23.1/README.md similarity index 100% rename from apps/nginx/1.23.1/READEME.md rename to apps/nginx/1.23.1/README.md diff --git a/apps/nginx/1.23.1/docker-compose.yml b/apps/nginx/1.23.1/docker-compose.yml index 2f7cdd256..44f49984a 100644 --- a/apps/nginx/1.23.1/docker-compose.yml +++ b/apps/nginx/1.23.1/docker-compose.yml @@ -4,7 +4,8 @@ services: image: nginx:1.23.1 restart: always ports: - - ${PANEL_APP_PORT}:80 + - ${PANEL_APP_PORT_HTTP}:80 + - ${PANEL_APP_PORT_HTTPS}:443 volumes: - ./conf/nginx.conf:/etc/nginx/nginx.conf - ./www:/home/www diff --git a/apps/nginx/1.23.1/params.json b/apps/nginx/1.23.1/params.json index 127f1b9be..c1ab673a1 100644 --- a/apps/nginx/1.23.1/params.json +++ b/apps/nginx/1.23.1/params.json @@ -2,11 +2,19 @@ "formFields": [ { "type": "number", - "labelZh": "端口", - "labelEn": "Port", + "labelZh": "Http 端口", + "labelEn": "Http Port", "required": true, "default": 80, - "envKey": "PANEL_APP_PORT" + "envKey": "PANEL_APP_PORT_HTTP" + }, + { + "type": "number", + "labelZh": "Https 端口", + "labelEn": "Https Port", + "required": true, + "default": 443, + "envKey": "PANEL_APP_PORT_HTTPS" } ] } \ No newline at end of file diff --git a/apps/wordpress/6.0.1/docker-compose.yml b/apps/wordpress/6.0.1/docker-compose.yml index bf9b6701c..1e4ea35fd 100644 --- a/apps/wordpress/6.0.1/docker-compose.yml +++ b/apps/wordpress/6.0.1/docker-compose.yml @@ -4,7 +4,7 @@ services: image: wordpress:6.0.1 container_name: ${CONTAINER_NAME} ports: - - ${PANEL_APP_PORT}:80 + - ${PANEL_APP_PORT_HTTP}:80 restart: always networks: - 1panel diff --git a/apps/wordpress/6.0.1/params.json b/apps/wordpress/6.0.1/params.json index a08cf4ef0..82b91fbe7 100644 --- a/apps/wordpress/6.0.1/params.json +++ b/apps/wordpress/6.0.1/params.json @@ -39,7 +39,7 @@ "labelEn": "Port", "required": true, "default": 8080, - "envKey": "PANEL_APP_PORT" + "envKey": "PANEL_APP_PORT_HTTP" } ] } \ No newline at end of file diff --git a/backend/app/service/app.go b/backend/app/service/app.go index 210ebf994..d714950c1 100644 --- a/backend/app/service/app.go +++ b/backend/app/service/app.go @@ -4,7 +4,6 @@ import ( "encoding/base64" "encoding/json" "errors" - "fmt" "github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/app/repo" @@ -249,7 +248,7 @@ func handleErr(install model.AppInstall, err error, out string) error { func (a AppService) Install(name string, appDetailId uint, params map[string]interface{}) error { - port, ok := params["PANEL_APP_PORT"] + port, ok := params["PANEL_APP_PORT_HTTP"] if ok { portStr := strconv.FormatFloat(port.(float64), 'f', -1, 32) if common.ScanPort(portStr) { @@ -266,33 +265,12 @@ func (a AppService) Install(name string, appDetailId uint, params map[string]int return err } - if app.Required != "" { - var requiredArray []string - if err := json.Unmarshal([]byte(app.Required), &requiredArray); err != nil { - return err - } - for _, key := range requiredArray { - if key == "" { - continue - } - requireApp, err := appRepo.GetFirst(appRepo.WithKey(key)) - if err != nil { - return err - } - details, err := appDetailRepo.GetBy(appDetailRepo.WithAppId(requireApp.ID)) - if err != nil { - return err - } - var detailIds []uint - for _, d := range details { - detailIds = append(detailIds, d.ID) - } - - _, err = appInstallRepo.GetFirst(appInstallRepo.WithDetailIdsIn(detailIds)) - if err != nil { - return errors.New(fmt.Sprintf("%s is required", requireApp.Key)) - } - } + if err := checkRequiredAndLimit(app); err != nil { + return err + } + composeFilePath, err := copyAppData(app.Key, appDetail.Version, name, params) + if err != nil { + return err } paramByte, err := json.Marshal(params) @@ -308,11 +286,6 @@ func (a AppService) Install(name string, appDetailId uint, params map[string]int Params: string(paramByte), } - composeFilePath, err := copyAppData(app.Key, appDetail.Version, name, params) - if err != nil { - return err - } - var ( auth string dbConfig dto.AppDatabase @@ -363,7 +336,7 @@ func (a AppService) Install(name string, appDetailId uint, params map[string]int value["container_name"] = containerName servicePort := 0 - port, ok := params["PANEL_APP_PORT"] + port, ok := params["PANEL_APP_PORT_HTTP"] if ok { portN := int(math.Ceil(port.(float64))) servicePort = portN diff --git a/backend/app/service/app_utils.go b/backend/app/service/app_utils.go index 50324366e..260c50283 100644 --- a/backend/app/service/app_utils.go +++ b/backend/app/service/app_utils.go @@ -11,6 +11,7 @@ import ( "github.com/1Panel-dev/1Panel/utils/compose" "github.com/1Panel-dev/1Panel/utils/files" "github.com/joho/godotenv" + "github.com/pkg/errors" "path" "strconv" ) @@ -58,6 +59,50 @@ func getSqlStr(key string, operate DatabaseOp, exec dto.ContainerExec) string { return str } +func checkRequiredAndLimit(app model.App) error { + + if app.Limit > 0 { + installs, err := appInstallRepo.GetBy(appInstallRepo.WithAppId(app.ID)) + if err != nil { + return err + } + if len(installs) >= app.Limit { + return errors.New(fmt.Sprintf("app install limit %d", app.Limit)) + } + } + + if app.Required != "" { + var requiredArray []string + if err := json.Unmarshal([]byte(app.Required), &requiredArray); err != nil { + return err + } + for _, key := range requiredArray { + if key == "" { + continue + } + requireApp, err := appRepo.GetFirst(appRepo.WithKey(key)) + if err != nil { + return err + } + details, err := appDetailRepo.GetBy(appDetailRepo.WithAppId(requireApp.ID)) + if err != nil { + return err + } + var detailIds []uint + for _, d := range details { + detailIds = append(detailIds, d.ID) + } + + _, err = appInstallRepo.GetFirst(appInstallRepo.WithDetailIdsIn(detailIds)) + if err != nil { + return errors.New(fmt.Sprintf("%s is required", requireApp.Key)) + } + } + } + + return nil +} + func copyAppData(key, version, installName string, params map[string]interface{}) (composeFilePath string, err error) { resourceDir := path.Join(global.CONF.System.ResourceDir, "apps", key, version) installDir := path.Join(global.CONF.System.AppDir, key) diff --git a/backend/utils/docker/docker.go b/backend/utils/docker/docker.go index 03ec40022..9b9d6d404 100644 --- a/backend/utils/docker/docker.go +++ b/backend/utils/docker/docker.go @@ -1,9 +1,7 @@ package docker import ( - "bufio" "context" - "fmt" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/client" @@ -50,29 +48,21 @@ func (c Client) ListContainersByName(names []string) ([]types.Container, error) return containers, nil } -func (c Client) ExecCommand(context context.Context, name string, command []string) { - execConfig := types.ExecConfig{Tty: true, AttachStdout: true, AttachStderr: false, Cmd: command} - respIdExecCreate, err := c.cli.ContainerExecCreate(context, name, execConfig) - if err != nil { - fmt.Println(err) - } - respId, err := c.cli.ContainerExecAttach(context, respIdExecCreate.ID, types.ExecStartCheck{}) - if err != nil { - fmt.Println(err) - } - - //text, _ := respId.Reader.ReadString('\n') - //fmt.Printf("%s\n", text) - scanner := bufio.NewScanner(respId.Reader) - //text, _ := resp.Reader.ReadString('\n') - //log.Print(text) - for scanner.Scan() { - fmt.Println(scanner.Text()) - } - // - //respId, err := c.cli.ContainerExecAttach(context, respIdExecCreate.ID, types.ExecStartCheck{}) - //if err != nil { - // fmt.Println(err) - //} - +func (c Client) CreateNetwork(name string) error { + _, err := c.cli.NetworkCreate(context.Background(), name, types.NetworkCreate{ + Driver: "bridge", + }) + return err +} + +func (c Client) NetworkExist(name string) bool { + var options types.NetworkListOptions + var array []filters.KeyValuePair + array = append(array, filters.Arg("name", name)) + networks, err := c.cli.NetworkList(context.Background(), options) + if err != nil { + return false + } + + return len(networks) > 0 }