pull/437/head
Frostebite 2022-10-17 17:36:22 +01:00
parent 7c4df887c4
commit bc8208b484
3 changed files with 53 additions and 30 deletions

24
dist/index.js vendored
View File

@ -2888,13 +2888,8 @@ class Kubernetes {
this.secretName = `build-credentials-${buildGuid}`;
this.jobName = `unity-builder-job-${buildGuid}`;
this.containerName = `main`;
yield kubernetes_secret_1.default.createSecret(secrets, this.secretName, this.namespace, this.kubeClient);
const jobSpec = kubernetes_job_spec_factory_1.default.getJobSpec(commands, image, mountdir, workingdir, environment, secrets, this.buildGuid, this.buildParameters, this.secretName, this.pvcName, this.jobName, k8s);
cloud_runner_logger_1.default.log(`Build job secret created ${JSON.stringify(this.secretName, undefined, 4)}`);
const jobResult = yield this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
cloud_runner_logger_1.default.log(`Build job created ${JSON.stringify(jobResult.body.metadata, undefined, 4)}`);
yield new Promise((promise) => setTimeout(promise, 5000));
cloud_runner_logger_1.default.log('Job created');
yield this.createSecret(secrets);
yield this.createNamespacedJob(commands, image, mountdir, workingdir, environment, secrets);
this.setPodNameAndContainerName(yield Kubernetes.findPodFromJob(this.kubeClient, this.jobName, this.namespace));
cloud_runner_logger_1.default.log('Watching pod until running');
let output = '';
@ -2926,6 +2921,21 @@ class Kubernetes {
}
});
}
createSecret(secrets) {
return __awaiter(this, void 0, void 0, function* () {
yield kubernetes_secret_1.default.createSecret(secrets, this.secretName, this.namespace, this.kubeClient);
cloud_runner_logger_1.default.log(`Secret created`);
});
}
createNamespacedJob(commands, image, mountdir, workingdir, environment, secrets) {
return __awaiter(this, void 0, void 0, function* () {
const jobSpec = kubernetes_job_spec_factory_1.default.getJobSpec(commands, image, mountdir, workingdir, environment, secrets, this.buildGuid, this.buildParameters, this.secretName, this.pvcName, this.jobName, k8s);
yield this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
cloud_runner_logger_1.default.log(`Build job created`);
yield new Promise((promise) => setTimeout(promise, 5000));
cloud_runner_logger_1.default.log('Job created');
});
}
setPodNameAndContainerName(pod) {
var _a, _b, _c;
this.podName = ((_a = pod.metadata) === null || _a === void 0 ? void 0 : _a.name) || '';

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -99,28 +99,8 @@ class Kubernetes implements ProviderInterface {
this.secretName = `build-credentials-${buildGuid}`;
this.jobName = `unity-builder-job-${buildGuid}`;
this.containerName = `main`;
await KubernetesSecret.createSecret(secrets, this.secretName, this.namespace, this.kubeClient);
const jobSpec = KubernetesJobSpecFactory.getJobSpec(
commands,
image,
mountdir,
workingdir,
environment,
secrets,
this.buildGuid,
this.buildParameters,
this.secretName,
this.pvcName,
this.jobName,
k8s,
);
CloudRunnerLogger.log(`Build job secret created ${JSON.stringify(this.secretName, undefined, 4)}`);
const jobResult = await this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
CloudRunnerLogger.log(`Build job created ${JSON.stringify(jobResult.body.metadata, undefined, 4)}`);
await new Promise((promise) => setTimeout(promise, 5000));
CloudRunnerLogger.log('Job created');
await this.createSecret(secrets);
await this.createNamespacedJob(commands, image, mountdir, workingdir, environment, secrets);
this.setPodNameAndContainerName(await Kubernetes.findPodFromJob(this.kubeClient, this.jobName, this.namespace));
CloudRunnerLogger.log('Watching pod until running');
let output = '';
@ -157,6 +137,39 @@ class Kubernetes implements ProviderInterface {
}
}
private async createSecret(secrets: CloudRunnerSecret[]) {
await KubernetesSecret.createSecret(secrets, this.secretName, this.namespace, this.kubeClient);
CloudRunnerLogger.log(`Secret created`);
}
private async createNamespacedJob(
commands: string,
image: string,
mountdir: string,
workingdir: string,
environment: CloudRunnerEnvironmentVariable[],
secrets: CloudRunnerSecret[],
) {
const jobSpec = KubernetesJobSpecFactory.getJobSpec(
commands,
image,
mountdir,
workingdir,
environment,
secrets,
this.buildGuid,
this.buildParameters,
this.secretName,
this.pvcName,
this.jobName,
k8s,
);
await this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
CloudRunnerLogger.log(`Build job created`);
await new Promise((promise) => setTimeout(promise, 5000));
CloudRunnerLogger.log('Job created');
}
setPodNameAndContainerName(pod: k8s.V1Pod) {
this.podName = pod.metadata?.name || '';
this.containerName = pod.status?.containerStatuses?.[0].name || '';