mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-11-24 02:59:16 +08:00
feat: 修改软件参数
This commit is contained in:
parent
9c7552d037
commit
12617f95dd
@ -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
|
||||
|
@ -14,7 +14,7 @@
|
||||
"labelEn": "Port",
|
||||
"required": true,
|
||||
"default": 3306,
|
||||
"envKey": "PANEL_APP_PORT"
|
||||
"envKey": "PANEL_APP_PORT_HTTP"
|
||||
}
|
||||
]
|
||||
}
|
@ -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
|
||||
|
@ -14,7 +14,7 @@
|
||||
"labelEn": "Port",
|
||||
"required": true,
|
||||
"default": 3306,
|
||||
"envKey": "PANEL_APP_PORT"
|
||||
"envKey": "PANEL_APP_PORT_HTTP"
|
||||
}
|
||||
]
|
||||
}
|
@ -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
|
||||
|
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
@ -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
|
||||
|
@ -39,7 +39,7 @@
|
||||
"labelEn": "Port",
|
||||
"required": true,
|
||||
"default": 8080,
|
||||
"envKey": "PANEL_APP_PORT"
|
||||
"envKey": "PANEL_APP_PORT_HTTP"
|
||||
}
|
||||
]
|
||||
}
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user