-
Notifications
You must be signed in to change notification settings - Fork 1
feat: implement Hetzner server management and update Probot integration #476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
3905bfb
feat: implement Hetzner server management and update Probot integration
mafreud 1f74e06
feat: add runner requirement check for workflow jobs
mafreud 5245bdb
feat: implement job requirement check for OpenCI runner in Probot int…
mafreud e84d796
feat: add logging for workflow job events in Probot integration
mafreud 63d0406
refactor: rename deploy step for clarity in Firebase functions workflow
mafreud 4844dab
feat: add @octokit/rest dependency to package.json and package-lock.json
mafreud 7c49e1a
feat: add Hetzner API secrets to GitHub webhook configuration
mafreud 1b05ea2
feat: add Hetzner API secrets to GitHub webhook configuration
mafreud 15794c8
fix: add missing return statements in workflow job event handlers
mafreud 66b9da5
fix: ensure proper handling of response in GitHub webhook function
mafreud 649f051
fix: ensure consistent resource allocation for GitHub webhook function
mafreud 171438e
fix: reduce CPU allocation for GitHub webhook function
mafreud 2ee11f7
fix: reduce memory allocation for GitHub webhook function
mafreud 5c8a4de
fix: remove explicit CPU and memory allocation for GitHub webhook fun…
mafreud eb04987
fix: ensure consistent resource allocation for GitHub webhook function
mafreud a059c31
fix: implement matrix strategy for CI and deployment runners
mafreud ce5975e
fix: add error handling for missing environment variables and SSH con…
mafreud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import type { Octokit } from "@octokit/rest"; | ||
|
|
||
| const baseUrl = "https://api.hetzner.cloud/v1/servers"; | ||
|
|
||
| export interface OctokitToken { | ||
| token: string; | ||
| } | ||
|
|
||
| export async function deleteServer(id: string, apiKey: string) { | ||
| await fetch(`${baseUrl}/${id}`, { | ||
| method: "DELETE", | ||
| headers: { | ||
| Authorization: `Bearer ${apiKey}`, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| export type HetznerResponse = { | ||
| serverId: number; | ||
| ipv4: string; | ||
| }; | ||
|
|
||
| export async function createServer(apiKey: string): Promise<HetznerResponse> { | ||
| const body = { | ||
| name: crypto.randomUUID(), | ||
| location: "fsn1", | ||
| server_type: "cpx41", | ||
| image: "ubuntu-24.04", | ||
| ssh_keys: ["openci-runner-probot"], | ||
| }; | ||
|
|
||
| const response = await fetch(baseUrl, { | ||
| method: "POST", | ||
| headers: { | ||
| Authorization: `Bearer ${apiKey}`, | ||
| }, | ||
| body: JSON.stringify(body), | ||
| }); | ||
mafreud marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const responseJson = await response.json(); | ||
|
|
||
| const server = responseJson.server; | ||
| const ipv4 = server.public_net.ipv4.ip; | ||
|
|
||
| const serverId = server.id; | ||
|
|
||
| return { | ||
| serverId: serverId, | ||
| ipv4: ipv4, | ||
| }; | ||
| } | ||
|
|
||
| export async function getServerStatusById( | ||
| serverId: number, | ||
| apiKey: string, | ||
| ): Promise<string> { | ||
| const _response = await fetch(`${baseUrl}/${serverId}`, { | ||
| headers: { | ||
| Authorization: `Bearer ${apiKey}`, | ||
| }, | ||
| }); | ||
| const jsonRes = await _response.json(); | ||
| return jsonRes.server.status; | ||
| } | ||
|
|
||
| export async function getJitConfig( | ||
| octokit: Octokit, | ||
| owner: string, | ||
| repo: string, | ||
| serverId: number, | ||
| ): Promise<string> { | ||
| const jitConfigRes = await octokit.request( | ||
| `POST /repos/{owner}/{repo}/actions/runners/generate-jitconfig`, | ||
| { | ||
| owner: `${owner}`, | ||
| repo: `${repo}`, | ||
| name: `OpenCI ランナー ${serverId}`, | ||
| runner_group_id: 1, | ||
| labels: ["openci-runner-beta"], | ||
| work_folder: "_work", | ||
| headers: { | ||
| "X-GitHub-Api-Version": "2022-11-28", | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| return jitConfigRes.data.encoded_jit_config; | ||
| } | ||
|
|
||
| export function initRunner(runnerConfig: string): string { | ||
| const command = ` | ||
| mkdir actions-runner | ||
| cd actions-runner | ||
| curl -o actions-runner-linux-x64-2.328.0.tar.gz -L https://github.com/actions/runner/releases/download/v2.328.0/actions-runner-linux-x64-2.328.0.tar.gz | ||
| tar xzf ./actions-runner-linux-x64-2.328.0.tar.gz | ||
| tmux new -d -s runner "RUNNER_ALLOW_RUNASROOT=true ./run.sh --jitconfig ${runnerConfig}" | ||
| `; | ||
| return command; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.