mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-02-08 01:20:07 +08:00
feat: Node.js 增加 pnpm 支持 (#5225)
This commit is contained in:
parent
bd91c88357
commit
90bcf464d3
@ -4,7 +4,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/utils/files"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@ -12,10 +14,6 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/backend/utils/files"
|
|
||||||
"gopkg.in/yaml.v3"
|
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/backend/utils/env"
|
"github.com/1Panel-dev/1Panel/backend/utils/env"
|
||||||
"github.com/1Panel-dev/1Panel/backend/utils/nginx"
|
"github.com/1Panel-dev/1Panel/backend/utils/nginx"
|
||||||
@ -703,15 +701,6 @@ func (a *AppInstallService) GetParams(id uint) (*response.AppConfig, error) {
|
|||||||
return &res, nil
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func measureExecutionTime(name string, fn func() error) error {
|
|
||||||
start := time.Now() // 记录开始时间
|
|
||||||
err := fn() // 执行函数
|
|
||||||
elapsed := time.Since(start) // 计算执行时间
|
|
||||||
|
|
||||||
fmt.Printf("%s took %s\n", name, elapsed) // 输出函数名和执行时间
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func syncAppInstallStatus(appInstall *model.AppInstall) error {
|
func syncAppInstallStatus(appInstall *model.AppInstall) error {
|
||||||
if appInstall.Status == constant.Installing || appInstall.Status == constant.Rebuilding || appInstall.Status == constant.Upgrading {
|
if appInstall.Status == constant.Installing || appInstall.Status == constant.Rebuilding || appInstall.Status == constant.Upgrading {
|
||||||
return nil
|
return nil
|
||||||
|
@ -2,19 +2,13 @@ package docker
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/compose-spec/compose-go/v2/loader"
|
||||||
|
"github.com/compose-spec/compose-go/v2/types"
|
||||||
|
"github.com/docker/compose/v2/pkg/api"
|
||||||
|
"github.com/joho/godotenv"
|
||||||
"path"
|
"path"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/compose-spec/compose-go/v2/loader"
|
|
||||||
"github.com/compose-spec/compose-go/v2/types"
|
|
||||||
"github.com/docker/cli/cli/command"
|
|
||||||
"github.com/docker/cli/cli/flags"
|
|
||||||
"github.com/docker/compose/v2/pkg/api"
|
|
||||||
"github.com/docker/compose/v2/pkg/compose"
|
|
||||||
"github.com/docker/docker/client"
|
|
||||||
"github.com/joho/godotenv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ComposeService struct {
|
type ComposeService struct {
|
||||||
@ -22,47 +16,6 @@ type ComposeService struct {
|
|||||||
project *types.Project
|
project *types.Project
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpComposeProject(project *types.Project) error {
|
|
||||||
for i, s := range project.Services {
|
|
||||||
s.CustomLabels = map[string]string{
|
|
||||||
api.ProjectLabel: project.Name,
|
|
||||||
api.ServiceLabel: s.Name,
|
|
||||||
api.VersionLabel: api.ComposeVersion,
|
|
||||||
api.WorkingDirLabel: project.WorkingDir,
|
|
||||||
api.ConfigFilesLabel: strings.Join(project.ComposeFiles, ","),
|
|
||||||
api.OneoffLabel: "False",
|
|
||||||
}
|
|
||||||
project.Services[i] = s
|
|
||||||
}
|
|
||||||
|
|
||||||
apiClient, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var ops []command.CLIOption
|
|
||||||
ops = append(ops, command.WithAPIClient(apiClient), command.WithDefaultContextStoreConfig())
|
|
||||||
cli, err := command.NewDockerCli(ops...)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
cliOp := flags.NewClientOptions()
|
|
||||||
if err = cli.Initialize(cliOp); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
service := compose.NewComposeService(cli)
|
|
||||||
composeService := ComposeService{Service: service}
|
|
||||||
|
|
||||||
return composeService.Up(context.Background(), project, api.UpOptions{
|
|
||||||
Create: api.CreateOptions{
|
|
||||||
Timeout: getComposeTimeout(),
|
|
||||||
},
|
|
||||||
Start: api.StartOptions{
|
|
||||||
WaitTimeout: *getComposeTimeout(),
|
|
||||||
Wait: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetComposeProject(projectName, workDir string, yml []byte, env []byte, skipNormalization bool) (*types.Project, error) {
|
func GetComposeProject(projectName, workDir string, yml []byte, env []byte, skipNormalization bool) (*types.Project, error) {
|
||||||
var configFiles []types.ConfigFile
|
var configFiles []types.ConfigFile
|
||||||
configFiles = append(configFiles, types.ConfigFile{
|
configFiles = append(configFiles, types.ConfigFile{
|
||||||
@ -93,11 +46,6 @@ func GetComposeProject(projectName, workDir string, yml []byte, env []byte, skip
|
|||||||
return project, nil
|
return project, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getComposeTimeout() *time.Duration {
|
|
||||||
timeout := time.Minute * time.Duration(10)
|
|
||||||
return &timeout
|
|
||||||
}
|
|
||||||
|
|
||||||
type ComposeProject struct {
|
type ComposeProject struct {
|
||||||
Version string
|
Version string
|
||||||
Services map[string]Service `yaml:"services"`
|
Services map[string]Service `yaml:"services"`
|
||||||
|
@ -3,6 +3,7 @@ package postgresql
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -42,7 +43,7 @@ func NewPostgresqlClient(conn client.DBInfo) (PostgresqlClient, error) {
|
|||||||
if err := db.PingContext(ctx); err != nil {
|
if err := db.PingContext(ctx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if ctx.Err() == context.DeadlineExceeded {
|
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
|
||||||
return nil, buserr.New(constant.ErrExecTimeOut)
|
return nil, buserr.New(constant.ErrExecTimeOut)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,6 +165,7 @@
|
|||||||
<el-select v-model="runtime.params['PACKAGE_MANAGER']">
|
<el-select v-model="runtime.params['PACKAGE_MANAGER']">
|
||||||
<el-option label="npm" value="npm"></el-option>
|
<el-option label="npm" value="npm"></el-option>
|
||||||
<el-option label="yarn" value="yarn"></el-option>
|
<el-option label="yarn" value="yarn"></el-option>
|
||||||
|
<el-option v-if="hasPnpm" label="pnpm" value="pnpm"></el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item :label="$t('runtime.imageSource')" prop="source">
|
<el-form-item :label="$t('runtime.imageSource')" prop="source">
|
||||||
@ -206,7 +207,7 @@ import { Rules, checkNumberRange } from '@/global/form-rules';
|
|||||||
import i18n from '@/lang';
|
import i18n from '@/lang';
|
||||||
import { MsgError, MsgSuccess } from '@/utils/message';
|
import { MsgError, MsgSuccess } from '@/utils/message';
|
||||||
import { FormInstance } from 'element-plus';
|
import { FormInstance } from 'element-plus';
|
||||||
import { reactive, ref, watch } from 'vue';
|
import { computed, reactive, ref, watch } from 'vue';
|
||||||
import DrawerHeader from '@/components/drawer-header/index.vue';
|
import DrawerHeader from '@/components/drawer-header/index.vue';
|
||||||
|
|
||||||
interface OperateRrops {
|
interface OperateRrops {
|
||||||
@ -263,6 +264,13 @@ const rules = ref<any>({
|
|||||||
const scripts = ref<Runtime.NodeScripts[]>([]);
|
const scripts = ref<Runtime.NodeScripts[]>([]);
|
||||||
const em = defineEmits(['close']);
|
const em = defineEmits(['close']);
|
||||||
|
|
||||||
|
const hasPnpm = computed(() => {
|
||||||
|
if (runtime.version == undefined) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return parseFloat(runtime.version) > 18;
|
||||||
|
});
|
||||||
|
|
||||||
const imageSources = [
|
const imageSources = [
|
||||||
{
|
{
|
||||||
label: i18n.global.t('runtime.default'),
|
label: i18n.global.t('runtime.default'),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user