cleanup
parent
6dc4d12ac5
commit
0ae8dc9a20
|
|
@ -50,7 +50,7 @@ function run() {
|
|||
switch (buildParameters.remoteBuildCluster) {
|
||||
case 'k8s':
|
||||
core.info('Building with Kubernetes');
|
||||
yield model_1.Kubernetes.runBuildJob(buildParameters, baseImage);
|
||||
yield model_1.Kubernetes.run(buildParameters, baseImage);
|
||||
break;
|
||||
case 'aws':
|
||||
core.info('Building with AWS');
|
||||
|
|
@ -735,7 +735,7 @@ const core = __importStar(__webpack_require__(42186));
|
|||
const base64 = __webpack_require__(85848);
|
||||
const pollInterval = 10000;
|
||||
class Kubernetes {
|
||||
static runBuildJob(buildParameters, baseImage) {
|
||||
static run(buildParameters, baseImage) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
core.info('Starting up k8s');
|
||||
const kc = new k8s.KubeConfig();
|
||||
|
|
@ -766,12 +766,8 @@ class Kubernetes {
|
|||
yield Kubernetes.createSecret();
|
||||
yield Kubernetes.createPersistentVolumeClaim();
|
||||
// start
|
||||
yield Kubernetes.scheduleBuildJob();
|
||||
// watch
|
||||
yield Kubernetes.watchPersistentVolumeClaimUntilReady();
|
||||
yield Kubernetes.watchBuildJobUntilFinished();
|
||||
// cleanup
|
||||
yield Kubernetes.cleanup();
|
||||
yield Kubernetes.runCloneJob();
|
||||
yield Kubernetes.runBuildJob();
|
||||
core.setOutput('volume', pvcName);
|
||||
});
|
||||
}
|
||||
|
|
@ -820,20 +816,7 @@ class Kubernetes {
|
|||
core.info('Persistent Volume created, waiting for ready state...');
|
||||
});
|
||||
}
|
||||
static watchPersistentVolumeClaimUntilReady() {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
yield new Promise((resolve) => setTimeout(resolve, pollInterval));
|
||||
const queryResult = yield this.kubeClient.readNamespacedPersistentVolumeClaim(this.pvcName, this.namespace);
|
||||
if (((_a = queryResult.body.status) === null || _a === void 0 ? void 0 : _a.phase) === 'Pending') {
|
||||
yield Kubernetes.watchPersistentVolumeClaimUntilReady();
|
||||
}
|
||||
else {
|
||||
core.info('Persistent Volume ready for claims');
|
||||
}
|
||||
});
|
||||
}
|
||||
static scheduleBuildJob() {
|
||||
static runJob(command, image) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
core.info('Creating build job');
|
||||
const job = new k8s.V1Job();
|
||||
|
|
@ -862,62 +845,11 @@ class Kubernetes {
|
|||
},
|
||||
},
|
||||
],
|
||||
initContainers: [
|
||||
{
|
||||
name: 'clone',
|
||||
image: 'alpine/git',
|
||||
command: [
|
||||
'/bin/sh',
|
||||
'-c',
|
||||
`apk update;
|
||||
apk add git-lfs;
|
||||
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 checkout $GITHUB_SHA;
|
||||
ls`,
|
||||
],
|
||||
volumeMounts: [
|
||||
{
|
||||
name: 'data',
|
||||
mountPath: '/data',
|
||||
},
|
||||
{
|
||||
name: 'credentials',
|
||||
mountPath: '/credentials',
|
||||
readOnly: true,
|
||||
},
|
||||
],
|
||||
env: [
|
||||
{
|
||||
name: 'GITHUB_SHA',
|
||||
value: this.buildId,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
containers: [
|
||||
{
|
||||
name: 'main',
|
||||
image: `${this.baseImage.toString()}`,
|
||||
command: [
|
||||
'bin/bash',
|
||||
'-c',
|
||||
`ls
|
||||
for f in ./credentials/*; do export $(basename $f)="$(cat $f)"; done
|
||||
ls /data
|
||||
ls /data/builder
|
||||
ls /data/builder/dist
|
||||
cp -r /data/builder/dist/default-build-script /UnityBuilderAction
|
||||
cp -r /data/builder/dist/entrypoint.sh /entrypoint.sh
|
||||
cp -r /data/builder/dist/steps /steps
|
||||
chmod -R +x /entrypoint.sh
|
||||
chmod -R +x /steps
|
||||
/entrypoint.sh
|
||||
`,
|
||||
],
|
||||
image,
|
||||
command: ['bin/bash', '-c', command],
|
||||
resources: {
|
||||
requests: {
|
||||
memory: this.buildParameters.remoteBuildMemory,
|
||||
|
|
@ -925,6 +857,10 @@ class Kubernetes {
|
|||
},
|
||||
},
|
||||
env: [
|
||||
{
|
||||
name: 'GITHUB_SHA',
|
||||
value: this.buildId,
|
||||
},
|
||||
{
|
||||
name: 'GITHUB_WORKSPACE',
|
||||
value: '/data/repo',
|
||||
|
|
@ -1007,6 +943,53 @@ class Kubernetes {
|
|||
job.spec.backoffLimit = 1;
|
||||
yield this.kubeClientBatch.createNamespacedJob(this.namespace, job);
|
||||
core.info('Job created');
|
||||
// watch
|
||||
yield Kubernetes.watchPersistentVolumeClaimUntilReady();
|
||||
yield Kubernetes.watchBuildJobUntilFinished();
|
||||
// cleanup
|
||||
yield Kubernetes.cleanup();
|
||||
});
|
||||
}
|
||||
static runCloneJob() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
yield Kubernetes.runJob(`apk update;
|
||||
apk add git-lfs;
|
||||
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 checkout $GITHUB_SHA;
|
||||
ls`, 'alpine/git');
|
||||
});
|
||||
}
|
||||
static runBuildJob() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
yield this.runJob(`ls
|
||||
for f in ./credentials/*; do export $(basename $f)="$(cat $f)"; done
|
||||
ls /data
|
||||
ls /data/builder
|
||||
ls /data/builder/dist
|
||||
cp -r /data/builder/dist/default-build-script /UnityBuilderAction
|
||||
cp -r /data/builder/dist/entrypoint.sh /entrypoint.sh
|
||||
cp -r /data/builder/dist/steps /steps
|
||||
chmod -R +x /entrypoint.sh
|
||||
chmod -R +x /steps
|
||||
/entrypoint.sh
|
||||
`, this.baseImage.toString());
|
||||
});
|
||||
}
|
||||
static watchPersistentVolumeClaimUntilReady() {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
yield new Promise((resolve) => setTimeout(resolve, pollInterval));
|
||||
const queryResult = yield this.kubeClient.readNamespacedPersistentVolumeClaim(this.pvcName, this.namespace);
|
||||
if (((_a = queryResult.body.status) === null || _a === void 0 ? void 0 : _a.phase) === 'Pending') {
|
||||
yield Kubernetes.watchPersistentVolumeClaimUntilReady();
|
||||
}
|
||||
else {
|
||||
core.info('Persistent Volume ready for claims');
|
||||
}
|
||||
});
|
||||
}
|
||||
static watchPodUntilReadyAndRead(statusFilter) {
|
||||
|
|
@ -1035,12 +1018,12 @@ class Kubernetes {
|
|||
});
|
||||
}
|
||||
static watchBuildJobUntilFinished() {
|
||||
var _a, _b, _c, _d;
|
||||
var _a, _b;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
const pod = (yield Kubernetes.watchPodUntilReadyAndRead('Pending')) || {};
|
||||
core.info(`Watching build job ${(_a = pod.metadata) === null || _a === void 0 ? void 0 : _a.name} ${JSON.stringify((_c = (_b = pod.status) === null || _b === void 0 ? void 0 : _b.containerStatuses) === null || _c === void 0 ? void 0 : _c[0].state, undefined, 4)}`);
|
||||
yield Kubernetes.streamLogs(((_d = pod.metadata) === null || _d === void 0 ? void 0 : _d.name) || '', this.namespace);
|
||||
core.info(`Watching build job ${(_a = pod.metadata) === null || _a === void 0 ? void 0 : _a.name}`);
|
||||
yield Kubernetes.streamLogs(((_b = pod.metadata) === null || _b === void 0 ? void 0 : _b.name) || '', this.namespace);
|
||||
}
|
||||
catch (error) {
|
||||
core.error('Failed while watching build job');
|
||||
|
|
@ -1053,7 +1036,7 @@ class Kubernetes {
|
|||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
let running = true;
|
||||
let logQueryTime = 0;
|
||||
let logQueryTime = 999;
|
||||
let mostRecentLine = '';
|
||||
while (running) {
|
||||
const pod = yield this.kubeClient.readNamespacedPod(name, namespace);
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -15,7 +15,7 @@ async function run() {
|
|||
switch (buildParameters.remoteBuildCluster) {
|
||||
case 'k8s':
|
||||
core.info('Building with Kubernetes');
|
||||
await Kubernetes.runBuildJob(buildParameters, baseImage);
|
||||
await Kubernetes.run(buildParameters, baseImage);
|
||||
break;
|
||||
|
||||
case 'aws':
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class Kubernetes {
|
|||
private static jobName: string;
|
||||
private static namespace: string;
|
||||
|
||||
static async runBuildJob(buildParameters: BuildParameters, baseImage) {
|
||||
static async run(buildParameters: BuildParameters, baseImage) {
|
||||
core.info('Starting up k8s');
|
||||
const kc = new k8s.KubeConfig();
|
||||
kc.loadFromDefault();
|
||||
|
|
@ -52,14 +52,8 @@ class Kubernetes {
|
|||
await Kubernetes.createPersistentVolumeClaim();
|
||||
|
||||
// start
|
||||
await Kubernetes.scheduleBuildJob();
|
||||
|
||||
// watch
|
||||
await Kubernetes.watchPersistentVolumeClaimUntilReady();
|
||||
await Kubernetes.watchBuildJobUntilFinished();
|
||||
|
||||
// cleanup
|
||||
await Kubernetes.cleanup();
|
||||
await Kubernetes.runCloneJob();
|
||||
await Kubernetes.runBuildJob();
|
||||
|
||||
core.setOutput('volume', pvcName);
|
||||
}
|
||||
|
|
@ -109,18 +103,7 @@ class Kubernetes {
|
|||
core.info('Persistent Volume created, waiting for ready state...');
|
||||
}
|
||||
|
||||
static async watchPersistentVolumeClaimUntilReady() {
|
||||
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
||||
const queryResult = await this.kubeClient.readNamespacedPersistentVolumeClaim(this.pvcName, this.namespace);
|
||||
|
||||
if (queryResult.body.status?.phase === 'Pending') {
|
||||
await Kubernetes.watchPersistentVolumeClaimUntilReady();
|
||||
} else {
|
||||
core.info('Persistent Volume ready for claims');
|
||||
}
|
||||
}
|
||||
|
||||
static async scheduleBuildJob() {
|
||||
static async runJob(command: string, image: string) {
|
||||
core.info('Creating build job');
|
||||
const job = new k8s.V1Job();
|
||||
job.apiVersion = 'batch/v1';
|
||||
|
|
@ -148,62 +131,11 @@ class Kubernetes {
|
|||
},
|
||||
},
|
||||
],
|
||||
initContainers: [
|
||||
{
|
||||
name: 'clone',
|
||||
image: 'alpine/git',
|
||||
command: [
|
||||
'/bin/sh',
|
||||
'-c',
|
||||
`apk update;
|
||||
apk add git-lfs;
|
||||
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 checkout $GITHUB_SHA;
|
||||
ls`,
|
||||
],
|
||||
volumeMounts: [
|
||||
{
|
||||
name: 'data',
|
||||
mountPath: '/data',
|
||||
},
|
||||
{
|
||||
name: 'credentials',
|
||||
mountPath: '/credentials',
|
||||
readOnly: true,
|
||||
},
|
||||
],
|
||||
env: [
|
||||
{
|
||||
name: 'GITHUB_SHA',
|
||||
value: this.buildId,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
containers: [
|
||||
{
|
||||
name: 'main',
|
||||
image: `${this.baseImage.toString()}`,
|
||||
command: [
|
||||
'bin/bash',
|
||||
'-c',
|
||||
`ls
|
||||
for f in ./credentials/*; do export $(basename $f)="$(cat $f)"; done
|
||||
ls /data
|
||||
ls /data/builder
|
||||
ls /data/builder/dist
|
||||
cp -r /data/builder/dist/default-build-script /UnityBuilderAction
|
||||
cp -r /data/builder/dist/entrypoint.sh /entrypoint.sh
|
||||
cp -r /data/builder/dist/steps /steps
|
||||
chmod -R +x /entrypoint.sh
|
||||
chmod -R +x /steps
|
||||
/entrypoint.sh
|
||||
`,
|
||||
],
|
||||
image,
|
||||
command: ['bin/bash', '-c', command],
|
||||
resources: {
|
||||
requests: {
|
||||
memory: this.buildParameters.remoteBuildMemory,
|
||||
|
|
@ -211,6 +143,10 @@ class Kubernetes {
|
|||
},
|
||||
},
|
||||
env: [
|
||||
{
|
||||
name: 'GITHUB_SHA',
|
||||
value: this.buildId,
|
||||
},
|
||||
{
|
||||
name: 'GITHUB_WORKSPACE',
|
||||
value: '/data/repo',
|
||||
|
|
@ -293,6 +229,57 @@ class Kubernetes {
|
|||
job.spec.backoffLimit = 1;
|
||||
await this.kubeClientBatch.createNamespacedJob(this.namespace, job);
|
||||
core.info('Job created');
|
||||
|
||||
// watch
|
||||
await Kubernetes.watchPersistentVolumeClaimUntilReady();
|
||||
await Kubernetes.watchBuildJobUntilFinished();
|
||||
|
||||
// cleanup
|
||||
await Kubernetes.cleanup();
|
||||
}
|
||||
|
||||
static async runCloneJob() {
|
||||
await Kubernetes.runJob(
|
||||
`apk update;
|
||||
apk add git-lfs;
|
||||
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 checkout $GITHUB_SHA;
|
||||
ls`,
|
||||
'alpine/git',
|
||||
);
|
||||
}
|
||||
|
||||
static async runBuildJob() {
|
||||
await this.runJob(
|
||||
`ls
|
||||
for f in ./credentials/*; do export $(basename $f)="$(cat $f)"; done
|
||||
ls /data
|
||||
ls /data/builder
|
||||
ls /data/builder/dist
|
||||
cp -r /data/builder/dist/default-build-script /UnityBuilderAction
|
||||
cp -r /data/builder/dist/entrypoint.sh /entrypoint.sh
|
||||
cp -r /data/builder/dist/steps /steps
|
||||
chmod -R +x /entrypoint.sh
|
||||
chmod -R +x /steps
|
||||
/entrypoint.sh
|
||||
`,
|
||||
this.baseImage.toString(),
|
||||
);
|
||||
}
|
||||
|
||||
static async watchPersistentVolumeClaimUntilReady() {
|
||||
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
||||
const queryResult = await this.kubeClient.readNamespacedPersistentVolumeClaim(this.pvcName, this.namespace);
|
||||
|
||||
if (queryResult.body.status?.phase === 'Pending') {
|
||||
await Kubernetes.watchPersistentVolumeClaimUntilReady();
|
||||
} else {
|
||||
core.info('Persistent Volume ready for claims');
|
||||
}
|
||||
}
|
||||
|
||||
static async watchPodUntilReadyAndRead(statusFilter: string) {
|
||||
|
|
@ -321,14 +308,7 @@ class Kubernetes {
|
|||
static async watchBuildJobUntilFinished() {
|
||||
try {
|
||||
const pod = (await Kubernetes.watchPodUntilReadyAndRead('Pending')) || {};
|
||||
|
||||
core.info(
|
||||
`Watching build job ${pod.metadata?.name} ${JSON.stringify(
|
||||
pod.status?.containerStatuses?.[0].state,
|
||||
undefined,
|
||||
4,
|
||||
)}`,
|
||||
);
|
||||
core.info(`Watching build job ${pod.metadata?.name}`);
|
||||
await Kubernetes.streamLogs(pod.metadata?.name || '', this.namespace);
|
||||
} catch (error) {
|
||||
core.error('Failed while watching build job');
|
||||
|
|
@ -339,7 +319,7 @@ class Kubernetes {
|
|||
static async streamLogs(name: string, namespace: string) {
|
||||
try {
|
||||
let running = true;
|
||||
let logQueryTime: number = 0;
|
||||
let logQueryTime: number = 999;
|
||||
let mostRecentLine: string = '';
|
||||
while (running) {
|
||||
const pod = await this.kubeClient.readNamespacedPod(name, namespace);
|
||||
|
|
|
|||
Loading…
Reference in New Issue