pr feedback

This commit is contained in:
Frostebite
2025-12-11 02:59:45 +00:00
parent 8824ea4f18
commit 35c6d45981
6 changed files with 340 additions and 51 deletions

View File

@@ -29,8 +29,6 @@ class KubernetesTaskRunner {
`Streaming logs from pod: ${podName} container: ${containerName} namespace: ${namespace} ${CloudRunner.buildParameters.kubeVolumeSize}/${CloudRunner.buildParameters.containerCpu}/${CloudRunner.buildParameters.containerMemory}`,
);
const isRunning = await KubernetesPods.IsPodRunning(podName, namespace, kubeClient);
let extraFlags = ``;
extraFlags += isRunning ? ` -f -c ${containerName} -n ${namespace}` : ` --previous -n ${namespace}`;
const callback = (outputChunk: string) => {
output += outputChunk;
@@ -46,7 +44,14 @@ class KubernetesTaskRunner {
}
};
try {
await CloudRunnerSystem.Run(`kubectl logs ${podName}${extraFlags}`, false, true, callback);
// Always specify container name explicitly to avoid containerd:// errors
// Use -f for running pods, --previous for terminated pods
await CloudRunnerSystem.Run(
`kubectl logs ${podName} -c ${containerName} -n ${namespace}${isRunning ? ' -f' : ' --previous'}`,
false,
true,
callback,
);
} catch (error: any) {
await new Promise((resolve) => setTimeout(resolve, 3000));
const continueStreaming = await KubernetesPods.IsPodRunning(podName, namespace, kubeClient);

View File

@@ -48,20 +48,42 @@ export class RemoteClientLogger {
if (CloudRunnerOptions.providerStrategy !== 'k8s') {
return;
}
CloudRunnerLogger.log(`Collected Logs`);
const collectedLogsMessage = `Collected Logs`;
// For K8s, write to stdout so kubectl logs can capture it
// This is critical because kubectl logs reads from stdout/stderr, not from GitHub Actions logs
if (CloudRunnerOptions.providerStrategy === 'k8s') {
process.stdout.write(`${collectedLogsMessage}\n`, 'utf8');
process.stderr.write(`${collectedLogsMessage}\n`, 'utf8');
}
// Also log via CloudRunnerLogger for GitHub Actions
CloudRunnerLogger.log(collectedLogsMessage);
// check for log file not existing
if (!fs.existsSync(RemoteClientLogger.LogFilePath)) {
CloudRunnerLogger.log(`Log file does not exist`);
const logFileMissingMessage = `Log file does not exist`;
if (CloudRunnerOptions.providerStrategy === 'k8s') {
process.stdout.write(`${logFileMissingMessage}\n`, 'utf8');
}
CloudRunnerLogger.log(logFileMissingMessage);
// check if CloudRunner.isCloudRunnerEnvironment is true, log
if (!CloudRunner.isCloudRunnerEnvironment) {
CloudRunnerLogger.log(`Cloud Runner is not running in a cloud environment, not collecting logs`);
const notCloudEnvMessage = `Cloud Runner is not running in a cloud environment, not collecting logs`;
if (CloudRunnerOptions.providerStrategy === 'k8s') {
process.stdout.write(`${notCloudEnvMessage}\n`, 'utf8');
}
CloudRunnerLogger.log(notCloudEnvMessage);
}
return;
}
CloudRunnerLogger.log(`Log file exist`);
const logFileExistsMessage = `Log file exist`;
if (CloudRunnerOptions.providerStrategy === 'k8s') {
process.stdout.write(`${logFileExistsMessage}\n`, 'utf8');
}
CloudRunnerLogger.log(logFileExistsMessage);
await new Promise((resolve) => setTimeout(resolve, 1));
// let hashedLogs = fs.readFileSync(RemoteClientLogger.LogFilePath).toString();

View File

@@ -177,23 +177,25 @@ echo "CACHE_KEY=$CACHE_KEY"`;
if [ ! -f "/data/cache/$CACHE_KEY/build/build-$BUILD_GUID.tar" ] && [ ! -f "/data/cache/$CACHE_KEY/build/build-$BUILD_GUID.tar.lz4" ]; then
tar -cf "/data/cache/$CACHE_KEY/build/build-$BUILD_GUID.tar" --files-from /dev/null || touch "/data/cache/$CACHE_KEY/build/build-$BUILD_GUID.tar"
fi
# Run post-build tasks and pipe output through log stream to capture "Activation successful"
# Use set +e to allow the command to fail without exiting the script, then restore set -e behavior
set +e
node ${builderPath} -m remote-cli-post-build | node ${builderPath} -m remote-cli-log-stream --logFile /home/job-log.txt || echo "Post-build command completed with warnings"
set -e
# Write end marker and pipe through log stream
# Use set +e to prevent failure if builder path doesn't exist (builder might have been cleaned up)
# Keep set +e for the rest of the script to prevent exit on error
# Run post-build tasks and capture output
# Note: Post-build may clean up the builder directory, so we write output directly to log file
# Use set +e to allow the command to fail without exiting the script
set +e
# Run post-build and write output to both stdout (for K8s kubectl logs) and log file
# For local-docker, stdout is captured by the log stream mechanism
if [ -f "${builderPath}" ]; then
echo "end of cloud runner job" | node ${builderPath} -m remote-cli-log-stream --logFile /home/job-log.txt || echo "end of cloud runner job" >> /home/job-log.txt
echo "---${CloudRunner.buildParameters.logId}" | node ${builderPath} -m remote-cli-log-stream --logFile /home/job-log.txt || echo "---${CloudRunner.buildParameters.logId}" >> /home/job-log.txt
# Use tee to write to both stdout and log file, ensuring output is captured
# For K8s, kubectl logs reads from stdout, so we need stdout
# For local-docker, the log file is read directly
node ${builderPath} -m remote-cli-post-build 2>&1 | tee -a /home/job-log.txt || echo "Post-build command completed with warnings" | tee -a /home/job-log.txt
else
# Builder path doesn't exist, write directly to log file
echo "end of cloud runner job" >> /home/job-log.txt
echo "---${CloudRunner.buildParameters.logId}" >> /home/job-log.txt
# Builder doesn't exist, skip post-build (shouldn't happen, but handle gracefully)
echo "Builder path not found, skipping post-build" | tee -a /home/job-log.txt
fi
# Write end markers directly to log file (builder might be cleaned up by post-build)
# Also write to stdout for K8s kubectl logs
echo "end of cloud runner job" | tee -a /home/job-log.txt
echo "---${CloudRunner.buildParameters.logId}" | tee -a /home/job-log.txt
# Don't restore set -e - keep set +e to prevent script from exiting on error
# This ensures the script completes successfully even if some operations fail
# Mirror cache back into workspace for test assertions
@@ -213,11 +215,18 @@ echo "CACHE_KEY=$CACHE_KEY"`;
chmod -R +x "/entrypoint.sh"
chmod -R +x "/steps"
{ echo "game ci start"; echo "game ci start" >> /home/job-log.txt; echo "CACHE_KEY=$CACHE_KEY"; echo "$CACHE_KEY"; if [ -n "$LOCKED_WORKSPACE" ]; then echo "Retained Workspace: true"; fi; if [ -n "$LOCKED_WORKSPACE" ] && [ -d "$GITHUB_WORKSPACE/.git" ]; then echo "Retained Workspace Already Exists!"; fi; /entrypoint.sh; } | node ${builderPath} -m remote-cli-log-stream --logFile /home/job-log.txt
# Run post-build and ensure output is captured in logs
node ${builderPath} -m remote-cli-post-build | node ${builderPath} -m remote-cli-log-stream --logFile /home/job-log.txt || true
# Write end marker through log stream to ensure it's captured in BuildResults
echo "end of cloud runner job" | node ${builderPath} -m remote-cli-log-stream --logFile /home/job-log.txt
echo "---${CloudRunner.buildParameters.logId}" | node ${builderPath} -m remote-cli-log-stream --logFile /home/job-log.txt`;
# Run post-build and capture output to both stdout (for kubectl logs) and log file
# Note: Post-build may clean up the builder directory, so write output directly
set +e
if [ -f "${builderPath}" ]; then
# Use tee to write to both stdout and log file for K8s kubectl logs
node ${builderPath} -m remote-cli-post-build 2>&1 | tee -a /home/job-log.txt || echo "Post-build command completed with warnings" | tee -a /home/job-log.txt
else
echo "Builder path not found, skipping post-build" | tee -a /home/job-log.txt
fi
# Write end markers to both stdout and log file (builder might be cleaned up by post-build)
echo "end of cloud runner job" | tee -a /home/job-log.txt
echo "---${CloudRunner.buildParameters.logId}" | tee -a /home/job-log.txt`;
}
// prettier-ignore