Skip to content

Commit

Permalink
3352 add platform option into the build process on serverless function (
Browse files Browse the repository at this point in the history
redhat-developer#3427)

* added context menu for build config

Signed-off-by: msivasubramaniaan <msivasub@redhat.com>
  • Loading branch information
msivasubramaniaan authored Oct 13, 2023
1 parent 66ef49f commit 257c4f8
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 22 deletions.
40 changes: 33 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,13 @@
"icon": "$(refresh)"
},
{
"command": "openshift.Serverless.build",
"title": "Build",
"command": "openshift.Serverless.baseBuild",
"title": "Base Build",
"category": "OpenShift"
},
{
"command": "openshift.Serverless.s2iBuild",
"title": "S2I Build",
"category": "OpenShift"
},
{
Expand Down Expand Up @@ -883,6 +888,10 @@
{
"id": "serverlessfunction/removeConfig",
"label": "Remove"
},
{
"id": "serverlessfunction/buildConfig",
"label": "Build Configuration"
}
],
"viewsContainers": {
Expand Down Expand Up @@ -1189,7 +1198,11 @@
"when": "false"
},
{
"command": "openshift.Serverless.build",
"command": "openshift.Serverless.baseBuild",
"when": "false"
},
{
"command": "openshift.Serverless.s2iBuild",
"when": "false"
},
{
Expand Down Expand Up @@ -1365,6 +1378,18 @@
"group": "c1@3"
}
],
"serverlessfunction/buildConfig": [
{
"command": "openshift.Serverless.baseBuild",
"when": "view == openshiftServerlessFunctionsView && viewItem =~ /^(localFunctions|localFunctionsWithBuild|localDeployFunctions)$/",
"group": "c1@0"
},
{
"command": "openshift.Serverless.s2iBuild",
"when": "view == openshiftServerlessFunctionsView && viewItem =~ /^(localFunctions|localFunctionsWithBuild|localDeployFunctions)$/",
"group": "c1@1"
}
],
"view/item/context": [
{
"command": "openshift.sandbox.signup",
Expand Down Expand Up @@ -1624,10 +1649,6 @@
"command": "openshift.resource.openInDeveloperConsole",
"when": "view == openshiftProjectExplorer && viewItem == openshift.k8sObject && isOpenshiftCluster || openshift.k8sObject.helm && isOpenshiftCluster"
},
{
"command": "openshift.Serverless.build",
"when": "view == openshiftServerlessFunctionsView && viewItem =~ /^(localFunctions|localFunctionsWithBuild|localDeployFunctions)$/"
},
{
"command": "openshift.Serverless.buildAndRun",
"when": "view == openshiftServerlessFunctionsView && viewItem =~ /^(localFunctions|localFunctionsWithBuild|localDeployFunctions)$/"
Expand Down Expand Up @@ -1662,6 +1683,11 @@
"when": "view == openshiftServerlessFunctionsView && viewItem =~ /^(localFunctionsWithBuild|localDeployFunctions)$/",
"group": "c1@2"
},
{
"submenu": "serverlessfunction/buildConfig",
"when": "view == openshiftServerlessFunctionsView && viewItem =~ /^(localFunctions|localFunctionsWithBuild|localDeployFunctions)$/",
"group": "c1@2"
},
{
"command": "openshift.component.commands.command.run",
"when": "view == openshiftComponentsView && viewItem =~ /openshift\\-component-command.*\\.dev-run.*/",
Expand Down
5 changes: 3 additions & 2 deletions src/serverlessFunction/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ export class ServerlessCommand {
]);
}

static buildFunction(location: string, image: string, isOpenShiftCluster: boolean): CommandText {
static buildFunction(location: string, builder:string, image: string, isOpenShiftCluster: boolean): CommandText {
const commandText = new CommandText('func', 'build', [
new CommandOption('-p', location),
new CommandOption('--path', location),
new CommandOption('--builder', builder),
new CommandOption('-i', image),
new CommandOption('-v')
]);
Expand Down
22 changes: 12 additions & 10 deletions src/serverlessFunction/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Progress } from '../util/progress';
import { OpenShiftTerminalApi, OpenShiftTerminalManager } from '../webview/openshift-terminal/openShiftTerminal';
import { ServerlessCommand, Utils } from './commands';
import { multiStep } from './multiStepInput';
import { FunctionContent, FunctionObject, FunctionView, InvokeFunction } from './types';
import { FunctionContent, FunctionObject, InvokeFunction } from './types';

export class Functions {

Expand Down Expand Up @@ -47,7 +47,7 @@ export class Functions {
}
}

public async build(context: FunctionObject, view: FunctionView): Promise<void> {
public async build(context: FunctionObject, s2iBuild: boolean): Promise<void> {
const existingTerminal: OpenShiftTerminalApi = this.buildTerminalMap.get(`build-${context.folderURI.fsPath}`);

if (existingTerminal) {
Expand All @@ -63,31 +63,33 @@ export class Functions {
});

// start new build
await this.buildProcess(context, view);
await this.buildProcess(context, s2iBuild);
}
});
} else {
await this.buildProcess(context, view);
await this.buildProcess(context, s2iBuild);
}
}

private async buildProcess(context: FunctionObject, view: FunctionView) {
private async buildProcess(context: FunctionObject, s2iBuild: boolean) {
const isOpenShiftCluster = await Oc.Instance.isOpenShiftCluster();
const buildImage = await this.getImage(context.folderURI);
const terminalKey = `build-${context.folderURI.fsPath}`;
await this.buildTerminal(context, s2iBuild ? 's2i' : 'pack',buildImage, isOpenShiftCluster, terminalKey);
}

private async buildTerminal(context: FunctionObject, builder: string, buildImage: string, isOpenShiftCluster: boolean, terminalKey: string) {
const terminal = await OpenShiftTerminalManager.getInstance().createTerminal(
ServerlessCommand.buildFunction(context.folderURI.fsPath, buildImage, isOpenShiftCluster),
ServerlessCommand.buildFunction(context.folderURI.fsPath, builder, buildImage, isOpenShiftCluster),
`Build ${context.name}`,
context.folderURI.fsPath,
process.env,
{
onExit: () => {
this.buildTerminalMap.delete(terminalKey)
this.buildTerminalMap.delete(terminalKey);
}
}
);

this.buildTerminalMap.set(terminalKey, terminal);
}

Expand Down Expand Up @@ -196,7 +198,7 @@ export class Functions {
await OpenShiftTerminalManager.getInstance().createTerminal(
ServerlessCommand.invokeFunction(invokeFunData),
`Invoke ${functionName}`,
);
);
}

public async config(title: string, context: FunctionObject, mode: string, isAdd = true) {
Expand Down Expand Up @@ -228,7 +230,7 @@ export class Functions {
return null;
}
openshiftTerminalApi.sendText(`${userName}\n`);
await new Promise(resolve => {setTimeout(resolve, 100)});
await new Promise(resolve => { setTimeout(resolve, 100) });
openshiftTerminalApi.sendText(`${userPassword}\n`);
}

Expand Down
11 changes: 8 additions & 3 deletions src/serverlessFunction/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,14 @@ export class ServerlessFunctionView implements TreeDataProvider<ExplorerItem>, D
ServerlessFunctionView.getInstance().refresh(target);
}

@vsCommand('openshift.Serverless.build')
static async buildFunction(context: FunctionObject) {
await Functions.getInstance().build(context, this);
@vsCommand('openshift.Serverless.baseBuild')
static async baseBuildFunction(context: FunctionObject) {
await Functions.getInstance().build(context, false);
}

@vsCommand('openshift.Serverless.s2iBuild')
static async s2iBuildFunction(context: FunctionObject) {
await Functions.getInstance().build(context, true);
}

@vsCommand('openshift.Serverless.buildAndRun')
Expand Down

0 comments on commit 257c4f8

Please sign in to comment.