Skip to content

Commit

Permalink
try to remove all kubernetes stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
hanjoosten committed Jan 8, 2025
1 parent 890a51a commit 694aff2
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 142 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.191.0/containers/typescript-node
{
"name": "Node.js & TypeScript",
"name": "Node.js & TypeScript2",
"build": {
"dockerfile": "Dockerfile",
"args": {
Expand Down
58 changes: 0 additions & 58 deletions assets/prototype-template.yaml

This file was deleted.

27 changes: 18 additions & 9 deletions src/commands/generateFunctionalSpecCommand.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
import { config, fileUtils, terminalUtils } from '../utils';
import { terminalBuilder } from '../builders';

export class generateFunctionalSpecCommand implements ICommand {
export class generateFunctionalSpecCommand implements ICommand {
static commandName: string = "extension.generateFunctionalSpec";

private builder : terminalBuilder = new terminalBuilder();
private builder: terminalBuilder = new terminalBuilder();

RunCommand() {
if(config.mainScriptSetting === undefined || config.folderSetting === undefined)
if (config.mainScriptSetting === undefined) {
console.error("Main script not set in settings");
return
};
console.info("Script setting: " + config.mainScriptSetting);

if (config.mainScriptSetting === undefined || config.folderSetting === undefined) {
console.error("Folder not set in settings");
return;

};
console.info("Folder setting: " + config.folderSetting);

const mainScriptPath: string = fileUtils.generateWorkspacePath([config.folderSetting, config.mainScriptSetting]);

const terminal = this.builder.setName("Ampersand generate functional spec")
.setWorkingDir(['ampersand'])
.getTerminal();
.setWorkingDir(['ampersand'])
.getTerminal();

terminalUtils.RunCommandsInExistingTerminal(terminal,
[`ampersand documentation --no-text --format docx ${mainScriptPath}`,
`ampersand documentation ${mainScriptPath} --format docx --no-graphics --language=NL --ConceptualAnalysis --verbosity debug`],
[`ampersand documentation --no-text --format docx ${mainScriptPath}`,
`ampersand documentation ${mainScriptPath} --format docx --no-graphics --language=NL --ConceptualAnalysis --verbosity debug`],
);
}
}
69 changes: 23 additions & 46 deletions src/commands/generatePrototypeCommand.ts
Original file line number Diff line number Diff line change
@@ -1,78 +1,55 @@
import { fileUtils, terminalUtils } from "../utils";
import * as vscode from 'vscode';
import { terminalBuilder } from "../builders/terminalBuilder";
import { manifest } from '../models/manifest';

export class generatePrototypeCommand implements ICommand {
static commandName: string = "extension.generatePrototype";

static portForwardTerminal: vscode.Terminal | undefined = undefined;
private builder : terminalBuilder = new terminalBuilder();
private builder: terminalBuilder = new terminalBuilder();

private manifestFile : manifest;
async RunCommand() {
this.tryKillPortForwardedProcessAndTerminal();

constructor(context: vscode.ExtensionContext)
{
this.manifestFile = new manifest(context.extensionPath);
}

async RunCommand()
{
this.tryKillPortForwardedProcessAndTerminal();

const data = await vscode.workspace.fs.readFile(this.manifestFile.templateFileUri);
this.replaceMarkers(data);
}

private async tryKillPortForwardedProcessAndTerminal()
{
if(generatePrototypeCommand.portForwardTerminal === undefined)
private async tryKillPortForwardedProcessAndTerminal() {
if (generatePrototypeCommand.portForwardTerminal === undefined)
return;

const buildTerminal = this.builder.setName("Cleanup")
.setVisibility(false)
.getTerminal();
.setVisibility(false)
.getTerminal();

//get the processID from the terminal that needs to be killed
const terminalToKillPID = await generatePrototypeCommand.portForwardTerminal.processId;

terminalUtils.RunCommandsInExistingTerminal(buildTerminal,
[`PID=$(ps -ef | grep 'kubectl port-forward' | grep -v grep | awk '{print $2}')`,
`kill $PID`,
(`kill -9 ${terminalToKillPID}`)]);
`kill $PID`,
(`kill -9 ${terminalToKillPID}`)]);

//Get own terminal PID to kill it later
const killerTerminalPID = await buildTerminal.processId;

//Kill self to cleanup
terminalUtils.RunCommandsInExistingTerminal(buildTerminal,[(`kill -9 ${killerTerminalPID}`)]);
}

private async replaceMarkers(data: Uint8Array)
{
const newData: Uint8Array = fileUtils.replaceMarkers(data, new Map<string, string>(
[
['{{zipFileContent}}', this.manifestFile.encodedZipContent],
['{{mainScript}}', this.manifestFile.encodedMainScript]
]
));
//Kill self to cleanup
terminalUtils.RunCommandsInExistingTerminal(buildTerminal, [(`kill -9 ${killerTerminalPID}`)]);
}

await vscode.workspace.fs.writeFile(this.manifestFile.fileUri, newData);
private async replaceMarkers(data: Uint8Array) {
this.runPrototypeCommand();
}

private runPrototypeCommand()
{
private runPrototypeCommand() {
const deployment: string = 'prototype';
const service: string = 'prototype';
generatePrototypeCommand.portForwardTerminal = this.builder.setName("Run prototype in minikube")
.getTerminal();
const service: string = 'prototype';

generatePrototypeCommand.portForwardTerminal = this.builder.setName("Run prototype")
.getTerminal();
generatePrototypeCommand.portForwardTerminal.show();

terminalUtils.RunCommandsInExistingTerminal(generatePrototypeCommand.portForwardTerminal,
[`kubectl apply -f ${this.manifestFile.fileUri.fsPath}`,
`kubectl rollout status deployment/${deployment} --timeout=300s`,
`kubectl port-forward svc/${service} -n default 8000:80`,]);
[`docker compose up -d --build`]);
}
}
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function activate(context: vscode.ExtensionContext) {
watcherUtils.setupLastRunningWatcher(context);

pushDisposable(context, generatePrototypeCommand.commandName, () =>
new generatePrototypeCommand(context).RunCommand()
new generatePrototypeCommand().RunCommand()
);
pushDisposable(context, generateAtlasCommand.commandName, () =>
new generateAtlasCommand().RunCommand()
Expand Down
2 changes: 0 additions & 2 deletions src/models/index.ts

This file was deleted.

25 changes: 0 additions & 25 deletions src/models/manifest.ts

This file was deleted.

0 comments on commit 694aff2

Please sign in to comment.