pull/310/head
Frostebite 2021-12-26 00:32:00 +00:00
parent 5947566262
commit 9bcd11c51c
4 changed files with 79 additions and 66 deletions

118
dist/index.js vendored
View File

@ -486,20 +486,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.RemoteClientSystem = void 0; exports.RemoteClientSystem = void 0;
const child_process_1 = __webpack_require__(63129);
const cloud_runner_logger_1 = __importDefault(__webpack_require__(22855)); const cloud_runner_logger_1 = __importDefault(__webpack_require__(22855));
const system_1 = __importDefault(__webpack_require__(62177));
class RemoteClientSystem { class RemoteClientSystem {
static Run(command) { static Run(command) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { return yield new Promise((promise) => {
const result = yield system_1.default.run(command); child_process_1.exec(command, (error, stdout, stderr) => {
cloud_runner_logger_1.default.logRemoteCli(`${result}`); if (error) {
return result; cloud_runner_logger_1.default.logRemoteCli(`[ERROR] ${error.message}`);
} throw new Error(error.toString());
catch (error) { }
cloud_runner_logger_1.default.logRemoteCli(`[ERROR] (${command}) ${error}`); if (stderr) {
throw error; cloud_runner_logger_1.default.logRemoteCli(`[STD-ERROR] ${stderr.toString()}`);
} throw new Error(stderr.toString());
}
cloud_runner_logger_1.default.logRemoteCli(`${stdout.toString()}`);
promise(stdout.toString());
});
});
}); });
} }
} }
@ -670,6 +675,7 @@ class SetupRemoteRepository {
yield remote_client_system_1.RemoteClientSystem.Run(`git clone --depth 1 ${cloud_runner_state_1.CloudRunnerState.targetBuildRepoUrl} ${cloud_runner_state_1.CloudRunnerState.repoPathFull}`); yield remote_client_system_1.RemoteClientSystem.Run(`git clone --depth 1 ${cloud_runner_state_1.CloudRunnerState.targetBuildRepoUrl} ${cloud_runner_state_1.CloudRunnerState.repoPathFull}`);
yield remote_client_system_1.RemoteClientSystem.Run(`ls -lh`); yield remote_client_system_1.RemoteClientSystem.Run(`ls -lh`);
yield remote_client_system_1.RemoteClientSystem.Run(`tree`); yield remote_client_system_1.RemoteClientSystem.Run(`tree`);
yield remote_client_system_1.RemoteClientSystem.Run(`${cloud_runner_state_1.CloudRunnerState.buildParams.gitSha}`);
yield remote_client_system_1.RemoteClientSystem.Run(`git checkout ${cloud_runner_state_1.CloudRunnerState.buildParams.gitSha}`); yield remote_client_system_1.RemoteClientSystem.Run(`git checkout ${cloud_runner_state_1.CloudRunnerState.buildParams.gitSha}`);
cloud_runner_logger_1.default.logRemoteCli(`Checked out ${process.env.GITHUB_SHA}`); cloud_runner_logger_1.default.logRemoteCli(`Checked out ${process.env.GITHUB_SHA}`);
}); });
@ -932,8 +938,8 @@ class AWSJobStack {
setupCloudFormations(CF, buildGuid, image, entrypoint, commands, mountdir, workingdir, secrets) { setupCloudFormations(CF, buildGuid, image, entrypoint, commands, mountdir, workingdir, secrets) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const logGuid = nanoid_1.customAlphabet(cloud_runner_constants_1.default.alphabet, 9)(); const logGuid = nanoid_1.customAlphabet(cloud_runner_constants_1.default.alphabet, 9)();
commands[1] += ` commands[1] += `
echo "${logGuid}" echo "${logGuid}"
`; `;
const taskDefStackName = `${this.baseStackName}-${buildGuid}`; const taskDefStackName = `${this.baseStackName}-${buildGuid}`;
let taskDefCloudFormation = aws_templates_1.AWSTemplates.readTaskCloudFormationTemplate(); let taskDefCloudFormation = aws_templates_1.AWSTemplates.readTaskCloudFormationTemplate();
@ -1309,25 +1315,25 @@ exports.AWSTemplates = void 0;
const fs = __importStar(__webpack_require__(35747)); const fs = __importStar(__webpack_require__(35747));
class AWSTemplates { class AWSTemplates {
static getParameterTemplate(p1) { static getParameterTemplate(p1) {
return ` return `
${p1}: ${p1}:
Type: String Type: String
Default: '' Default: ''
`; `;
} }
static getSecretTemplate(p1) { static getSecretTemplate(p1) {
return ` return `
${p1}Secret: ${p1}Secret:
Type: AWS::SecretsManager::Secret Type: AWS::SecretsManager::Secret
Properties: Properties:
Name: !Join [ "", [ '${p1}', !Ref BUILDID ] ] Name: !Join [ "", [ '${p1}', !Ref BUILDID ] ]
SecretString: !Ref ${p1} SecretString: !Ref ${p1}
`; `;
} }
static getSecretDefinitionTemplate(p1, p2) { static getSecretDefinitionTemplate(p1, p2) {
return ` return `
- Name: '${p1}' - Name: '${p1}'
ValueFrom: !Ref ${p2}Secret ValueFrom: !Ref ${p2}Secret
`; `;
} }
static insertAtTemplate(template, insertionKey, insertion) { static insertAtTemplate(template, insertionKey, insertion) {
@ -1883,8 +1889,8 @@ class KubernetesJobSpecFactory {
command: [ command: [
'bin/bash', 'bin/bash',
'-c', '-c',
`cd /data/builder/action/steps; `cd /data/builder/action/steps;
chmod +x /return_license.sh; chmod +x /return_license.sh;
/return_license.sh;`, /return_license.sh;`,
], ],
}, },
@ -2691,23 +2697,23 @@ class BuildStep {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
cloud_runner_logger_1.default.logLine('Starting part 2/2 (build unity project)'); cloud_runner_logger_1.default.logLine('Starting part 2/2 (build unity project)');
yield cloud_runner_state_1.CloudRunnerState.CloudRunnerProviderPlatform.runTask(cloud_runner_state_1.CloudRunnerState.buildGuid, image, [ yield cloud_runner_state_1.CloudRunnerState.CloudRunnerProviderPlatform.runTask(cloud_runner_state_1.CloudRunnerState.buildGuid, image, [
` `
export GITHUB_WORKSPACE="${cloud_runner_state_1.CloudRunnerState.repoPathFull}" export GITHUB_WORKSPACE="${cloud_runner_state_1.CloudRunnerState.repoPathFull}"
cp -r "${cloud_runner_state_1.CloudRunnerState.builderPathFull}/dist/default-build-script/" "/UnityBuilderAction" cp -r "${cloud_runner_state_1.CloudRunnerState.builderPathFull}/dist/default-build-script/" "/UnityBuilderAction"
cp -r "${cloud_runner_state_1.CloudRunnerState.builderPathFull}/dist/entrypoint.sh" "/entrypoint.sh" cp -r "${cloud_runner_state_1.CloudRunnerState.builderPathFull}/dist/entrypoint.sh" "/entrypoint.sh"
cp -r "${cloud_runner_state_1.CloudRunnerState.builderPathFull}/dist/steps/" "/steps" cp -r "${cloud_runner_state_1.CloudRunnerState.builderPathFull}/dist/steps/" "/steps"
chmod -R +x "/entrypoint.sh" chmod -R +x "/entrypoint.sh"
chmod -R +x "/steps" chmod -R +x "/steps"
/entrypoint.sh /entrypoint.sh
apk update -q apk update -q
apk add zip tree -q apk add zip tree -q
cd "$libraryFolderFull/.." cd "$libraryFolderFull/.."
zip -r "lib-$BUILDID.zip" "./Library" zip -r "lib-$BUILDID.zip" "./Library"
mv "lib-$BUILDID.zip" "/$cacheFolderFull/lib" mv "lib-$BUILDID.zip" "/$cacheFolderFull/lib"
cd "$repoPathFull" cd "$repoPathFull"
ls -lh "$repoPathFull" ls -lh "$repoPathFull"
zip -r "build-$BUILDID.zip" "./${cloud_runner_state_1.CloudRunnerState.buildParams.buildPath}" zip -r "build-$BUILDID.zip" "./${cloud_runner_state_1.CloudRunnerState.buildParams.buildPath}"
mv "build-$BUILDID.zip" "/$cacheFolderFull/build-$BUILDID.zip" mv "build-$BUILDID.zip" "/$cacheFolderFull/build-$BUILDID.zip"
`, `,
], `/${cloud_runner_state_1.CloudRunnerState.buildVolumeFolder}`, `/${cloud_runner_state_1.CloudRunnerState.projectPathFull}`, environmentVariables, secrets); ], `/${cloud_runner_state_1.CloudRunnerState.buildVolumeFolder}`, `/${cloud_runner_state_1.CloudRunnerState.projectPathFull}`, environmentVariables, secrets);
}); });
@ -2755,15 +2761,15 @@ class SetupStep {
try { try {
cloud_runner_logger_1.default.logLine('Starting step 1/2 download game files from repository, try to use cache'); cloud_runner_logger_1.default.logLine('Starting step 1/2 download game files from repository, try to use cache');
yield cloud_runner_state_1.CloudRunnerState.CloudRunnerProviderPlatform.runTask(cloud_runner_state_1.CloudRunnerState.buildGuid, image, [ yield cloud_runner_state_1.CloudRunnerState.CloudRunnerProviderPlatform.runTask(cloud_runner_state_1.CloudRunnerState.buildGuid, image, [
` `
apk update -q apk update -q
apk add unzip zip git-lfs jq tree nodejs -q apk add unzip zip git-lfs jq tree nodejs -q
export GIT_DISCOVERY_ACROSS_FILESYSTEM=1 export GIT_DISCOVERY_ACROSS_FILESYSTEM=1
mkdir -p ${cloud_runner_state_1.CloudRunnerState.builderPathFull} mkdir -p ${cloud_runner_state_1.CloudRunnerState.builderPathFull}
echo "${cloud_runner_state_1.CloudRunnerState.cloneBuilderCommand}" echo "${cloud_runner_state_1.CloudRunnerState.cloneBuilderCommand}"
${cloud_runner_state_1.CloudRunnerState.cloneBuilderCommand} ${cloud_runner_state_1.CloudRunnerState.cloneBuilderCommand}
chmod +x ${cloud_runner_state_1.CloudRunnerState.builderPathFull}/dist/index.js chmod +x ${cloud_runner_state_1.CloudRunnerState.builderPathFull}/dist/index.js
node ${cloud_runner_state_1.CloudRunnerState.builderPathFull}/dist/index.js -m remote-cli node ${cloud_runner_state_1.CloudRunnerState.builderPathFull}/dist/index.js -m remote-cli
`, `,
], `/${cloud_runner_state_1.CloudRunnerState.buildVolumeFolder}`, `/${cloud_runner_state_1.CloudRunnerState.buildVolumeFolder}/`, environmentVariables, secrets); ], `/${cloud_runner_state_1.CloudRunnerState.buildVolumeFolder}`, `/${cloud_runner_state_1.CloudRunnerState.buildVolumeFolder}/`, environmentVariables, secrets);
} }
@ -3116,7 +3122,7 @@ class ImageEnvironmentFactory {
const environmentVariables = ImageEnvironmentFactory.getEnvironmentVariables(parameters); const environmentVariables = ImageEnvironmentFactory.getEnvironmentVariables(parameters);
let string = ''; let string = '';
for (const p of environmentVariables) { for (const p of environmentVariables) {
string += `--env ${p.name}="${p.value}" \ string += `--env ${p.name}="${p.value}" \
`; `;
} }
return string; return string;
@ -3261,8 +3267,8 @@ class ImageTag {
case platform_1.default.types.Test: case platform_1.default.types.Test:
return generic; return generic;
default: default:
throw new Error(` throw new Error(`
Platform must be one of the ones described in the documentation. Platform must be one of the ones described in the documentation.
"${platform}" is currently not supported.`); "${platform}" is currently not supported.`);
} }
} }

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -1,15 +1,21 @@
import { exec } from 'child_process';
import CloudRunnerLogger from '../../cloud-runner/services/cloud-runner-logger'; import CloudRunnerLogger from '../../cloud-runner/services/cloud-runner-logger';
import System from '../../system';
export class RemoteClientSystem { export class RemoteClientSystem {
public static async Run(command: string) { public static async Run(command: string) {
try { return await new Promise<string>((promise) => {
const result = await System.run(command); exec(command, (error, stdout, stderr) => {
CloudRunnerLogger.logRemoteCli(`${result}`); if (error) {
return result; CloudRunnerLogger.logRemoteCli(`[ERROR] ${error.message}`);
} catch (error) { throw new Error(error.toString());
CloudRunnerLogger.logRemoteCli(`[ERROR] (${command}) ${error}`); }
throw error; if (stderr) {
} CloudRunnerLogger.logRemoteCli(`[STD-ERROR] ${stderr.toString()}`);
throw new Error(stderr.toString());
}
CloudRunnerLogger.logRemoteCli(`${stdout.toString()}`);
promise(stdout.toString());
});
});
} }
} }

View File

@ -145,6 +145,7 @@ export class SetupRemoteRepository {
); );
await RemoteClientSystem.Run(`ls -lh`); await RemoteClientSystem.Run(`ls -lh`);
await RemoteClientSystem.Run(`tree`); await RemoteClientSystem.Run(`tree`);
await RemoteClientSystem.Run(`${CloudRunnerState.buildParams.gitSha}`);
await RemoteClientSystem.Run(`git checkout ${CloudRunnerState.buildParams.gitSha}`); await RemoteClientSystem.Run(`git checkout ${CloudRunnerState.buildParams.gitSha}`);
CloudRunnerLogger.logRemoteCli(`Checked out ${process.env.GITHUB_SHA}`); CloudRunnerLogger.logRemoteCli(`Checked out ${process.env.GITHUB_SHA}`);
} }