stream logs through standard input and new remote client cli command

This commit is contained in:
Frostebite 2023-06-05 21:05:49 +01:00
parent fdde0dec58
commit 88fa5d247c
5 changed files with 18 additions and 3 deletions

BIN
dist/index.js generated vendored

Binary file not shown.

BIN
dist/index.js.map generated vendored

Binary file not shown.

View File

@ -42,6 +42,14 @@ class Kubernetes implements ProviderInterface {
CloudRunnerLogger.log('Loaded default Kubernetes configuration for this environment'); CloudRunnerLogger.log('Loaded default Kubernetes configuration for this environment');
} }
async PushLogUpdate(logs: string) {
const body: k8s.V1ConfigMap = new k8s.V1ConfigMap();
body.data = {};
body.data['logs'] = logs;
body.metadata = { name: `${this.jobName}-logs` };
await this.kubeClient.createNamespacedConfigMap(this.namespace, body);
}
async listResources(): Promise<ProviderResource[]> { async listResources(): Promise<ProviderResource[]> {
const pods = await this.kubeClient.listNamespacedPod(this.namespace); const pods = await this.kubeClient.listNamespacedPod(this.namespace);
const serviceAccounts = await this.kubeClient.listNamespacedServiceAccount(this.namespace); const serviceAccounts = await this.kubeClient.listNamespacedServiceAccount(this.namespace);

View File

@ -82,7 +82,7 @@ export class RemoteClient {
await RemoteClient.runCustomHookFiles(`after-build`); await RemoteClient.runCustomHookFiles(`after-build`);
RemoteClientLogger.printCollectedLogs(); await RemoteClientLogger.printCollectedLogs();
return new Promise((result) => result(``)); return new Promise((result) => result(``));
} }

View File

@ -2,6 +2,8 @@ import CloudRunnerLogger from '../services/core/cloud-runner-logger';
import fs from 'node:fs'; import fs from 'node:fs';
import path from 'node:path'; import path from 'node:path';
import CloudRunner from '../cloud-runner'; import CloudRunner from '../cloud-runner';
import CloudRunnerOptions from '../options/cloud-runner-options';
import Kubernetes from '../providers/k8s';
export class RemoteClientLogger { export class RemoteClientLogger {
private static get LogFilePath() { private static get LogFilePath() {
@ -32,8 +34,13 @@ export class RemoteClientLogger {
} }
} }
public static printCollectedLogs() { public static async printCollectedLogs() {
if (CloudRunnerOptions.providerStrategy !== 'k8s') {
return;
}
CloudRunnerLogger.log(`Collected Logs`); CloudRunnerLogger.log(`Collected Logs`);
CloudRunnerLogger.log(fs.readFileSync(RemoteClientLogger.LogFilePath).toString()); const logs = fs.readFileSync(RemoteClientLogger.LogFilePath).toString();
CloudRunnerLogger.log(logs);
await Kubernetes.Instance.PushLogUpdate(logs);
} }
} }