feat: Node.js 增加 pnpm 支持 (#5225)

This commit is contained in:
zhengkunwang 2024-05-30 17:39:15 +08:00 committed by GitHub
parent bd91c88357
commit 90bcf464d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 17 additions and 71 deletions

View file

@ -4,7 +4,9 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/1Panel-dev/1Panel/backend/utils/files"
"github.com/docker/docker/api/types"
"gopkg.in/yaml.v3"
"math"
"os"
"path"
@ -12,10 +14,6 @@ import (
"sort"
"strconv"
"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/nginx"
@ -703,15 +701,6 @@ func (a *AppInstallService) GetParams(id uint) (*response.AppConfig, error) {
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 {
if appInstall.Status == constant.Installing || appInstall.Status == constant.Rebuilding || appInstall.Status == constant.Upgrading {
return nil

View file

@ -2,19 +2,13 @@ package docker
import (
"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"
"regexp"
"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 {
@ -22,47 +16,6 @@ type ComposeService struct {
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) {
var 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
}
func getComposeTimeout() *time.Duration {
timeout := time.Minute * time.Duration(10)
return &timeout
}
type ComposeProject struct {
Version string
Services map[string]Service `yaml:"services"`

View file

@ -3,6 +3,7 @@ package postgresql
import (
"context"
"database/sql"
"errors"
"fmt"
"time"
@ -42,7 +43,7 @@ func NewPostgresqlClient(conn client.DBInfo) (PostgresqlClient, error) {
if err := db.PingContext(ctx); err != nil {
return nil, err
}
if ctx.Err() == context.DeadlineExceeded {
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
return nil, buserr.New(constant.ErrExecTimeOut)
}

View file

@ -165,6 +165,7 @@
<el-select v-model="runtime.params['PACKAGE_MANAGER']">
<el-option label="npm" value="npm"></el-option>
<el-option label="yarn" value="yarn"></el-option>
<el-option v-if="hasPnpm" label="pnpm" value="pnpm"></el-option>
</el-select>
</el-form-item>
<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 { MsgError, MsgSuccess } from '@/utils/message';
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';
interface OperateRrops {
@ -263,6 +264,13 @@ const rules = ref<any>({
const scripts = ref<Runtime.NodeScripts[]>([]);
const em = defineEmits(['close']);
const hasPnpm = computed(() => {
if (runtime.version == undefined) {
return false;
}
return parseFloat(runtime.version) > 18;
});
const imageSources = [
{
label: i18n.global.t('runtime.default'),