Parameterize more of the K8s build

pull/273/head
Frostebite 2021-06-19 18:04:03 +01:00
parent 52fe9fd9d0
commit e75c489156
3 changed files with 147 additions and 132 deletions

100
dist/index.js vendored
View File

@ -1260,6 +1260,9 @@ const stream_1 = __webpack_require__(92413);
const async_wait_until_1 = __webpack_require__(41299);
const kubernetes_storage_1 = __importDefault(__webpack_require__(38941));
const base64 = __webpack_require__(85848);
const repositoryFolder = 'repo';
const buildVolumeFolder = 'data';
// const cacheFolder = 'cache';
class Kubernetes {
constructor(buildParameters, baseImage) {
this.buildId = '';
@ -1318,7 +1321,7 @@ class Kubernetes {
yield this.createSecret(defaultSecretsArray);
yield kubernetes_storage_1.default.createPersistentVolumeClaim(this.buildParameters, this.pvcName, this.kubeClient, this.namespace);
//run
const jobSpec = this.getJobSpec(commands, image);
const jobSpec = this.getJobSpec(commands, image, mountdir, workingdir, environment);
core.info('Creating build job');
yield this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
core.info('Job created');
@ -1385,45 +1388,8 @@ class Kubernetes {
}
});
}
getJobSpec(command, image) {
const job = new k8s.V1Job();
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: [
getJobSpec(command, image, mountdir, workingDirectory, environment) {
environment.push(...[
{
name: 'GITHUB_SHA',
value: this.buildId,
@ -1476,11 +1442,51 @@ class Kubernetes {
name: 'ANDROID_KEYALIAS_NAME',
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: [
{
name: 'data',
mountPath: '/data',
name: 'buildMount',
mountPath: `/${mountdir}`,
},
{
name: 'credentials',
@ -1507,7 +1513,6 @@ class Kubernetes {
},
},
};
job.spec.backoffLimit = 1;
return job;
}
runJobInKubernetesPod(command, image) {
@ -1545,7 +1550,7 @@ class Kubernetes {
yield this.createSecret(defaultSecretsArray);
yield kubernetes_storage_1.default.createPersistentVolumeClaim(this.buildParameters, this.pvcName, this.kubeClient, this.namespace);
//run
const jobSpec = this.getJobSpec(command, image);
const jobSpec = this.getJobSpec(command, image, 'data', 'data', []);
core.info('Creating build job');
yield this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
core.info('Job created');
@ -1585,10 +1590,9 @@ class Kubernetes {
apk add jq;
ls /credentials/
export GITHUB_TOKEN=$(cat /credentials/GITHUB_TOKEN);
cd /data;
git clone https://github.com/${process.env.GITHUB_REPOSITORY}.git repo;
git clone https://github.com/webbertakken/unity-builder.git builder;
cd repo;
git clone https://github.com/${process.env.GITHUB_REPOSITORY}.git ${buildVolumeFolder}/${repositoryFolder};
git clone https://github.com/webbertakken/unity-builder.git ${buildVolumeFolder}/builder;
cd ${buildVolumeFolder}/${repositoryFolder};
git checkout $GITHUB_SHA;
ls
echo "end"`,

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -10,7 +10,9 @@ import KubernetesStorage from './kubernetes-storage';
import RemoteBuilderEnvironmentVariable from './remote-builder-environment-variable';
const base64 = require('base-64');
const repositoryFolder = 'repo';
const buildVolumeFolder = 'data';
// const cacheFolder = 'cache';
class Kubernetes implements RemoteBuilderProviderInterface {
private kubeConfig: KubeConfig;
private kubeClient: k8s.CoreV1Api;
@ -93,7 +95,7 @@ class Kubernetes implements RemoteBuilderProviderInterface {
);
//run
const jobSpec = this.getJobSpec(commands, image);
const jobSpec = this.getJobSpec(commands, image, mountdir, workingdir, environment);
core.info('Creating build job');
await this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
core.info('Job created');
@ -158,45 +160,15 @@ class Kubernetes implements RemoteBuilderProviderInterface {
}
}
getJobSpec(command: string[], image: string) {
const job = new k8s.V1Job();
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: [
getJobSpec(
command: string[],
image: string,
mountdir: string,
workingDirectory: string,
environment: RemoteBuilderEnvironmentVariable[],
) {
environment.push(
...[
{
name: 'GITHUB_SHA',
value: this.buildId,
@ -250,10 +222,51 @@ class Kubernetes implements RemoteBuilderProviderInterface {
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: [
{
name: 'data',
mountPath: '/data',
name: 'buildMount',
mountPath: `/${mountdir}`,
},
{
name: 'credentials',
@ -280,7 +293,6 @@ class Kubernetes implements RemoteBuilderProviderInterface {
},
},
};
job.spec.backoffLimit = 1;
return job;
}
@ -325,7 +337,7 @@ class Kubernetes implements RemoteBuilderProviderInterface {
);
//run
const jobSpec = this.getJobSpec(command, image);
const jobSpec = this.getJobSpec(command, image, 'data', 'data', []);
core.info('Creating build job');
await this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
core.info('Job created');
@ -368,10 +380,9 @@ class Kubernetes implements RemoteBuilderProviderInterface {
apk add jq;
ls /credentials/
export GITHUB_TOKEN=$(cat /credentials/GITHUB_TOKEN);
cd /data;
git clone https://github.com/${process.env.GITHUB_REPOSITORY}.git repo;
git clone https://github.com/webbertakken/unity-builder.git builder;
cd repo;
git clone https://github.com/${process.env.GITHUB_REPOSITORY}.git ${buildVolumeFolder}/${repositoryFolder};
git clone https://github.com/webbertakken/unity-builder.git ${buildVolumeFolder}/builder;
cd ${buildVolumeFolder}/${repositoryFolder};
git checkout $GITHUB_SHA;
ls
echo "end"`,