Skip to content

Commit

Permalink
Adds support for post-boot script (#77)
Browse files Browse the repository at this point in the history
* Renames boot.sh to start-runner.sh

* Runs post-boot.sh if it exists
  • Loading branch information
simonbs committed Apr 23, 2024
1 parent c3fb477 commit 4a97607
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public struct GitHubActionsRunnerSSHConnectionHandler: VirtualMachineSSHConnecti
with: appAccessToken,
runnerScope: configuration.runnerScope
)
let bootScriptFilePath = "~/boot.sh"
try await connection.executeCommand("touch \(bootScriptFilePath)")
let startRunnerScriptFilePath = "~/start-runner.sh"
try await connection.executeCommand("touch \(startRunnerScriptFilePath)")
try await connection.executeCommand("""
cat > \(bootScriptFilePath) << EOF
cat > \(startRunnerScriptFilePath) << EOF
#!/bin/zsh
ACTIONS_RUNNER_ARCHIVE=./actions-runner.tar.gz
ACTIONS_RUNNER_DIRECTORY=~/actions-runner
Expand Down Expand Up @@ -111,8 +111,8 @@ cd \\$ACTIONS_RUNNER_DIRECTORY
./run.sh
EOF
""")
try await connection.executeCommand("chmod +x \(bootScriptFilePath)")
try await connection.executeCommand("open -a Terminal \(bootScriptFilePath)")
try await connection.executeCommand("chmod +x \(startRunnerScriptFilePath)")
try await connection.executeCommand("open -a Terminal \(startRunnerScriptFilePath)")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import SSHDomain

public struct PostBootScriptSSHConnectionHandler: VirtualMachineSSHConnectionHandler {
public init() {}

public func didConnect(to virtualMachine: VirtualMachine, through connection: SSHConnection) async throws {
try await connection.executeCommand("""
export RUNNER_NAME=\(virtualMachine.name)
POST_BOOT_SCRIPT_PATH="$HOME/.tartelet/post-boot.sh"
if [ -f "$POST_BOOT_SCRIPT_PATH" ]; then
sh $POST_BOOT_SCRIPT_PATH
fi
""")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import SSHDomain

public struct CompositeVirtualMachineSSHConnectionHandler: VirtualMachineSSHConnectionHandler {
private let handlers: [VirtualMachineSSHConnectionHandler]

public init(_ handlers: [VirtualMachineSSHConnectionHandler]) {
self.handlers = handlers
}

public func didConnect(to virtualMachine: VirtualMachine, through connection: SSHConnection) async throws {
for handler in handlers {
try await handler.didConnect(to: virtualMachine, through: connection)
}
}
}
23 changes: 13 additions & 10 deletions Tartelet/Sources/Composers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,22 @@ enum Composers {
),
ipAddressReader: RetryingVirtualMachineIPAddressReader(),
credentialsStore: virtualMachineSSHCredentialsStore,
connectionHandler: GitHubActionsRunnerSSHConnectionHandler(
logger: logger(subsystem: "GitHubActionsRunnerSSHConnectionHandler"),
client: NetworkingGitHubClient(
connectionHandler: CompositeVirtualMachineSSHConnectionHandler([
PostBootScriptSSHConnectionHandler(),
GitHubActionsRunnerSSHConnectionHandler(
logger: logger(subsystem: "GitHubActionsRunnerSSHConnectionHandler"),
client: NetworkingGitHubClient(
credentialsStore: gitHubCredentialsStore,
networkingService: URLSessionNetworkingService(
logger: logger(subsystem: "URLSessionNetworkingService")
)
),
credentialsStore: gitHubCredentialsStore,
networkingService: URLSessionNetworkingService(
logger: logger(subsystem: "URLSessionNetworkingService")
configuration: SettingsGitHubActionsRunnerConfiguration(
settingsStore: settingsStore
)
),
credentialsStore: gitHubCredentialsStore,
configuration: SettingsGitHubActionsRunnerConfiguration(
settingsStore: settingsStore
)
)
])
)
)
)
Expand Down

0 comments on commit 4a97607

Please sign in to comment.