Parameterize more of the K8s build
parent
52fe9fd9d0
commit
e75c489156
|
|
@ -1260,6 +1260,9 @@ const stream_1 = __webpack_require__(92413);
|
||||||
const async_wait_until_1 = __webpack_require__(41299);
|
const async_wait_until_1 = __webpack_require__(41299);
|
||||||
const kubernetes_storage_1 = __importDefault(__webpack_require__(38941));
|
const kubernetes_storage_1 = __importDefault(__webpack_require__(38941));
|
||||||
const base64 = __webpack_require__(85848);
|
const base64 = __webpack_require__(85848);
|
||||||
|
const repositoryFolder = 'repo';
|
||||||
|
const buildVolumeFolder = 'data';
|
||||||
|
// const cacheFolder = 'cache';
|
||||||
class Kubernetes {
|
class Kubernetes {
|
||||||
constructor(buildParameters, baseImage) {
|
constructor(buildParameters, baseImage) {
|
||||||
this.buildId = '';
|
this.buildId = '';
|
||||||
|
|
@ -1318,7 +1321,7 @@ class Kubernetes {
|
||||||
yield this.createSecret(defaultSecretsArray);
|
yield this.createSecret(defaultSecretsArray);
|
||||||
yield kubernetes_storage_1.default.createPersistentVolumeClaim(this.buildParameters, this.pvcName, this.kubeClient, this.namespace);
|
yield kubernetes_storage_1.default.createPersistentVolumeClaim(this.buildParameters, this.pvcName, this.kubeClient, this.namespace);
|
||||||
//run
|
//run
|
||||||
const jobSpec = this.getJobSpec(commands, image);
|
const jobSpec = this.getJobSpec(commands, image, mountdir, workingdir, environment);
|
||||||
core.info('Creating build job');
|
core.info('Creating build job');
|
||||||
yield this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
|
yield this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
|
||||||
core.info('Job created');
|
core.info('Job created');
|
||||||
|
|
@ -1385,45 +1388,8 @@ class Kubernetes {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
getJobSpec(command, image) {
|
getJobSpec(command, image, mountdir, workingDirectory, environment) {
|
||||||
const job = new k8s.V1Job();
|
environment.push(...[
|
||||||
job.apiVersion = 'batch/v1';
|
|
||||||
job.kind = 'Job';
|
|
||||||
job.metadata = {
|
|
||||||
name: this.jobName,
|
|
||||||
labels: {
|
|
||||||
app: 'unity-builder',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
job.spec = {
|
|
||||||
template: {
|
|
||||||
spec: {
|
|
||||||
volumes: [
|
|
||||||
{
|
|
||||||
name: 'data',
|
|
||||||
persistentVolumeClaim: {
|
|
||||||
claimName: this.pvcName,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'credentials',
|
|
||||||
secret: {
|
|
||||||
secretName: this.secretName,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
containers: [
|
|
||||||
{
|
|
||||||
name: 'main',
|
|
||||||
image,
|
|
||||||
command,
|
|
||||||
resources: {
|
|
||||||
requests: {
|
|
||||||
memory: this.buildParameters.remoteBuildMemory,
|
|
||||||
cpu: this.buildParameters.remoteBuildCpu,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
env: [
|
|
||||||
{
|
{
|
||||||
name: 'GITHUB_SHA',
|
name: 'GITHUB_SHA',
|
||||||
value: this.buildId,
|
value: this.buildId,
|
||||||
|
|
@ -1476,11 +1442,51 @@ class Kubernetes {
|
||||||
name: 'ANDROID_KEYALIAS_NAME',
|
name: 'ANDROID_KEYALIAS_NAME',
|
||||||
value: this.buildParameters.androidKeyaliasName,
|
value: this.buildParameters.androidKeyaliasName,
|
||||||
},
|
},
|
||||||
|
]);
|
||||||
|
const job = new k8s.V1Job();
|
||||||
|
job.apiVersion = 'batch/v1';
|
||||||
|
job.kind = 'Job';
|
||||||
|
job.metadata = {
|
||||||
|
name: this.jobName,
|
||||||
|
labels: {
|
||||||
|
app: 'unity-builder',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
job.spec = {
|
||||||
|
backoffLimit: 1,
|
||||||
|
template: {
|
||||||
|
spec: {
|
||||||
|
volumes: [
|
||||||
|
{
|
||||||
|
name: 'buildMount',
|
||||||
|
persistentVolumeClaim: {
|
||||||
|
claimName: this.pvcName,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'credentials',
|
||||||
|
secret: {
|
||||||
|
secretName: this.secretName,
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
|
containers: [
|
||||||
|
{
|
||||||
|
name: 'main',
|
||||||
|
image,
|
||||||
|
command,
|
||||||
|
workingDir: workingDirectory,
|
||||||
|
resources: {
|
||||||
|
requests: {
|
||||||
|
memory: this.buildParameters.remoteBuildMemory,
|
||||||
|
cpu: this.buildParameters.remoteBuildCpu,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
env: environment,
|
||||||
volumeMounts: [
|
volumeMounts: [
|
||||||
{
|
{
|
||||||
name: 'data',
|
name: 'buildMount',
|
||||||
mountPath: '/data',
|
mountPath: `/${mountdir}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'credentials',
|
name: 'credentials',
|
||||||
|
|
@ -1507,7 +1513,6 @@ class Kubernetes {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
job.spec.backoffLimit = 1;
|
|
||||||
return job;
|
return job;
|
||||||
}
|
}
|
||||||
runJobInKubernetesPod(command, image) {
|
runJobInKubernetesPod(command, image) {
|
||||||
|
|
@ -1545,7 +1550,7 @@ class Kubernetes {
|
||||||
yield this.createSecret(defaultSecretsArray);
|
yield this.createSecret(defaultSecretsArray);
|
||||||
yield kubernetes_storage_1.default.createPersistentVolumeClaim(this.buildParameters, this.pvcName, this.kubeClient, this.namespace);
|
yield kubernetes_storage_1.default.createPersistentVolumeClaim(this.buildParameters, this.pvcName, this.kubeClient, this.namespace);
|
||||||
//run
|
//run
|
||||||
const jobSpec = this.getJobSpec(command, image);
|
const jobSpec = this.getJobSpec(command, image, 'data', 'data', []);
|
||||||
core.info('Creating build job');
|
core.info('Creating build job');
|
||||||
yield this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
|
yield this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
|
||||||
core.info('Job created');
|
core.info('Job created');
|
||||||
|
|
@ -1585,10 +1590,9 @@ class Kubernetes {
|
||||||
apk add jq;
|
apk add jq;
|
||||||
ls /credentials/
|
ls /credentials/
|
||||||
export GITHUB_TOKEN=$(cat /credentials/GITHUB_TOKEN);
|
export GITHUB_TOKEN=$(cat /credentials/GITHUB_TOKEN);
|
||||||
cd /data;
|
git clone https://github.com/${process.env.GITHUB_REPOSITORY}.git ${buildVolumeFolder}/${repositoryFolder};
|
||||||
git clone https://github.com/${process.env.GITHUB_REPOSITORY}.git repo;
|
git clone https://github.com/webbertakken/unity-builder.git ${buildVolumeFolder}/builder;
|
||||||
git clone https://github.com/webbertakken/unity-builder.git builder;
|
cd ${buildVolumeFolder}/${repositoryFolder};
|
||||||
cd repo;
|
|
||||||
git checkout $GITHUB_SHA;
|
git checkout $GITHUB_SHA;
|
||||||
ls
|
ls
|
||||||
echo "end"`,
|
echo "end"`,
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -10,7 +10,9 @@ import KubernetesStorage from './kubernetes-storage';
|
||||||
import RemoteBuilderEnvironmentVariable from './remote-builder-environment-variable';
|
import RemoteBuilderEnvironmentVariable from './remote-builder-environment-variable';
|
||||||
|
|
||||||
const base64 = require('base-64');
|
const base64 = require('base-64');
|
||||||
|
const repositoryFolder = 'repo';
|
||||||
|
const buildVolumeFolder = 'data';
|
||||||
|
// const cacheFolder = 'cache';
|
||||||
class Kubernetes implements RemoteBuilderProviderInterface {
|
class Kubernetes implements RemoteBuilderProviderInterface {
|
||||||
private kubeConfig: KubeConfig;
|
private kubeConfig: KubeConfig;
|
||||||
private kubeClient: k8s.CoreV1Api;
|
private kubeClient: k8s.CoreV1Api;
|
||||||
|
|
@ -93,7 +95,7 @@ class Kubernetes implements RemoteBuilderProviderInterface {
|
||||||
);
|
);
|
||||||
|
|
||||||
//run
|
//run
|
||||||
const jobSpec = this.getJobSpec(commands, image);
|
const jobSpec = this.getJobSpec(commands, image, mountdir, workingdir, environment);
|
||||||
core.info('Creating build job');
|
core.info('Creating build job');
|
||||||
await this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
|
await this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
|
||||||
core.info('Job created');
|
core.info('Job created');
|
||||||
|
|
@ -158,45 +160,15 @@ class Kubernetes implements RemoteBuilderProviderInterface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getJobSpec(command: string[], image: string) {
|
getJobSpec(
|
||||||
const job = new k8s.V1Job();
|
command: string[],
|
||||||
job.apiVersion = 'batch/v1';
|
image: string,
|
||||||
job.kind = 'Job';
|
mountdir: string,
|
||||||
job.metadata = {
|
workingDirectory: string,
|
||||||
name: this.jobName,
|
environment: RemoteBuilderEnvironmentVariable[],
|
||||||
labels: {
|
) {
|
||||||
app: 'unity-builder',
|
environment.push(
|
||||||
},
|
...[
|
||||||
};
|
|
||||||
job.spec = {
|
|
||||||
template: {
|
|
||||||
spec: {
|
|
||||||
volumes: [
|
|
||||||
{
|
|
||||||
name: 'data',
|
|
||||||
persistentVolumeClaim: {
|
|
||||||
claimName: this.pvcName,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'credentials',
|
|
||||||
secret: {
|
|
||||||
secretName: this.secretName,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
containers: [
|
|
||||||
{
|
|
||||||
name: 'main',
|
|
||||||
image,
|
|
||||||
command,
|
|
||||||
resources: {
|
|
||||||
requests: {
|
|
||||||
memory: this.buildParameters.remoteBuildMemory,
|
|
||||||
cpu: this.buildParameters.remoteBuildCpu,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
env: [
|
|
||||||
{
|
{
|
||||||
name: 'GITHUB_SHA',
|
name: 'GITHUB_SHA',
|
||||||
value: this.buildId,
|
value: this.buildId,
|
||||||
|
|
@ -250,10 +222,51 @@ class Kubernetes implements RemoteBuilderProviderInterface {
|
||||||
value: this.buildParameters.androidKeyaliasName,
|
value: this.buildParameters.androidKeyaliasName,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
);
|
||||||
|
const job = new k8s.V1Job();
|
||||||
|
job.apiVersion = 'batch/v1';
|
||||||
|
job.kind = 'Job';
|
||||||
|
job.metadata = {
|
||||||
|
name: this.jobName,
|
||||||
|
labels: {
|
||||||
|
app: 'unity-builder',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
job.spec = {
|
||||||
|
backoffLimit: 1,
|
||||||
|
template: {
|
||||||
|
spec: {
|
||||||
|
volumes: [
|
||||||
|
{
|
||||||
|
name: 'buildMount',
|
||||||
|
persistentVolumeClaim: {
|
||||||
|
claimName: this.pvcName,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'credentials',
|
||||||
|
secret: {
|
||||||
|
secretName: this.secretName,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
containers: [
|
||||||
|
{
|
||||||
|
name: 'main',
|
||||||
|
image,
|
||||||
|
command,
|
||||||
|
workingDir: workingDirectory,
|
||||||
|
resources: {
|
||||||
|
requests: {
|
||||||
|
memory: this.buildParameters.remoteBuildMemory,
|
||||||
|
cpu: this.buildParameters.remoteBuildCpu,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
env: environment,
|
||||||
volumeMounts: [
|
volumeMounts: [
|
||||||
{
|
{
|
||||||
name: 'data',
|
name: 'buildMount',
|
||||||
mountPath: '/data',
|
mountPath: `/${mountdir}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'credentials',
|
name: 'credentials',
|
||||||
|
|
@ -280,7 +293,6 @@ class Kubernetes implements RemoteBuilderProviderInterface {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
job.spec.backoffLimit = 1;
|
|
||||||
return job;
|
return job;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -325,7 +337,7 @@ class Kubernetes implements RemoteBuilderProviderInterface {
|
||||||
);
|
);
|
||||||
|
|
||||||
//run
|
//run
|
||||||
const jobSpec = this.getJobSpec(command, image);
|
const jobSpec = this.getJobSpec(command, image, 'data', 'data', []);
|
||||||
core.info('Creating build job');
|
core.info('Creating build job');
|
||||||
await this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
|
await this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
|
||||||
core.info('Job created');
|
core.info('Job created');
|
||||||
|
|
@ -368,10 +380,9 @@ class Kubernetes implements RemoteBuilderProviderInterface {
|
||||||
apk add jq;
|
apk add jq;
|
||||||
ls /credentials/
|
ls /credentials/
|
||||||
export GITHUB_TOKEN=$(cat /credentials/GITHUB_TOKEN);
|
export GITHUB_TOKEN=$(cat /credentials/GITHUB_TOKEN);
|
||||||
cd /data;
|
git clone https://github.com/${process.env.GITHUB_REPOSITORY}.git ${buildVolumeFolder}/${repositoryFolder};
|
||||||
git clone https://github.com/${process.env.GITHUB_REPOSITORY}.git repo;
|
git clone https://github.com/webbertakken/unity-builder.git ${buildVolumeFolder}/builder;
|
||||||
git clone https://github.com/webbertakken/unity-builder.git builder;
|
cd ${buildVolumeFolder}/${repositoryFolder};
|
||||||
cd repo;
|
|
||||||
git checkout $GITHUB_SHA;
|
git checkout $GITHUB_SHA;
|
||||||
ls
|
ls
|
||||||
echo "end"`,
|
echo "end"`,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue