Skip to content

[pull] master from donknap:master #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions app/application/http/controller/compose-container.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"fmt"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/pkg/stdcopy"
"github.com/donknap/dpanel/app/application/logic"
"github.com/donknap/dpanel/common/accessor"
Expand All @@ -18,6 +19,7 @@ import (
"log/slog"
"os"
"path/filepath"
"strings"
"time"
)

Expand Down Expand Up @@ -117,6 +119,7 @@ func (self Compose) ContainerDeploy(http *gin.Context) {
self.JsonResponseWithError(http, err, 500)
return
}

if params.AutoRemove {
response1, err := tasker.Destroy(false, true)
if err != nil {
Expand All @@ -127,6 +130,7 @@ func (self Compose) ContainerDeploy(http *gin.Context) {
self.JsonSuccessResponse(http)
return
}

taskContainerList := tasker.Ps()
if function.IsEmptyArray(taskContainerList) {
self.JsonResponseWithError(http, errors.New(lastMessage), 500)
Expand All @@ -140,6 +144,40 @@ func (self Compose) ContainerDeploy(http *gin.Context) {
}
}

// 这里需要单独适配一下 php 环境的相关扩展安装
// 目前只有 php 需要这样处理,暂时先直接进行判断
if strings.HasPrefix(composeRow.Setting.Store, accessor.StoreTypeOnePanel) && strings.HasSuffix(composeRow.Setting.Store, "@php") {
out, err := docker.Sdk.ContainerExec(docker.Sdk.Ctx, taskContainerList[0].Name, container.ExecOptions{
Privileged: true,
Tty: false,
AttachStdin: false,
AttachStdout: true,
AttachStderr: false,
Cmd: []string{
"install-ext",
strings.Join(function.PluckArrayWalk(params.Environment, func(item docker.EnvItem) (string, bool) {
if item.Name == "PHP_EXTENSIONS" {
return item.Value, true
} else {
return "", false
}
}), " "),
},
})
if err != nil {
self.JsonResponseWithError(http, err, 500)
return
}
defer func() {
out.Close()
}()
_, err = io.Copy(wsBuffer, out.Reader)
if err != nil {
self.JsonResponseWithError(http, err, 500)
return
}
}

self.JsonSuccessResponse(http)
return
}
Expand Down
47 changes: 47 additions & 0 deletions app/application/http/controller/explorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import (
"fmt"
"github.com/docker/docker/api/types/container"
"github.com/donknap/dpanel/common/function"
"github.com/donknap/dpanel/common/service/compose"
"github.com/donknap/dpanel/common/service/docker"
"github.com/donknap/dpanel/common/service/fs"
"github.com/donknap/dpanel/common/service/notice"
"github.com/donknap/dpanel/common/service/plugin"
"github.com/donknap/dpanel/common/service/storage"
fs2 "github.com/donknap/dpanel/common/types/fs"
"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -574,3 +577,47 @@ func (self Explorer) MkDir(http *gin.Context) {
}
self.JsonSuccessResponse(http)
}

func (self Explorer) AttachVolume(http *gin.Context) {
type ParamsValidate struct {
Name string `json:"name" binding:"required"`
}
params := ParamsValidate{}
if !self.Validate(http, &params) {
return
}
_, err := docker.Sdk.Client.VolumeInspect(docker.Sdk.Ctx, params.Name)
if err != nil {
self.JsonResponseWithError(http, err, 500)
return
}
_ = notice.Message{}.Info(".volumeMountSomeVolume")
path := fmt.Sprintf("/%s", function.GetMd5(params.Name))
explorerPlugin, err := plugin.NewPlugin(plugin.PluginExplorer, map[string]*plugin.TemplateParser{
plugin.PluginExplorer: &plugin.TemplateParser{
ExtService: compose.ExtService{
External: compose.ExternalItem{
Volumes: []string{
fmt.Sprintf("%s:%s", params.Name, path),
},
},
},
},
})
if err != nil {
self.JsonResponseWithError(http, err, 500)
return
}
if explorerPlugin.Exists() {
_ = explorerPlugin.Destroy()
}
pluginName, err := explorerPlugin.Create()
if err != nil {
self.JsonResponseWithError(http, err, 500)
return
}
self.JsonResponseWithoutError(http, gin.H{
"containerName": pluginName,
"path": path,
})
}
1 change: 1 addition & 0 deletions app/application/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func (provider *Provider) Register(httpServer *http_server.Server) {
cors.POST("/app/explorer/get-file-stat", controller.Explorer{}.GetFileStat)
cors.POST("/app/explorer/get-user-list", controller.Explorer{}.GetUserList)
cors.POST("/app/explorer/mkdir", controller.Explorer{}.MkDir)
cors.POST("/app/explorer/attach-volume", controller.Explorer{}.AttachVolume)

// 日志相关
cors.POST("/app/log/run", controller.RunLog{}.Run)
Expand Down
5 changes: 3 additions & 2 deletions app/common/http/controller/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/donknap/dpanel/common/accessor"
"github.com/donknap/dpanel/common/dao"
"github.com/donknap/dpanel/common/entity"
"github.com/donknap/dpanel/common/function"
"github.com/donknap/dpanel/common/service/crontab"
"github.com/donknap/dpanel/common/service/docker"
"github.com/donknap/dpanel/common/service/storage"
Expand Down Expand Up @@ -45,15 +46,15 @@ func (self Cron) Create(http *gin.Context) {
}
err := crontab.Wrapper.CheckExpression(allExpression)
if err != nil {
self.JsonResponseWithError(http, err, 500)
self.JsonResponseWithError(http, function.ErrorMessage(".containerCronExpressionInCorrect", "message", err.Error()), 500)
return
}

var taskRow *entity.Cron
if params.Id > 0 {
taskRow, _ = dao.Cron.Where(dao.Cron.ID.Eq(params.Id)).First()
if taskRow == nil {
self.JsonResponseWithError(http, errors.New("任务不存在"), 500)
self.JsonResponseWithError(http, function.ErrorMessage(".commonDataNotFoundOrDeleted"), 500)
return
}
crontab.Wrapper.RemoveJob(taskRow.Setting.JobIds...)
Expand Down
2 changes: 1 addition & 1 deletion app/common/http/controller/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func (self Store) Deploy(http *gin.Context) {
Title: params.Title,
Setting: &accessor.ComposeSettingOption{
Type: accessor.ComposeTypeStore,
Store: fmt.Sprintf("%s@%s", storeRow.Title, storeRow.Setting.Url),
Store: fmt.Sprintf("%s@%s@%s", storeRow.Title, storeRow.Setting.Url, params.AppName),
Environment: params.Environment,
Uri: []string{
filepath.Join(params.Name, filepath.Base(params.ComposeFile)),
Expand Down
5 changes: 3 additions & 2 deletions app/common/http/controller/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/donknap/dpanel/common/accessor"
"github.com/donknap/dpanel/common/dao"
"github.com/donknap/dpanel/common/entity"
"github.com/donknap/dpanel/common/function"
"github.com/donknap/dpanel/common/service/docker"
"github.com/donknap/dpanel/common/service/family"
"github.com/donknap/dpanel/common/service/notice"
Expand Down Expand Up @@ -38,11 +39,11 @@ func (self User) Login(http *gin.Context) {
exists := logic.Setting{}.GetByKey(logic.SettingGroupSetting, logic.SettingGroupSettingTwoFa, &twoFa)
if exists && twoFa.Enable {
if params.Code == "" {
self.JsonResponseWithError(http, errors.New("请输入双因素验证码"), 500)
self.JsonResponseWithError(http, function.ErrorMessage(".userTwoFaEmpty"), 500)
return
}
if !totp.Validate(params.Code, twoFa.Secret) {
self.JsonResponseWithError(http, errors.New("验证码错误"), 500)
self.JsonResponseWithError(http, function.ErrorMessage(".userTwoFaNotCorrect"), 500)
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/pro
Submodule pro updated from 5588b5 to c91243
7 changes: 6 additions & 1 deletion asset/plugin/explorer/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ services:
image_tar:
amd64: asset/plugin/explorer/image-amd64.tar
arm64: asset/plugin/explorer/image-arm64.tar
arm: asset/plugin/explorer/image-arm.tar
arm: asset/plugin/explorer/image-arm.tar
external:
volumes:
#{{- range $key, $val := .explorer.External.Volumes}}
- {{ $val }}
#{{- end}}
3 changes: 3 additions & 0 deletions asset/static/1058.cb2cf0a7.async.js

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

Loading