'$npm_config_message'

pull/273/head
Frostebite 2021-06-19 04:31:29 +01:00
parent b9cf74b2e6
commit 6a4d3365e4
4 changed files with 92 additions and 88 deletions

79
dist/index.js vendored
View File

@ -1263,6 +1263,7 @@ const base64 = __webpack_require__(85848);
class Kubernetes {
constructor(buildParameters, baseImage) {
this.buildId = '';
this.buildCorrelationId = '';
this.pvcName = '';
this.secretName = '';
this.jobName = '';
@ -1276,10 +1277,10 @@ class Kubernetes {
this.kubeConfig = kc;
this.kubeClient = k8sApi;
this.kubeClientBatch = k8sBatchApi;
this.buildCorrelationId = Kubernetes.uuidv4();
this.namespace = 'default';
this.buildParameters = buildParameters;
this.baseImage = baseImage;
this.setUniqueBuildId();
}
runBuild(buildId, stackName, image, commands, mountdir, workingdir, environment, secrets) {
return __awaiter(this, void 0, void 0, function* () {
@ -1316,7 +1317,7 @@ class Kubernetes {
yield this.createSecret(defaultSecretsArray);
yield kubernetes_storage_1.default.createPersistentVolumeClaim(this.buildParameters, this.pvcName, this.kubeClient, this.namespace);
// run
yield this.runJob(commands, image);
yield this.runJobInKubernetesPod(commands, image);
yield this.cleanup();
}
catch (error) {
@ -1338,41 +1339,9 @@ class Kubernetes {
run() {
return __awaiter(this, void 0, void 0, function* () {
core.info('Running Remote Builder on Kubernetes');
const defaultSecretsArray = [
{
ParameterKey: 'GithubToken',
EnvironmentVariable: 'GITHUB_TOKEN',
ParameterValue: this.buildParameters.githubToken,
},
{
ParameterKey: 'UNITY_LICENSE',
EnvironmentVariable: 'UNITY_LICENSE',
ParameterValue: process.env.UNITY_LICENSE || '',
},
{
ParameterKey: 'ANDROID_KEYSTORE_BASE64',
EnvironmentVariable: 'ANDROID_KEYSTORE_BASE64',
ParameterValue: this.buildParameters.androidKeystoreBase64,
},
{
ParameterKey: 'ANDROID_KEYSTORE_PASS',
EnvironmentVariable: 'ANDROID_KEYSTORE_PASS',
ParameterValue: this.buildParameters.androidKeystorePass,
},
{
ParameterKey: 'ANDROID_KEYALIAS_PASS',
EnvironmentVariable: 'ANDROID_KEYALIAS_PASS',
ParameterValue: this.buildParameters.androidKeyaliasPass,
},
];
try {
// setup
yield this.createSecret(defaultSecretsArray);
yield kubernetes_storage_1.default.createPersistentVolumeClaim(this.buildParameters, this.pvcName, this.kubeClient, this.namespace);
// run
yield this.runCloneJob();
yield this.runBuildJob();
yield this.cleanup();
}
catch (error) {
core.error(error);
@ -1529,10 +1498,41 @@ class Kubernetes {
job.spec.backoffLimit = 1;
return job;
}
runJob(command, image) {
runJobInKubernetesPod(command, image) {
return __awaiter(this, void 0, void 0, function* () {
try {
this.setUniqueBuildId();
const defaultSecretsArray = [
{
ParameterKey: 'GithubToken',
EnvironmentVariable: 'GITHUB_TOKEN',
ParameterValue: this.buildParameters.githubToken,
},
{
ParameterKey: 'UNITY_LICENSE',
EnvironmentVariable: 'UNITY_LICENSE',
ParameterValue: process.env.UNITY_LICENSE || '',
},
{
ParameterKey: 'ANDROID_KEYSTORE_BASE64',
EnvironmentVariable: 'ANDROID_KEYSTORE_BASE64',
ParameterValue: this.buildParameters.androidKeystoreBase64,
},
{
ParameterKey: 'ANDROID_KEYSTORE_PASS',
EnvironmentVariable: 'ANDROID_KEYSTORE_PASS',
ParameterValue: this.buildParameters.androidKeystorePass,
},
{
ParameterKey: 'ANDROID_KEYALIAS_PASS',
EnvironmentVariable: 'ANDROID_KEYALIAS_PASS',
ParameterValue: this.buildParameters.androidKeyaliasPass,
},
];
// setup
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);
core.info('Creating build job');
yield this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
@ -1540,8 +1540,9 @@ class Kubernetes {
yield kubernetes_storage_1.default.watchUntilPVCNotPending(this.kubeClient, this.pvcName, this.namespace);
core.info('PVC Bound');
this.setPodNameAndContainerName(yield this.getPod());
core.info('Watching pod and streaming logs');
core.info('Watching pod until running');
yield this.watchUntilPodRunning();
core.info('Pod running, streaming logs');
yield this.streamLogs();
yield this.cleanup();
}
@ -1568,7 +1569,7 @@ class Kubernetes {
}
runCloneJob() {
return __awaiter(this, void 0, void 0, function* () {
yield this.runJob([
yield this.runJobInKubernetesPod([
'/bin/ash',
'-c',
`apk update;
@ -1587,7 +1588,7 @@ class Kubernetes {
}
runBuildJob() {
return __awaiter(this, void 0, void 0, function* () {
yield this.runJob([
yield this.runJobInKubernetesPod([
'bin/bash',
'-c',
`ls
@ -1615,7 +1616,7 @@ class Kubernetes {
return __awaiter(this, void 0, void 0, function* () {
yield async_wait_until_1.waitUntil(() => __awaiter(this, void 0, void 0, function* () {
(yield this.getPodStatusPhase()) !== 'Pending';
}));
}), 500000);
const phase = yield this.getPodStatusPhase();
if (phase === 'Running') {
core.info('Pod no longer pending');

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -11,7 +11,9 @@
"build": "tsc && ncc build lib --source-map --license licenses.txt",
"lint": "prettier --check \"src/**/*.{js,ts}\" && eslint src/**/*.ts",
"format": "prettier --write \"src/**/*.{js,ts}\"",
"test": "jest"
"test": "jest",
"commit": "yarn build && git add . && git commit -m '$npm_config_message' -q",
"push": "yarn build && git add . && git commit -m '$npm_config_message' -q && git push"
},
"dependencies": {
"@actions/core": "^1.2.6",

View File

@ -16,6 +16,7 @@ class Kubernetes implements RemoteBuilderProviderInterface {
private kubeClient: k8s.CoreV1Api;
private kubeClientBatch: k8s.BatchV1Api;
private buildId: string = '';
private buildCorrelationId: string = '';
private buildParameters: BuildParameters;
private baseImage: any;
private pvcName: string = '';
@ -36,11 +37,11 @@ class Kubernetes implements RemoteBuilderProviderInterface {
this.kubeClient = k8sApi;
this.kubeClientBatch = k8sBatchApi;
this.buildCorrelationId = Kubernetes.uuidv4();
this.namespace = 'default';
this.buildParameters = buildParameters;
this.baseImage = baseImage;
this.setUniqueBuildId();
}
async runBuild(
buildId: string,
@ -91,7 +92,7 @@ class Kubernetes implements RemoteBuilderProviderInterface {
);
// run
await this.runJob(commands, image);
await this.runJobInKubernetesPod(commands, image);
await this.cleanup();
} catch (error) {
@ -114,48 +115,9 @@ class Kubernetes implements RemoteBuilderProviderInterface {
async run() {
core.info('Running Remote Builder on Kubernetes');
const defaultSecretsArray: RemoteBuilderSecret[] = [
{
ParameterKey: 'GithubToken',
EnvironmentVariable: 'GITHUB_TOKEN',
ParameterValue: this.buildParameters.githubToken,
},
{
ParameterKey: 'UNITY_LICENSE',
EnvironmentVariable: 'UNITY_LICENSE',
ParameterValue: process.env.UNITY_LICENSE || '',
},
{
ParameterKey: 'ANDROID_KEYSTORE_BASE64',
EnvironmentVariable: 'ANDROID_KEYSTORE_BASE64',
ParameterValue: this.buildParameters.androidKeystoreBase64,
},
{
ParameterKey: 'ANDROID_KEYSTORE_PASS',
EnvironmentVariable: 'ANDROID_KEYSTORE_PASS',
ParameterValue: this.buildParameters.androidKeystorePass,
},
{
ParameterKey: 'ANDROID_KEYALIAS_PASS',
EnvironmentVariable: 'ANDROID_KEYALIAS_PASS',
ParameterValue: this.buildParameters.androidKeyaliasPass,
},
];
try {
// setup
await this.createSecret(defaultSecretsArray);
await KubernetesStorage.createPersistentVolumeClaim(
this.buildParameters,
this.pvcName,
this.kubeClient,
this.namespace,
);
// run
await this.runCloneJob();
await this.runBuildJob();
await this.cleanup();
} catch (error) {
core.error(error);
core.error(JSON.stringify(error.response, undefined, 4));
@ -311,9 +273,47 @@ class Kubernetes implements RemoteBuilderProviderInterface {
return job;
}
async runJob(command: string[], image: string) {
async runJobInKubernetesPod(command: string[], image: string) {
try {
this.setUniqueBuildId();
const defaultSecretsArray: RemoteBuilderSecret[] = [
{
ParameterKey: 'GithubToken',
EnvironmentVariable: 'GITHUB_TOKEN',
ParameterValue: this.buildParameters.githubToken,
},
{
ParameterKey: 'UNITY_LICENSE',
EnvironmentVariable: 'UNITY_LICENSE',
ParameterValue: process.env.UNITY_LICENSE || '',
},
{
ParameterKey: 'ANDROID_KEYSTORE_BASE64',
EnvironmentVariable: 'ANDROID_KEYSTORE_BASE64',
ParameterValue: this.buildParameters.androidKeystoreBase64,
},
{
ParameterKey: 'ANDROID_KEYSTORE_PASS',
EnvironmentVariable: 'ANDROID_KEYSTORE_PASS',
ParameterValue: this.buildParameters.androidKeystorePass,
},
{
ParameterKey: 'ANDROID_KEYALIAS_PASS',
EnvironmentVariable: 'ANDROID_KEYALIAS_PASS',
ParameterValue: this.buildParameters.androidKeyaliasPass,
},
];
// setup
await this.createSecret(defaultSecretsArray);
await KubernetesStorage.createPersistentVolumeClaim(
this.buildParameters,
this.pvcName,
this.kubeClient,
this.namespace,
);
//run
const jobSpec = this.getJobSpec(command, image);
core.info('Creating build job');
await this.kubeClientBatch.createNamespacedJob(this.namespace, jobSpec);
@ -321,8 +321,9 @@ class Kubernetes implements RemoteBuilderProviderInterface {
await KubernetesStorage.watchUntilPVCNotPending(this.kubeClient, this.pvcName, this.namespace);
core.info('PVC Bound');
this.setPodNameAndContainerName(await this.getPod());
core.info('Watching pod and streaming logs');
core.info('Watching pod until running');
await this.watchUntilPodRunning();
core.info('Pod running, streaming logs');
await this.streamLogs();
await this.cleanup();
} catch (error) {
@ -347,7 +348,7 @@ class Kubernetes implements RemoteBuilderProviderInterface {
}
async runCloneJob() {
await this.runJob(
await this.runJobInKubernetesPod(
[
'/bin/ash',
'-c',
@ -368,7 +369,7 @@ class Kubernetes implements RemoteBuilderProviderInterface {
}
async runBuildJob() {
await this.runJob(
await this.runJobInKubernetesPod(
[
'bin/bash',
'-c',
@ -396,7 +397,7 @@ class Kubernetes implements RemoteBuilderProviderInterface {
async watchUntilPodRunning() {
await waitUntil(async () => {
(await this.getPodStatusPhase()) !== 'Pending';
});
}, 500000);
const phase = await this.getPodStatusPhase();
if (phase === 'Running') {
core.info('Pod no longer pending');