Skip to content

Commit

Permalink
Try out an alternate way to run the runner registration script in VM
Browse files Browse the repository at this point in the history
  • Loading branch information
Tereius committed Aug 1, 2024
1 parent ad5d0cf commit f81f7c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion compute.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ mkdir -p /home/agent
chown -R agent:agent /home/agent
pushd /home/agent
sudo -u agent tar zxf /tmp/agent.tar.gz
registration_token=$(curl "http://metadata.google.internal/computeMetadata/v1/instance/attributes/registration_token" -H "Metadata-Flavor: Google")
registration_token=$1
sudo -u agent ./config.sh --unattended --disableupdate --ephemeral --name $(hostname) ${local.runnerLabelInstanceTemplate} --url 'https://github.com/${var.github_organization}' --token $${registration_token} --runnergroup '${var.github_runner_group}' || shutdown now
./bin/installdependencies.sh || shutdown now
./svc.sh install agent || shutdown now
Expand Down
13 changes: 8 additions & 5 deletions runner-autoscaler/pkg/srv.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,17 +399,20 @@ func (s *Autoscaler) handleCreateVm(ctx *gin.Context) {
if token, err := s.GenerateRunnerRegistrationToken(ctx); err != nil {
ctx.AbortWithError(http.StatusInternalServerError, err)
} else {
registration_token_attr := fmt.Sprintf("%s_%s", RUNNER_REGISTRATION_TOKEN_ATTR, randStringRunes(16))
if err := s.CreateInstanceFromTemplate(ctx, string(data), &computepb.Items{
Key: proto.String(RUNNER_REGISTRATION_TOKEN_ATTR),
Key: proto.String(registration_token_attr),
Value: proto.String(token),
}, &computepb.Items{
Key: proto.String(RUNNER_STARTUP_SCRIPT_ATTR),
Value: proto.String(fmt.Sprintf(`
#!/bin/bash
curl "http://metadata.google.internal/computeMetadata/v1/instance/attributes/%s" -H "Metadata-Flavor: Google" > runner_startup.sh
chmod +x runner_startup.sh
./runner_startup.sh
`, RUNNER_STARTUP_SCRIPT_ATTR)),
registration_token=$(curl "http://metadata.google.internal/computeMetadata/v1/instance/attributes/%s" -H "Metadata-Flavor: Google")
curl "http://metadata.google.internal/computeMetadata/v1/project/attributes/%s" -H "Metadata-Flavor: Google" > runner_startup.sh
chmod +x ./runner_startup.sh
./runner_startup.sh $registration_token
rm runner_startup.sh
`, registration_token_attr, RUNNER_STARTUP_SCRIPT_ATTR)),
}); err != nil {
ctx.AbortWithError(http.StatusInternalServerError, err)
} else {
Expand Down

0 comments on commit f81f7c5

Please sign in to comment.