diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 34795fc..aefe940 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -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": { diff --git a/assets/prototype-template.yaml b/assets/prototype-template.yaml deleted file mode 100644 index b04cb42..0000000 --- a/assets/prototype-template.yaml +++ /dev/null @@ -1,58 +0,0 @@ ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: prototype - labels: - app: prototype - container-image: student-prototype -spec: - replicas: 1 - selector: - matchLabels: - app: prototype - template: - metadata: - labels: - app: prototype - container-image: student-prototype - spec: - containers: - - name: prototype - image: ampersandtarski/rap4-student-prototype:dev-zip - env: - - name: AMPERSAND_DBHOST - value: ampersand-db - - name: AMPERSAND_DBNAME - value: prototype - - name: AMPERSAND_DEBUG_MODE - value: "true" - - name: AMPERSAND_LOG_CONFIG - value: logging.yaml - - name: AMPERSAND_PRODUCTION_MODE - value: "false" - - name: AMPERSAND_SERVER_URL - value: https://localhost - - name: RAP_DEPLOYMENT - value: Kubernetes - - name: RAP_KUBERNETES_NAMESPACE - value: ampersand - envFrom: - - secretRef: - name: db-secrets - ports: - - containerPort: 80 - command: ["bash", "/run-student-prototype.sh"] - args: [{{zipFileContent}}, {{mainScript}}] ---- -# student-prototype user service -apiVersion: v1 -kind: Service -metadata: - name: prototype -spec: - type: ClusterIP - ports: - - port: 80 - selector: - app: prototype diff --git a/src/commands/generateFunctionalSpecCommand.ts b/src/commands/generateFunctionalSpecCommand.ts index 3f68638..c8d9912 100644 --- a/src/commands/generateFunctionalSpecCommand.ts +++ b/src/commands/generateFunctionalSpecCommand.ts @@ -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`], ); } } \ No newline at end of file diff --git a/src/commands/generatePrototypeCommand.ts b/src/commands/generatePrototypeCommand.ts index 70ff135..c4f6bdd 100644 --- a/src/commands/generatePrototypeCommand.ts +++ b/src/commands/generatePrototypeCommand.ts @@ -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( - [ - ['{{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`]); } } \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index f33f534..d06fe4d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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() diff --git a/src/models/index.ts b/src/models/index.ts deleted file mode 100644 index 458f6a3..0000000 --- a/src/models/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./terminal"; -export * from "./manifest"; \ No newline at end of file diff --git a/src/models/manifest.ts b/src/models/manifest.ts deleted file mode 100644 index b369d08..0000000 --- a/src/models/manifest.ts +++ /dev/null @@ -1,25 +0,0 @@ -import * as vscode from 'vscode'; -import { config, fileUtils, terminalUtils, zipUtils } from "../utils"; -import * as path from 'path'; - -export class manifest{ - private readonly _encodedZipContent: string | undefined; - - public get encodedZipContent(): string { - return (this._encodedZipContent === undefined) ? "" : this._encodedZipContent; - } - - public readonly encodedMainScript: string; - public readonly templateFileUri: vscode.Uri; - public readonly fileUri: vscode.Uri; - - constructor(extensionPath: string) - { - this._encodedZipContent = zipUtils.zipFolder(extensionPath); - this.encodedMainScript = btoa(config.mainScriptSetting as string); - this.templateFileUri = vscode.Uri.file(path.join(extensionPath, 'assets', 'prototype-template.yaml')); - - const fileName = fileUtils.generateWorkspacePath(['ampersand', 'prototype.yaml']); - this.fileUri = vscode.Uri.file(fileName) - } -} \ No newline at end of file