1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-02-07 17:10:07 +08:00

feat: 修改软件参数

This commit is contained in:
zhengkunwang223 2022-10-10 22:56:42 +08:00 committed by zhengkunwang223
parent 9c7552d037
commit 12617f95dd
12 changed files with 89 additions and 72 deletions

View File

@ -11,7 +11,7 @@ services:
networks: networks:
- 1panel - 1panel
ports: ports:
- ${PANEL_APP_PORT}:3306 - ${PANEL_APP_PORT_HTTP}:3306
volumes: volumes:
- ./data/:/var/lib/mysql - ./data/:/var/lib/mysql
- ./conf/my.cnf:/etc/mysql/my.cnf - ./conf/my.cnf:/etc/mysql/my.cnf

View File

@ -14,7 +14,7 @@
"labelEn": "Port", "labelEn": "Port",
"required": true, "required": true,
"default": 3306, "default": 3306,
"envKey": "PANEL_APP_PORT" "envKey": "PANEL_APP_PORT_HTTP"
} }
] ]
} }

View File

@ -11,7 +11,7 @@ services:
networks: networks:
- 1panel - 1panel
ports: ports:
- ${PANEL_APP_PORT}:3306 - ${PANEL_APP_PORT_HTTP}:3306
volumes: volumes:
- ./data/:/var/lib/mysql - ./data/:/var/lib/mysql
- ./conf/my.cnf:/etc/my.cnf - ./conf/my.cnf:/etc/my.cnf

View File

@ -14,7 +14,7 @@
"labelEn": "Port", "labelEn": "Port",
"required": true, "required": true,
"default": 3306, "default": 3306,
"envKey": "PANEL_APP_PORT" "envKey": "PANEL_APP_PORT_HTTP"
} }
] ]
} }

View File

@ -4,7 +4,8 @@ services:
image: nginx:1.23.1 image: nginx:1.23.1
restart: always restart: always
ports: ports:
- ${PANEL_APP_PORT}:80 - ${PANEL_APP_PORT_HTTP}:80
- ${PANEL_APP_PORT_HTTPS}:443
volumes: volumes:
- ./conf/nginx.conf:/etc/nginx/nginx.conf - ./conf/nginx.conf:/etc/nginx/nginx.conf
- ./www:/home/www - ./www:/home/www

View File

@ -2,11 +2,19 @@
"formFields": [ "formFields": [
{ {
"type": "number", "type": "number",
"labelZh": "端口", "labelZh": "Http 端口",
"labelEn": "Port", "labelEn": "Http Port",
"required": true, "required": true,
"default": 80, "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"
} }
] ]
} }

View File

@ -4,7 +4,7 @@ services:
image: wordpress:6.0.1 image: wordpress:6.0.1
container_name: ${CONTAINER_NAME} container_name: ${CONTAINER_NAME}
ports: ports:
- ${PANEL_APP_PORT}:80 - ${PANEL_APP_PORT_HTTP}:80
restart: always restart: always
networks: networks:
- 1panel - 1panel

View File

@ -39,7 +39,7 @@
"labelEn": "Port", "labelEn": "Port",
"required": true, "required": true,
"default": 8080, "default": 8080,
"envKey": "PANEL_APP_PORT" "envKey": "PANEL_APP_PORT_HTTP"
} }
] ]
} }

View File

@ -4,7 +4,6 @@ import (
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/app/dto"
"github.com/1Panel-dev/1Panel/app/model" "github.com/1Panel-dev/1Panel/app/model"
"github.com/1Panel-dev/1Panel/app/repo" "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 { 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 { if ok {
portStr := strconv.FormatFloat(port.(float64), 'f', -1, 32) portStr := strconv.FormatFloat(port.(float64), 'f', -1, 32)
if common.ScanPort(portStr) { if common.ScanPort(portStr) {
@ -266,33 +265,12 @@ func (a AppService) Install(name string, appDetailId uint, params map[string]int
return err return err
} }
if app.Required != "" { if err := checkRequiredAndLimit(app); err != nil {
var requiredArray []string return err
if err := json.Unmarshal([]byte(app.Required), &requiredArray); err != nil { }
return err composeFilePath, err := copyAppData(app.Key, appDetail.Version, name, params)
} if err != nil {
for _, key := range requiredArray { return err
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))
}
}
} }
paramByte, err := json.Marshal(params) paramByte, err := json.Marshal(params)
@ -308,11 +286,6 @@ func (a AppService) Install(name string, appDetailId uint, params map[string]int
Params: string(paramByte), Params: string(paramByte),
} }
composeFilePath, err := copyAppData(app.Key, appDetail.Version, name, params)
if err != nil {
return err
}
var ( var (
auth string auth string
dbConfig dto.AppDatabase dbConfig dto.AppDatabase
@ -363,7 +336,7 @@ func (a AppService) Install(name string, appDetailId uint, params map[string]int
value["container_name"] = containerName value["container_name"] = containerName
servicePort := 0 servicePort := 0
port, ok := params["PANEL_APP_PORT"] port, ok := params["PANEL_APP_PORT_HTTP"]
if ok { if ok {
portN := int(math.Ceil(port.(float64))) portN := int(math.Ceil(port.(float64)))
servicePort = portN servicePort = portN

View File

@ -11,6 +11,7 @@ import (
"github.com/1Panel-dev/1Panel/utils/compose" "github.com/1Panel-dev/1Panel/utils/compose"
"github.com/1Panel-dev/1Panel/utils/files" "github.com/1Panel-dev/1Panel/utils/files"
"github.com/joho/godotenv" "github.com/joho/godotenv"
"github.com/pkg/errors"
"path" "path"
"strconv" "strconv"
) )
@ -58,6 +59,50 @@ func getSqlStr(key string, operate DatabaseOp, exec dto.ContainerExec) string {
return str 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) { func copyAppData(key, version, installName string, params map[string]interface{}) (composeFilePath string, err error) {
resourceDir := path.Join(global.CONF.System.ResourceDir, "apps", key, version) resourceDir := path.Join(global.CONF.System.ResourceDir, "apps", key, version)
installDir := path.Join(global.CONF.System.AppDir, key) installDir := path.Join(global.CONF.System.AppDir, key)

View File

@ -1,9 +1,7 @@
package docker package docker
import ( import (
"bufio"
"context" "context"
"fmt"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
"github.com/docker/docker/client" "github.com/docker/docker/client"
@ -50,29 +48,21 @@ func (c Client) ListContainersByName(names []string) ([]types.Container, error)
return containers, nil return containers, nil
} }
func (c Client) ExecCommand(context context.Context, name string, command []string) { func (c Client) CreateNetwork(name string) error {
execConfig := types.ExecConfig{Tty: true, AttachStdout: true, AttachStderr: false, Cmd: command} _, err := c.cli.NetworkCreate(context.Background(), name, types.NetworkCreate{
respIdExecCreate, err := c.cli.ContainerExecCreate(context, name, execConfig) Driver: "bridge",
if err != nil { })
fmt.Println(err) return err
} }
respId, err := c.cli.ContainerExecAttach(context, respIdExecCreate.ID, types.ExecStartCheck{})
if err != nil { func (c Client) NetworkExist(name string) bool {
fmt.Println(err) var options types.NetworkListOptions
} var array []filters.KeyValuePair
array = append(array, filters.Arg("name", name))
//text, _ := respId.Reader.ReadString('\n') networks, err := c.cli.NetworkList(context.Background(), options)
//fmt.Printf("%s\n", text) if err != nil {
scanner := bufio.NewScanner(respId.Reader) return false
//text, _ := resp.Reader.ReadString('\n') }
//log.Print(text)
for scanner.Scan() { return len(networks) > 0
fmt.Println(scanner.Text())
}
//
//respId, err := c.cli.ContainerExecAttach(context, respIdExecCreate.ID, types.ExecStartCheck{})
//if err != nil {
// fmt.Println(err)
//}
} }