-
Notifications
You must be signed in to change notification settings - Fork 25
Add workflow for building runner image #149
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
Merged
Changes from all commits
Commits
Show all changes
73 commits
Select commit
Hold shift + click to select a range
00f37c3
Add workflow for building runner image
yhaliaw aa8d1b6
Add debug of workflow
yhaliaw 4d35d9f
Fix bug
yhaliaw 4476080
Add proxy configuration
yhaliaw b13b401
Push yq to image
yhaliaw fca6c76
Add sudo in build scripts
yhaliaw 5e7a226
Convert file permission
yhaliaw 5a533f0
Add download and loading of LXD image from GitHub
yhaliaw 7f02713
Merge branch 'main' into feat/build-image
yhaliaw d5c1e0c
Fix runner.py post-merge
yhaliaw 2fa9e02
Update scripts/build-image.sh
yhaliaw 614becf
Fix wrong series used
yhaliaw 65642c6
Fix bug with passing token to GhApi
yhaliaw 5777c71
Test existing integration test
yhaliaw 7b4a8e5
Add download of runner image
yhaliaw 2d87fb6
Only download runner image on new image
yhaliaw d970ebb
Merge branch 'main' into feat/build-image
yhaliaw 4822c11
Add download of runner image during install
yhaliaw 47fadea
Fix unit
yhaliaw b92716b
Test building of container images
yhaliaw 872bd48
Download container image in test mode
yhaliaw 7b64280
Test image built
yhaliaw c7144f8
Fix shebang line
yhaliaw 4b710aa
Fix shell lint
yhaliaw 7bd2d9c
Remove build-image workflow test
yhaliaw 7ef5397
Add delete_runner method in github client
yhaliaw 528a9fe
Merge branch 'main' into feat/build-image
yhaliaw 276ba22
Fix integration test
yhaliaw 66b3f6c
Change unsigned commit to stale review for integration test failure
yhaliaw cfca983
Change unsigned commit to stale review for integration test failure
yhaliaw 4f18f41
Build image within the charm
yhaliaw 5f30437
Merge branch 'main' into feat/build-image
yhaliaw 2cc70d5
Move build script to src
yhaliaw a3acdf5
Fix build-image.sh script
yhaliaw 44f818f
Prevent error during first build of image
yhaliaw d3124b9
Merge branch 'main' into feat/build-image
yhaliaw 94bcd86
Move build script location
yhaliaw f3e8a99
Await on constaint
yhaliaw 2d71d43
Fix filename
yhaliaw 247bb66
Fix build script
yhaliaw 056f0d1
Fix typo
yhaliaw 79b9926
Merge branch 'main' into feat/build-image
yhaliaw 89545b0
Fix integration test
yhaliaw 02f9b00
Remove -x option from build-image.sh
yhaliaw f5e4f53
Add support for arm64
yhaliaw 23ef5af
Revert some integration test change
yhaliaw aa75c03
Fix bash error
yhaliaw 0e75dde
Increase memory for integration test
yhaliaw efda7c4
Build image every 6 hours
yhaliaw b4f6c36
Merge branch 'main' into feat/build-image
yhaliaw c3444df
Add retry to build script
yhaliaw 2431eca
Fix bash script
yhaliaw 6c9793c
Merge branch 'main' into feat/build-image
yhaliaw 6bb6504
Merge with main
yhaliaw 0d0c858
Remove files
yhaliaw e795130
Fix arm64 support
yhaliaw 37d3be8
Fix bash lints
yhaliaw 62851f8
Fix bash script
yhaliaw 7b26c15
Fix linting
yhaliaw cc1bb58
Reduce the amount of memory used
yhaliaw a0e711d
Add limit to number of cleanup
yhaliaw 10a34eb
Remove files
yhaliaw 34d0f52
Remove unused function
yhaliaw 1007d45
Add docstrings
yhaliaw 5cd0f4b
Remove extra new line.
yhaliaw 6e7cdf9
Update comments on randomized time for cron job
yhaliaw f3be7e7
Fix yarn installation
yhaliaw ba55edd
Update src/lxd.py
yhaliaw c5236d1
Reverse naming change
yhaliaw 8673c70
Pin integration test dep macaroonbakery
yhaliaw 77c3fed
Update detection of CPU arch
yhaliaw 52b5d7a
Update docs
yhaliaw ae68a59
Fix sctp test
yhaliaw 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
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
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,104 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Copyright 2023 Canonical Ltd. | ||
| # See LICENSE file for licensing details. | ||
|
|
||
| set -e | ||
|
|
||
| retry() { | ||
| local command="$1" | ||
| local wait_message="$2" | ||
| local max_try="$3" | ||
|
|
||
| local attempt=0 | ||
|
|
||
| while ! $command | ||
| do | ||
| attempt=$((attempt + 1)) | ||
| if [[ attempt -ge $max_try ]]; then | ||
| return | ||
| fi | ||
|
|
||
| echo "$wait_message" | ||
| sleep 10 | ||
| done | ||
| } | ||
|
|
||
| cleanup() { | ||
| local test_command="$1" | ||
| local clean_up_command="$2" | ||
| local wait_message="$3" | ||
| local max_try="$4" | ||
|
|
||
| local attempt=0 | ||
|
|
||
| while bash -c "$test_command" | ||
| do | ||
| echo "$wait_message" | ||
|
|
||
| $clean_up_command | ||
|
|
||
| attempt=$((attempt + 1)) | ||
| if [[ attempt -ge $max_try ]]; then | ||
| # Cleanup failure. | ||
| return 1 | ||
| fi | ||
|
|
||
| sleep 10 | ||
| done | ||
| } | ||
|
|
||
| cleanup '/snap/bin/lxc info builder &> /dev/null' '/snap/bin/lxc delete builder --force' 'Cleanup LXD VM of previous run' 10 | ||
|
|
||
| if [[ "$1" == "test" ]]; then | ||
| retry '/snap/bin/lxc launch ubuntu-daily:jammy builder --device root,size=5GiB' 'Starting LXD VM' | ||
|
yhaliaw marked this conversation as resolved.
|
||
| else | ||
| retry '/snap/bin/lxc launch ubuntu-daily:jammy builder --vm --device root,size=5GiB' 'Starting LXD container' | ||
| fi | ||
| retry '/snap/bin/lxc exec builder -- /usr/bin/who' 'Wait for lxd agent to be ready' 30 | ||
| retry '/snap/bin/lxc exec builder -- /usr/bin/nslookup github.com' 'Wait for network to be ready' 30 | ||
|
|
||
| /snap/bin/lxc exec builder -- /usr/bin/apt-get update | ||
| /snap/bin/lxc exec builder --env DEBIAN_FRONTEND=noninteractive -- /usr/bin/apt-get upgrade -yq | ||
| /snap/bin/lxc exec builder --env DEBIAN_FRONTEND=noninteractive -- /usr/bin/apt-get install linux-generic-hwe-22.04 -yq | ||
|
|
||
| /snap/bin/lxc restart builder | ||
| retry '/snap/bin/lxc exec builder -- /usr/bin/who' 'Wait for lxd agent to be ready' 30 | ||
| retry '/snap/bin/lxc exec builder -- /usr/bin/nslookup github.com' 'Wait for network to be ready' 30 | ||
|
|
||
| /snap/bin/lxc exec builder -- /usr/bin/apt-get update | ||
| /snap/bin/lxc exec builder --env DEBIAN_FRONTEND=noninteractive -- /usr/bin/apt-get upgrade -yq | ||
| /snap/bin/lxc exec builder --env DEBIAN_FRONTEND=noninteractive -- /usr/bin/apt-get install docker.io npm python3-pip shellcheck jq wget -yq | ||
| /snap/bin/lxc exec builder -- /usr/bin/npm install --global yarn | ||
| /snap/bin/lxc exec builder -- /usr/sbin/groupadd microk8s | ||
| /snap/bin/lxc exec builder -- /usr/sbin/usermod -aG microk8s ubuntu | ||
| /snap/bin/lxc exec builder -- /usr/sbin/usermod -aG docker ubuntu | ||
| /snap/bin/lxc exec builder -- /usr/sbin/iptables -I DOCKER-USER -j ACCEPT | ||
|
|
||
| # Download and verify checksum of yq | ||
| if [[ $(uname -m) == 'aarch64' ]]; then | ||
| YQ_ARCH="arm64" | ||
| elif [[ $(uname -m) == 'arm64' ]]; then | ||
| YQ_ARCH="arm64" | ||
| elif [[ $(uname -m) == 'x86_64' ]]; then | ||
| YQ_ARCH="amd64" | ||
| else | ||
| echo "Unsupported CPU architecture: $(uname -m)" | ||
| return 1 | ||
| fi | ||
| /usr/bin/wget "https://github.com/mikefarah/yq/releases/latest/download/yq_linux_$YQ_ARCH" | ||
| /usr/bin/wget https://github.com/mikefarah/yq/releases/latest/download/checksums | ||
| /usr/bin/wget https://github.com/mikefarah/yq/releases/latest/download/checksums_hashes_order | ||
| /usr/bin/wget https://github.com/mikefarah/yq/releases/latest/download/extract-checksum.sh | ||
| /usr/bin/bash extract-checksum.sh SHA-256 "yq_linux_$YQ_ARCH" | /usr/bin/awk '{print $2,$1}' | /usr/bin/sha256sum -c | /usr/bin/grep OK | ||
| /snap/bin/lxc file push "yq_linux_$YQ_ARCH" builder/usr/bin/yq --mode 755 | ||
|
|
||
| /snap/bin/lxc publish builder --alias builder --reuse -f | ||
|
|
||
| # Swap in the built image | ||
| /snap/bin/lxc image alias rename runner old-runner || true | ||
| /snap/bin/lxc image alias rename builder runner | ||
| /snap/bin/lxc image delete old-runner || true | ||
|
|
||
| # Clean up LXD instance | ||
| cleanup '/snap/bin/lxc info builder &> /dev/null' '/snap/bin/lxc delete builder --force' 'Cleanup LXD VM' 10 | ||
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,144 @@ | ||
| <!-- markdownlint-disable --> | ||
|
|
||
| <a href="../src/github_client.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a> | ||
|
|
||
| # <kbd>module</kbd> `github_client.py` | ||
| GitHub API client. | ||
|
|
||
| Migrate to PyGithub in the future. PyGithub is still lacking some API such as remove token for runner. | ||
|
|
||
|
|
||
|
|
||
| --- | ||
|
|
||
| ## <kbd>class</kbd> `GithubClient` | ||
| GitHub API client. | ||
|
|
||
| <a href="../src/github_client.py#L25"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a> | ||
|
|
||
| ### <kbd>function</kbd> `__init__` | ||
|
|
||
| ```python | ||
| __init__(token: str, request_session: Session) | ||
| ``` | ||
|
|
||
| Instantiate the GiHub API client. | ||
|
|
||
|
|
||
|
|
||
| **Args:** | ||
|
|
||
| - <b>`token`</b>: GitHub personal token for API requests. | ||
| - <b>`request_session`</b>: Requests session for HTTP requests. | ||
|
|
||
|
|
||
|
|
||
|
|
||
| --- | ||
|
|
||
| <a href="../src/github_client.py#L142"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a> | ||
|
|
||
| ### <kbd>function</kbd> `delete_runner` | ||
|
|
||
| ```python | ||
| delete_runner(path: Union[GithubOrg, GithubRepo], runner_id: int) → None | ||
| ``` | ||
|
|
||
| Delete the self-hosted runner from GitHub. | ||
|
|
||
|
|
||
|
|
||
| **Args:** | ||
|
|
||
| - <b>`path`</b>: GitHub repository path in the format '<owner>/<repo>', or the GitHub organization name. | ||
| - <b>`runner_id`</b>: Id of the runner. | ||
|
|
||
| --- | ||
|
|
||
| <a href="../src/github_client.py#L36"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a> | ||
|
|
||
| ### <kbd>function</kbd> `get_runner_applications` | ||
|
|
||
| ```python | ||
| get_runner_applications( | ||
| path: Union[GithubOrg, GithubRepo] | ||
| ) → List[RunnerApplication] | ||
| ``` | ||
|
|
||
| Get list of runner applications available for download. | ||
|
|
||
|
|
||
|
|
||
| **Args:** | ||
|
|
||
| - <b>`path`</b>: GitHub repository path in the format '<owner>/<repo>', or the GitHub organization name. | ||
|
|
||
| **Returns:** | ||
| List of runner applications. | ||
|
|
||
| --- | ||
|
|
||
| <a href="../src/github_client.py#L55"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a> | ||
|
|
||
| ### <kbd>function</kbd> `get_runner_github_info` | ||
|
|
||
| ```python | ||
| get_runner_github_info( | ||
| path: Union[GithubOrg, GithubRepo] | ||
| ) → list[SelfHostedRunner] | ||
| ``` | ||
|
|
||
| Get runner information on GitHub under a repo or org. | ||
|
|
||
|
|
||
|
|
||
| **Args:** | ||
|
|
||
| - <b>`path`</b>: GitHub repository path in the format '<owner>/<repo>', or the GitHub organization name. | ||
|
|
||
|
|
||
|
|
||
| **Returns:** | ||
| List of runner information. | ||
|
|
||
| --- | ||
|
|
||
| <a href="../src/github_client.py#L120"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a> | ||
|
|
||
| ### <kbd>function</kbd> `get_runner_registration_token` | ||
|
|
||
| ```python | ||
| get_runner_registration_token(path: Union[GithubOrg, GithubRepo]) → str | ||
| ``` | ||
|
|
||
| Get token from GitHub used for registering runners. | ||
|
|
||
|
|
||
|
|
||
| **Args:** | ||
|
|
||
| - <b>`path`</b>: GitHub repository path in the format '<owner>/<repo>', or the GitHub organization name. | ||
|
|
||
|
|
||
|
|
||
| **Returns:** | ||
| The registration token. | ||
|
|
||
| --- | ||
|
|
||
| <a href="../src/github_client.py#L102"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a> | ||
|
|
||
| ### <kbd>function</kbd> `get_runner_remove_token` | ||
|
|
||
| ```python | ||
| get_runner_remove_token(path: Union[GithubOrg, GithubRepo]) → str | ||
| ``` | ||
|
|
||
| Get token from GitHub used for removing runners. | ||
|
|
||
|
|
||
|
|
||
| **Returns:** | ||
| The removing token. | ||
|
|
||
|
|
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.