@@ -145155,61 +145155,57 @@ function buildJitRunCommands(encodedJitConfig) {
145155145155 return userData;
145156145156}
145157145157
145158- // Build user data as a cloud-boothook (runs during cloud-init init stage,
145159- // bypassing cloud_final_modules which may be empty on some AMIs)
145158+ // Build cloud-init YAML user data
145160145159function buildUserDataScript(githubRegistrationToken, label, encodedJitConfig) {
145160+ // 1. Get the list of shell commands (keep your new buildRunCommands logic!)
145161145161 const runCommands = encodedJitConfig
145162145162 ? buildJitRunCommands(encodedJitConfig)
145163145163 : buildRunCommands(githubRegistrationToken, label);
145164145164
145165- const lines = [];
145165+ // 2. Start the YAML content
145166+ let yamlContent = '#cloud-config\n';
145166145167
145167- // cloud-boothook header — processed during init stage, not final stage
145168- lines.push('#cloud-boothook');
145169- lines.push('#!/bin/bash');
145170- lines.push('# Guard: only run once per boot');
145171- lines.push('[ -f /run/runner-setup-started ] && exit 0');
145172- lines.push('touch /run/runner-setup-started');
145173- lines.push('');
145168+ // 3. Add packages if specified
145169+ if (config.input.packages && config.input.packages.length > 0) {
145170+ yamlContent += 'packages:\n';
145171+ config.input.packages.forEach(pkg => {
145172+ yamlContent += ` - ${pkg}\n`;
145173+ });
145174+ }
145175+
145176+ // 4. write_files section
145177+ yamlContent += 'write_files:\n';
145174145178
145175145179 // Write pre-runner script
145176- lines.push("cat > /tmp/pre-runner-script.sh << 'PRERUNNEREOF'");
145180+ yamlContent += ' - path: /tmp/pre-runner-script.sh\n';
145181+ yamlContent += ' permissions: "0755"\n';
145182+ yamlContent += ' content: |\n';
145177145183 if (config.input.preRunnerScript) {
145178- lines.push(config.input.preRunnerScript);
145184+ // Indent the script content for YAML
145185+ config.input.preRunnerScript.split('\n').forEach(line => {
145186+ yamlContent += ` ${line}\n`;
145187+ });
145179145188 } else {
145180- lines.push(' #!/bin/bash') ;
145189+ yamlContent += ' #!/bin/bash\n' ;
145181145190 }
145182- lines.push('PRERUNNEREOF');
145183- lines.push('chmod 755 /tmp/pre-runner-script.sh');
145184- lines.push('');
145185145191
145186- // Install packages if specified
145187- if (config.input.packages && config.input.packages.length > 0) {
145188- const pkgList = config.input.packages.join(' ');
145189- lines.push(`echo "[BOOTHOOK] Installing packages: ${pkgList}"`);
145190- lines.push(`yum install -y ${pkgList} || apt-get install -y ${pkgList} || echo "[BOOTHOOK] WARNING: package installation failed"`);
145191- }
145192+ // Write main setup script
145193+ yamlContent += ' - path: /opt/runner-setup.sh\n';
145194+ yamlContent += ' permissions: "0755"\n';
145195+ yamlContent += ' content: |\n';
145192145196
145193- // Write the setup script to /opt/ using heredoc (quoted delimiter = no variable expansion)
145194- lines.push("cat > /opt/runner-setup.sh << 'RUNNERSETUPEOF'");
145195- for (let i = 0; i < runCommands.length; i++) {
145196- lines.push(runCommands[i]);
145197- }
145198- lines.push('RUNNERSETUPEOF');
145199- lines.push('chmod 755 /opt/runner-setup.sh');
145200- lines.push('');
145201-
145202- // Execute setup in background so boothook returns quickly and doesn't block cloud-init
145203- lines.push('nohup /opt/runner-setup.sh &');
145204-
145205- const script = lines.join('\n') + '\n';
145197+ // Add each line of the command list (from buildRunCommands)
145198+ runCommands.forEach(line => {
145199+ yamlContent += ` ${line}\n`;
145200+ });
145206145201
145207- core.info('User data script is built successfully');
145208- if (config.input.runnerDebug) {
145209- core.info(`User data script content:\n${script}`);
145210- }
145202+ // 5. runcmd section - This runs AFTER Docker is up
145203+ yamlContent += 'runcmd:\n';
145204+ // We still use nohup just in case cloud-init kills the process group,
145205+ // but now the environment is fully ready.
145206+ yamlContent += ' - nohup /opt/runner-setup.sh &\n';
145211145207
145212- return script ;
145208+ return yamlContent ;
145213145209}
145214145210
145215145211function buildMarketOptions() {
0 commit comments