mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-09-23 16:00:52 +00:00
feat: Node runtime environment supports configuring whether to install node_modules. (#13147)
This commit is contained in:
@@ -28,7 +28,7 @@ type RuntimeCreate struct {
|
||||
}
|
||||
|
||||
type NodeConfig struct {
|
||||
Install bool `json:"install"`
|
||||
Install *bool `json:"install"`
|
||||
Clean bool `json:"clean"`
|
||||
ExposedPorts []ExposedPort `json:"exposedPorts"`
|
||||
Environments []Environment `json:"environments"`
|
||||
|
||||
@@ -185,7 +185,6 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, e
|
||||
if !fileOp.Stat(create.CodeDir) {
|
||||
return nil, buserr.New("ErrPathNotFound")
|
||||
}
|
||||
create.Install = true
|
||||
for _, export := range create.ExposedPorts {
|
||||
hostPorts = append(hostPorts, strconv.Itoa(export.HostPort))
|
||||
if err := checkPortExistWithProtocol(export.HostPort, export.Protocol); err != nil {
|
||||
@@ -696,7 +695,7 @@ func (r *RuntimeService) Update(req request.RuntimeUpdate) error {
|
||||
Version: req.Version,
|
||||
Remark: req.Remark,
|
||||
NodeConfig: request.NodeConfig{
|
||||
Install: true,
|
||||
Install: req.Install,
|
||||
ExposedPorts: req.ExposedPorts,
|
||||
Environments: req.Environments,
|
||||
Volumes: req.Volumes,
|
||||
|
||||
@@ -68,6 +68,10 @@ func handleRuntime(create request.RuntimeCreate, runtime *model.Runtime, fileOp
|
||||
return
|
||||
}
|
||||
|
||||
func runtimeNodeShouldInstallDependencies(create request.RuntimeCreate) bool {
|
||||
return create.NodeConfig.Install == nil || *create.NodeConfig.Install
|
||||
}
|
||||
|
||||
func isPathInsideOrEqual(baseDir, targetDir string) bool {
|
||||
baseAbs := resolveRuntimePath(baseDir)
|
||||
targetAbs := resolveRuntimePath(targetDir)
|
||||
@@ -502,7 +506,7 @@ func handleParams(create request.RuntimeCreate, projectDir string) (composeConte
|
||||
case constant.RuntimeNode:
|
||||
create.Params["CODE_DIR"] = create.CodeDir
|
||||
create.Params["NODE_VERSION"] = create.Version
|
||||
if create.NodeConfig.Install {
|
||||
if runtimeNodeShouldInstallDependencies(create) {
|
||||
create.Params["RUN_INSTALL"] = "1"
|
||||
} else {
|
||||
create.Params["RUN_INSTALL"] = "0"
|
||||
|
||||
@@ -61,6 +61,7 @@ export namespace Runtime {
|
||||
codeDir?: string;
|
||||
port?: number;
|
||||
taskID?: string;
|
||||
install?: boolean;
|
||||
exposedPorts?: ExposedPort[];
|
||||
environments?: Environment[];
|
||||
volumes?: Volume[];
|
||||
@@ -99,6 +100,7 @@ export namespace Runtime {
|
||||
appID?: number;
|
||||
version?: string;
|
||||
rebuild?: boolean;
|
||||
install?: boolean;
|
||||
}
|
||||
|
||||
export interface RuntimeDelete {
|
||||
|
||||
@@ -33,6 +33,9 @@
|
||||
<el-option v-if="hasPnpm" label="pnpm" value="pnpm"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('commons.button.install') + ' node_modules'" prop="install">
|
||||
<el-switch v-model="runtime.install" />
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('runtime.imageSource')" prop="source">
|
||||
<el-select v-model="runtime.source" filterable allow-create default-first-option>
|
||||
<el-option
|
||||
@@ -98,6 +101,7 @@ const initData = (type: string) => ({
|
||||
type: type,
|
||||
resource: 'appstore',
|
||||
rebuild: false,
|
||||
install: true,
|
||||
codeDir: '/',
|
||||
port: 4004,
|
||||
source: 'https://registry.npmjs.org/',
|
||||
@@ -233,6 +237,7 @@ const getRuntime = async (id: number) => {
|
||||
codeDir: data.codeDir,
|
||||
port: data.port,
|
||||
remark: data.remark,
|
||||
install: data.params['RUN_INSTALL'] !== '0',
|
||||
});
|
||||
runtime.exposedPorts = data.exposedPorts || [];
|
||||
runtime.environments = data.environments || [];
|
||||
|
||||
Reference in New Issue
Block a user