From c73cb0eb825fc1a8a9aed6ecc242c2292e4ad6f3 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Thu, 15 Jun 2023 19:00:18 +0800 Subject: [PATCH 001/113] WIP --- .github/workflows/end_to_end_test.yaml | 9 +++++++-- .github/workflows/start_e2e_test.yaml | 16 ++++++++++++++++ src/charm.py | 3 ++- src/lxd.py | 15 ++++++++++++++- src/runner.py | 6 +++--- 5 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/start_e2e_test.yaml diff --git a/.github/workflows/end_to_end_test.yaml b/.github/workflows/end_to_end_test.yaml index 98510a44b..a2372956b 100644 --- a/.github/workflows/end_to_end_test.yaml +++ b/.github/workflows/end_to_end_test.yaml @@ -1,14 +1,19 @@ name: End to end tests on: - pull_request: workflow_call: + inputs: + test-runner: + required: true workflow_dispatch: + inputs: + test-runner: + required: true jobs: e2e-test: name: end to end test - runs-on: [self-hosted, linux, x64, e2e-runner] + runs-on: [self-hosted, linux, x64, e2e-test] steps: - name: Echo hello world run: echo "hello world" diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml new file mode 100644 index 000000000..8648449ba --- /dev/null +++ b/.github/workflows/start_e2e_test.yaml @@ -0,0 +1,16 @@ +name: Start E2E Test + +on: + pull_request: + +jobs: + deploy-e2e-test-runner: + run-on: ubuntu-latest + steps: + - uses: canonical/setup-lxd + - uses: actions/checkout@v3 + - run: sudo snap install charmcraft --classic + - run: sudo snap install juju --channel=3.1/stable + - run: charmcraft pack + - run: juju bootstrap lxd + - run: juju status \ No newline at end of file diff --git a/src/charm.py b/src/charm.py index 9cc18d0f2..8e40a8155 100755 --- a/src/charm.py +++ b/src/charm.py @@ -135,7 +135,8 @@ def __init__(self, *args, **kargs) -> None: self.proxies["http"] = http_proxy if https_proxy := get_env_var("JUJU_CHARM_HTTPS_PROXY"): self.proxies["https"] = https_proxy - if no_proxy := get_env_var("JUJU_CHARM_NO_PROXY"): + # there's no need for no_proxy if there's no http_proxy or https_proxy + if no_proxy := get_env_var("JUJU_CHARM_NO_PROXY") and (https_proxy or http_proxy): self.proxies["no_proxy"] = no_proxy self.service_token = None diff --git a/src/lxd.py b/src/lxd.py index 4d2aaaa49..0896bda56 100644 --- a/src/lxd.py +++ b/src/lxd.py @@ -47,7 +47,20 @@ def mk_dir(self, dir_name: str) -> None: Args: dir: Name of the directory to create. """ - self.instance.execute(["/usr/bin/mkdir", "-p", dir_name]) + lxc_command = [ + "/snap/bin/lxc", + "exec", + self.instance.name, + "--", + "/usr/bin/mkdir", + "-p", + dir_name + ] + try: + execute_command(lxc_command) + except SubprocessError as err: + logger.exception("Failed to create directory") + raise LxdError(f"Unable to create directory in LXD instance {self.instance.name}") from err def push_file(self, source: str, destination: str, mode: Optional[str] = None) -> None: """Push a file to the LXD instance. diff --git a/src/runner.py b/src/runner.py index 94b2c3ff5..9bc246808 100644 --- a/src/runner.py +++ b/src/runner.py @@ -306,14 +306,14 @@ def _start_instance(self) -> None: # Setting `wait=True` only ensure the instance has begin to boot up. self.instance.start(wait=True) - @retry(tries=5, delay=30, local_logger=logger) + @retry(tries=20, delay=30, local_logger=logger) def _wait_boot_up(self) -> None: if self.instance is None: raise RunnerError("Runner operation called prior to runner creation.") # Wait for the instance to finish to boot up and network to be up. - self.instance.execute(["/usr/bin/who"]) - self.instance.execute(["/usr/bin/nslookup", "github.com"]) + assert self.instance.execute(["/usr/bin/who"])[0] == 0 + assert self.instance.execute(["/usr/bin/nslookup", "github.com"])[0] == 0 logger.info("Finished booting up LXD instance for runner: %s", self.config.name) From 237954b9f3d7024389a6775157e02e0c26354885 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Thu, 15 Jun 2023 19:02:36 +0800 Subject: [PATCH 002/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 8648449ba..9777a7276 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -7,7 +7,7 @@ jobs: deploy-e2e-test-runner: run-on: ubuntu-latest steps: - - uses: canonical/setup-lxd + - uses: canonical/setup-lxd@main - uses: actions/checkout@v3 - run: sudo snap install charmcraft --classic - run: sudo snap install juju --channel=3.1/stable From 7f460f298e40429461e312f79822f42f56688cba Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Thu, 15 Jun 2023 19:03:17 +0800 Subject: [PATCH 003/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 9777a7276..aed5f9aa5 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -5,7 +5,7 @@ on: jobs: deploy-e2e-test-runner: - run-on: ubuntu-latest + runs-on: ubuntu-latest steps: - uses: canonical/setup-lxd@main - uses: actions/checkout@v3 From b1a27f5b5428faff6fafde0183d744f2e5cdd654 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Thu, 15 Jun 2023 19:14:59 +0800 Subject: [PATCH 004/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 32 ++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index aed5f9aa5..69153e52e 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -7,10 +7,30 @@ jobs: deploy-e2e-test-runner: runs-on: ubuntu-latest steps: - - uses: canonical/setup-lxd@main - uses: actions/checkout@v3 - - run: sudo snap install charmcraft --classic - - run: sudo snap install juju --channel=3.1/stable - - run: charmcraft pack - - run: juju bootstrap lxd - - run: juju status \ No newline at end of file + + - name: Setup LXD + uses: canonical/setup-lxd@main + + - name: Install charmcraft + run: sudo snap install charmcraft --classic + + - name: Install juju + run: sudo snap install juju --channel=3.1/stable + + - name: Pack github-runner Charm + run: charmcraft pack + + - name: Bootstrap Juju LXD controller + run: juju bootstrap lxd + + - name: Create Testing Juju Model + run: juju add-model testing + + - run: juju status + + +# - name: Deploy github-runner Charm +# run: | +# juju deploy ./github-runner_ubuntu-22.04-amd64.charm e2e-${{ github.run_id }}-${{ github.run_number }} \ +# --config= From 029b5d93fa1608315a8cba0c4c8516c19b8d31a5 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Thu, 15 Jun 2023 21:37:17 +0800 Subject: [PATCH 005/113] WIP --- .github/workflows/end_to_end_test.yaml | 2 +- .github/workflows/start_e2e_test.yaml | 85 ++++++++++++++++++-------- 2 files changed, 62 insertions(+), 25 deletions(-) diff --git a/.github/workflows/end_to_end_test.yaml b/.github/workflows/end_to_end_test.yaml index a2372956b..f8e21e184 100644 --- a/.github/workflows/end_to_end_test.yaml +++ b/.github/workflows/end_to_end_test.yaml @@ -13,7 +13,7 @@ on: jobs: e2e-test: name: end to end test - runs-on: [self-hosted, linux, x64, e2e-test] + runs-on: [self-hosted, linux, x64, ${{ test-runner }}] steps: - name: Echo hello world run: echo "hello world" diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 69153e52e..28e12de15 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -7,30 +7,67 @@ jobs: deploy-e2e-test-runner: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - - name: Setup LXD - uses: canonical/setup-lxd@main - - - name: Install charmcraft - run: sudo snap install charmcraft --classic - - - name: Install juju - run: sudo snap install juju --channel=3.1/stable - - - name: Pack github-runner Charm - run: charmcraft pack - - - name: Bootstrap Juju LXD controller - run: juju bootstrap lxd - - - name: Create Testing Juju Model - run: juju add-model testing - - - run: juju status - - +# - uses: actions/checkout@v3 +# +# - name: Setup LXD +# uses: canonical/setup-lxd@main +# +# - name: Install charmcraft +# run: sudo snap install charmcraft --classic +# +# - name: Install juju +# run: sudo snap install juju --channel=3.1/stable +# +# - name: Pack github-runner Charm +# run: charmcraft pack +# +# - name: Bootstrap Juju LXD controller +# run: juju bootstrap lxd +# +# - name: Create Testing Juju Model +# run: juju add-model testing +# +# - run: juju status +# +# - name: Setting Testing Model Constraints +# run: juju set-model-constraints "virt-type=virtual-machine mem=16G cores=4" +# +# - name: Change Testing Model Logging Level +# run: juju model-config logging-config="=INFO;unit=DEBUG" +# # - name: Deploy github-runner Charm # run: | # juju deploy ./github-runner_ubuntu-22.04-amd64.charm e2e-${{ github.run_id }}-${{ github.run_number }} \ -# --config= +# --config path=canonical/github-runner-operator \ +# --config token=${{ secrets.E2E_TESTING_TOKEN }} \ +# --config virtual-machines=1 + + - name: Dispatch Workflow on Testing Runner + env: + GH_TOKEN: ${{ secrets.E2E_TESTING_TOKEN }} + run: | + set +x + GH_TOKEN= + MAIN_SHA=$(gh api \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + /repos/${{ secrets.E2E_TESTING_REPO }}/git/ref/heads/main --jq .object.sha) + + gh api \ + --method POST \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + /repos/${{ secrets.E2E_TESTING_REPO }}/git/refs \ + -f ref='refs/heads/e2e-${{ github.run_id }}-${{ github.run_number }}' \ + -f sha=$MAIN_SHA + + gh workflow run test.yaml \ + -R ${{ secrets.E2E_TESTING_REPO }} \ + --ref e2e-${{ github.run_id }}-${{ github.run_number }} \ + -f runner=e2e-${{ github.run_id }}-${{ github.run_number }} + + gh run list \ + --workflow=test.yaml \ + -R ${{ secrets.E2E_TESTING_REPO }} \ + -b e2e-${{ github.run_id }}-${{ github.run_number }} \ + --json workflowDatabaseId,status \ No newline at end of file From df4567c12066293a2a492b65dcd7f89f776639ce Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Thu, 15 Jun 2023 21:38:25 +0800 Subject: [PATCH 006/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 28e12de15..87b0474a0 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -47,7 +47,6 @@ jobs: GH_TOKEN: ${{ secrets.E2E_TESTING_TOKEN }} run: | set +x - GH_TOKEN= MAIN_SHA=$(gh api \ -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ From 958ae5cd1740cc749e0dadb5c03d02e2303b293b Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Thu, 15 Jun 2023 21:50:57 +0800 Subject: [PATCH 007/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 30 +++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 87b0474a0..da8842fce 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -41,7 +41,10 @@ jobs: # --config path=canonical/github-runner-operator \ # --config token=${{ secrets.E2E_TESTING_TOKEN }} \ # --config virtual-machines=1 - + + - name: Install GitHub Cli + run: which gh || sudo apt install gh -y + - name: Dispatch Workflow on Testing Runner env: GH_TOKEN: ${{ secrets.E2E_TESTING_TOKEN }} @@ -69,4 +72,27 @@ jobs: --workflow=test.yaml \ -R ${{ secrets.E2E_TESTING_REPO }} \ -b e2e-${{ github.run_id }}-${{ github.run_number }} \ - --json workflowDatabaseId,status \ No newline at end of file + --json workflowDatabaseId,status + + get_workflow_status() { + output=$(gh run list \ + --workflow=test.yaml \ + -R ${{ secrets.E2E_TESTING_REPO }} \ + -b e2e-${{ github.run_id }}-${{ github.run_number }} \ + --json workflowDatabaseId,status) + + if [ $(echo "$output" | jq 'length') -eq 0 ] + then + echo "not-started" + else + # Parse output with jq to get the status field of the first object + status=$(echo "$output" | jq -r '.[0].status') + echo "$status" + fi + } + + for i in {1..20} + do + get_workflow_status + sleep 1 + done \ No newline at end of file From 8027159aeaf3ee6d36159790ddc3e9c9ea18b319 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Thu, 15 Jun 2023 21:58:58 +0800 Subject: [PATCH 008/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index da8842fce..16137425c 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -74,7 +74,7 @@ jobs: -b e2e-${{ github.run_id }}-${{ github.run_number }} \ --json workflowDatabaseId,status - get_workflow_status() { + get-workflow-status() { output=$(gh run list \ --workflow=test.yaml \ -R ${{ secrets.E2E_TESTING_REPO }} \ @@ -91,8 +91,8 @@ jobs: fi } - for i in {1..20} + for i in {1..3600} do - get_workflow_status + echo workflow status: get-workflow-status sleep 1 done \ No newline at end of file From 7bf4dd737b881867a1b9ec062c059d7893a76b68 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Thu, 15 Jun 2023 22:00:25 +0800 Subject: [PATCH 009/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 16137425c..54722b2ef 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -93,6 +93,6 @@ jobs: for i in {1..3600} do - echo workflow status: get-workflow-status + echo workflow status: $(get-workflow-status) sleep 1 done \ No newline at end of file From 048ea96f46abfb5ea3fb171b88dbf3e1244d2f7e Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Thu, 15 Jun 2023 22:03:26 +0800 Subject: [PATCH 010/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 54722b2ef..4fdfc8df9 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -37,7 +37,8 @@ jobs: # # - name: Deploy github-runner Charm # run: | -# juju deploy ./github-runner_ubuntu-22.04-amd64.charm e2e-${{ github.run_id }}-${{ github.run_number }} \ +# juju deploy ./github-runner_ubuntu-22.04-amd64.charm \ +# e2e-${{ github.run_id }}-${{ github.run_number }}-runner \ # --config path=canonical/github-runner-operator \ # --config token=${{ secrets.E2E_TESTING_TOKEN }} \ # --config virtual-machines=1 @@ -60,25 +61,25 @@ jobs: -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ /repos/${{ secrets.E2E_TESTING_REPO }}/git/refs \ - -f ref='refs/heads/e2e-${{ github.run_id }}-${{ github.run_number }}' \ + -f ref='refs/heads/e2e-${{ github.run_id }}-${{ github.run_number }}-runner' \ -f sha=$MAIN_SHA gh workflow run test.yaml \ -R ${{ secrets.E2E_TESTING_REPO }} \ - --ref e2e-${{ github.run_id }}-${{ github.run_number }} \ - -f runner=e2e-${{ github.run_id }}-${{ github.run_number }} + --ref e2e-${{ github.run_id }}-${{ github.run_number }}-runner \ + -f runner=e2e-${{ github.run_id }}-${{ github.run_number }}-runner gh run list \ --workflow=test.yaml \ -R ${{ secrets.E2E_TESTING_REPO }} \ - -b e2e-${{ github.run_id }}-${{ github.run_number }} \ + -b e2e-${{ github.run_id }}-${{ github.run_number }}-runner \ --json workflowDatabaseId,status get-workflow-status() { output=$(gh run list \ --workflow=test.yaml \ -R ${{ secrets.E2E_TESTING_REPO }} \ - -b e2e-${{ github.run_id }}-${{ github.run_number }} \ + -b e2e-${{ github.run_id }}-${{ github.run_number }}-runner \ --json workflowDatabaseId,status) if [ $(echo "$output" | jq 'length') -eq 0 ] From 34d7350e7d994d9a55ac70173cc4d519ce1ce933 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Thu, 15 Jun 2023 22:06:45 +0800 Subject: [PATCH 011/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 4fdfc8df9..3fcad0e6c 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -38,7 +38,7 @@ jobs: # - name: Deploy github-runner Charm # run: | # juju deploy ./github-runner_ubuntu-22.04-amd64.charm \ -# e2e-${{ github.run_id }}-${{ github.run_number }}-runner \ +# e2e-i${{ github.run_id }}-n${{ github.run_number }}-runner \ # --config path=canonical/github-runner-operator \ # --config token=${{ secrets.E2E_TESTING_TOKEN }} \ # --config virtual-machines=1 @@ -61,25 +61,25 @@ jobs: -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ /repos/${{ secrets.E2E_TESTING_REPO }}/git/refs \ - -f ref='refs/heads/e2e-${{ github.run_id }}-${{ github.run_number }}-runner' \ + -f ref='refs/heads/e2e-i${{ github.run_id }}-n${{ github.run_number }}-runner' \ -f sha=$MAIN_SHA gh workflow run test.yaml \ -R ${{ secrets.E2E_TESTING_REPO }} \ - --ref e2e-${{ github.run_id }}-${{ github.run_number }}-runner \ - -f runner=e2e-${{ github.run_id }}-${{ github.run_number }}-runner + --ref e2e-i${{ github.run_id }}-n${{ github.run_number }}-runner \ + -f runner=e2e-i${{ github.run_id }}-n${{ github.run_number }}-runner gh run list \ --workflow=test.yaml \ -R ${{ secrets.E2E_TESTING_REPO }} \ - -b e2e-${{ github.run_id }}-${{ github.run_number }}-runner \ + -b e2e-i${{ github.run_id }}-n${{ github.run_number }}-runner \ --json workflowDatabaseId,status get-workflow-status() { output=$(gh run list \ --workflow=test.yaml \ -R ${{ secrets.E2E_TESTING_REPO }} \ - -b e2e-${{ github.run_id }}-${{ github.run_number }}-runner \ + -b e2e-i${{ github.run_id }}-n${{ github.run_number }}-runner \ --json workflowDatabaseId,status) if [ $(echo "$output" | jq 'length') -eq 0 ] From 3f1b9299beb12e5da1de451ab854ceef128ece9f Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Thu, 15 Jun 2023 22:50:29 +0800 Subject: [PATCH 012/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 3fcad0e6c..64041b871 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -38,7 +38,7 @@ jobs: # - name: Deploy github-runner Charm # run: | # juju deploy ./github-runner_ubuntu-22.04-amd64.charm \ -# e2e-i${{ github.run_id }}-n${{ github.run_number }}-runner \ +# e2e-i${{ github.run_id }}n${{ github.run_number }}r \ # --config path=canonical/github-runner-operator \ # --config token=${{ secrets.E2E_TESTING_TOKEN }} \ # --config virtual-machines=1 @@ -61,25 +61,25 @@ jobs: -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ /repos/${{ secrets.E2E_TESTING_REPO }}/git/refs \ - -f ref='refs/heads/e2e-i${{ github.run_id }}-n${{ github.run_number }}-runner' \ + -f ref='refs/heads/e2e-i${{ github.run_id }}n${{ github.run_number }}r' \ -f sha=$MAIN_SHA gh workflow run test.yaml \ -R ${{ secrets.E2E_TESTING_REPO }} \ - --ref e2e-i${{ github.run_id }}-n${{ github.run_number }}-runner \ - -f runner=e2e-i${{ github.run_id }}-n${{ github.run_number }}-runner + --ref e2e-i${{ github.run_id }}n${{ github.run_number }}r \ + -f runner=e2e-i${{ github.run_id }}n${{ github.run_number }}r gh run list \ --workflow=test.yaml \ -R ${{ secrets.E2E_TESTING_REPO }} \ - -b e2e-i${{ github.run_id }}-n${{ github.run_number }}-runner \ + -b e2e-i${{ github.run_id }}n${{ github.run_number }}r \ --json workflowDatabaseId,status get-workflow-status() { output=$(gh run list \ --workflow=test.yaml \ -R ${{ secrets.E2E_TESTING_REPO }} \ - -b e2e-i${{ github.run_id }}-n${{ github.run_number }}-runner \ + -b e2e-i${{ github.run_id }}n${{ github.run_number }}r \ --json workflowDatabaseId,status) if [ $(echo "$output" | jq 'length') -eq 0 ] @@ -96,4 +96,6 @@ jobs: do echo workflow status: $(get-workflow-status) sleep 1 - done \ No newline at end of file + done +#juju debug-log & +#for i in {1..30};do echo $i && sleep 1;done; kill $(jobs -p) & \ No newline at end of file From 5acbbc8d58a9641ebc3e2518c5565b98eb628d5e Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Thu, 15 Jun 2023 23:43:18 +0800 Subject: [PATCH 013/113] Enable --- .github/workflows/start_e2e_test.yaml | 81 +++++++++++++-------------- src/runner_manager.py | 20 +++---- 2 files changed, 50 insertions(+), 51 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 64041b871..3f84e861e 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -7,41 +7,41 @@ jobs: deploy-e2e-test-runner: runs-on: ubuntu-latest steps: -# - uses: actions/checkout@v3 -# -# - name: Setup LXD -# uses: canonical/setup-lxd@main -# -# - name: Install charmcraft -# run: sudo snap install charmcraft --classic -# -# - name: Install juju -# run: sudo snap install juju --channel=3.1/stable -# -# - name: Pack github-runner Charm -# run: charmcraft pack -# -# - name: Bootstrap Juju LXD controller -# run: juju bootstrap lxd -# -# - name: Create Testing Juju Model -# run: juju add-model testing -# -# - run: juju status -# -# - name: Setting Testing Model Constraints -# run: juju set-model-constraints "virt-type=virtual-machine mem=16G cores=4" -# -# - name: Change Testing Model Logging Level -# run: juju model-config logging-config="=INFO;unit=DEBUG" -# -# - name: Deploy github-runner Charm -# run: | -# juju deploy ./github-runner_ubuntu-22.04-amd64.charm \ -# e2e-i${{ github.run_id }}n${{ github.run_number }}r \ -# --config path=canonical/github-runner-operator \ -# --config token=${{ secrets.E2E_TESTING_TOKEN }} \ -# --config virtual-machines=1 + - uses: actions/checkout@v3 + + - name: Setup LXD + uses: canonical/setup-lxd@main + + - name: Install charmcraft + run: sudo snap install charmcraft --classic + + - name: Install juju + run: sudo snap install juju --channel=3.1/stable + + - name: Pack github-runner Charm + run: charmcraft pack + + - name: Bootstrap Juju LXD controller + run: juju bootstrap lxd + + - name: Create Testing Juju Model + run: juju add-model testing + + - run: juju status + + - name: Setting Testing Model Constraints + run: juju set-model-constraints "virt-type=virtual-machine mem=16G cores=4" + + - name: Change Testing Model Logging Level + run: juju model-config logging-config="=INFO;unit=DEBUG" + + - name: Deploy github-runner Charm + run: | + juju deploy ./github-runner_ubuntu-22.04-amd64.charm \ + e2e-i${{ github.run_id }}n${{ github.run_number }}r \ + --config path=canonical/github-runner-operator \ + --config token=${{ secrets.E2E_TESTING_TOKEN }} \ + --config virtual-machines=1 - name: Install GitHub Cli run: which gh || sudo apt install gh -y @@ -50,7 +50,6 @@ jobs: env: GH_TOKEN: ${{ secrets.E2E_TESTING_TOKEN }} run: | - set +x MAIN_SHA=$(gh api \ -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ @@ -92,10 +91,10 @@ jobs: fi } - for i in {1..3600} + juju debug-log & + + for i in {1..1200} do echo workflow status: $(get-workflow-status) - sleep 1 - done -#juju debug-log & -#for i in {1..30};do echo $i && sleep 1;done; kill $(jobs -p) & \ No newline at end of file + sleep 3 + done; kill $(jobs -p) & diff --git a/src/runner_manager.py b/src/runner_manager.py index eebe7dddc..01b2f37ce 100644 --- a/src/runner_manager.py +++ b/src/runner_manager.py @@ -74,11 +74,11 @@ class RunnerManager: runner_bin_path = Path("/opt/github-runner-app") def __init__( - self, - app_name: str, - unit: int, - runner_manager_config: RunnerManagerConfig, - proxies: ProxySetting = ProxySetting(), + self, + app_name: str, + unit: int, + runner_manager_config: RunnerManagerConfig, + proxies: ProxySetting = ProxySetting(), ) -> None: """Construct RunnerManager object for creating and managing runners. @@ -135,7 +135,7 @@ def __init__( @retry(tries=5, delay=30, local_logger=logger) def get_latest_runner_bin_url( - self, os_name: str = "linux", arch_name: str = "x64" + self, os_name: str = "linux", arch_name: str = "x64" ) -> RunnerApplication: """Get the URL for the latest runner binary. @@ -204,7 +204,7 @@ def update_runner_bin(self, binary: RunnerApplication) -> None: sha256 = hashlib.sha256() with RunnerManager.runner_bin_path.open(mode="wb") as file: - for chunk in response.iter_content(decode_unicode=False): + for chunk in response.iter_content(chunk_size=128 * 1024, decode_unicode=False): file.write(chunk) sha256.update(chunk) @@ -406,9 +406,9 @@ def _get_runners(self) -> list[Runner]: """ def create_runner_info( - name: str, - local_runner: Optional[LxdInstance], - remote_runner: Optional[SelfHostedRunner], + name: str, + local_runner: Optional[LxdInstance], + remote_runner: Optional[SelfHostedRunner], ) -> Runner: """Create runner from information from GitHub and LXD.""" logger.debug( From 408476ce8965422e07feff94406be4e928b228f3 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Thu, 15 Jun 2023 23:45:13 +0800 Subject: [PATCH 014/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 3f84e861e..aa3c72123 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -5,7 +5,7 @@ on: jobs: deploy-e2e-test-runner: - runs-on: ubuntu-latest + runs-on: [self-hosted, linux, x64, e2e-test] steps: - uses: actions/checkout@v3 From 4afe47944ea52c681b56da73d15c820c28968719 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 00:04:12 +0800 Subject: [PATCH 015/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index aa3c72123..873c8d3f7 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -19,7 +19,7 @@ jobs: run: sudo snap install juju --channel=3.1/stable - name: Pack github-runner Charm - run: charmcraft pack + run: charmcraft pack || ( cat /home/ubuntu/.local/state/charmcraft/log/* 1 && exit 1 ) - name: Bootstrap Juju LXD controller run: juju bootstrap lxd @@ -27,8 +27,6 @@ jobs: - name: Create Testing Juju Model run: juju add-model testing - - run: juju status - - name: Setting Testing Model Constraints run: juju set-model-constraints "virt-type=virtual-machine mem=16G cores=4" From 5a55888544f86c87fa5a3a286894620687d71cda Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 00:20:58 +0800 Subject: [PATCH 016/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 186 +++++++++++++++----------- 1 file changed, 108 insertions(+), 78 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 873c8d3f7..27bbbbdb7 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -4,8 +4,8 @@ on: pull_request: jobs: - deploy-e2e-test-runner: - runs-on: [self-hosted, linux, x64, e2e-test] + build-charm: + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -15,84 +15,114 @@ jobs: - name: Install charmcraft run: sudo snap install charmcraft --classic - - name: Install juju - run: sudo snap install juju --channel=3.1/stable - - name: Pack github-runner Charm run: charmcraft pack || ( cat /home/ubuntu/.local/state/charmcraft/log/* 1 && exit 1 ) - - name: Bootstrap Juju LXD controller - run: juju bootstrap lxd - - - name: Create Testing Juju Model - run: juju add-model testing - - - name: Setting Testing Model Constraints - run: juju set-model-constraints "virt-type=virtual-machine mem=16G cores=4" - - - name: Change Testing Model Logging Level - run: juju model-config logging-config="=INFO;unit=DEBUG" + - name: Upload github-runner Charm + uses: actions/upload-artifact@v3 + with: + name: github-runner.charm + path: github-runner_ubuntu-22.04-amd64.charm - - name: Deploy github-runner Charm - run: | - juju deploy ./github-runner_ubuntu-22.04-amd64.charm \ - e2e-i${{ github.run_id }}n${{ github.run_number }}r \ - --config path=canonical/github-runner-operator \ - --config token=${{ secrets.E2E_TESTING_TOKEN }} \ - --config virtual-machines=1 - - - name: Install GitHub Cli - run: which gh || sudo apt install gh -y - - - name: Dispatch Workflow on Testing Runner - env: - GH_TOKEN: ${{ secrets.E2E_TESTING_TOKEN }} - run: | - MAIN_SHA=$(gh api \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - /repos/${{ secrets.E2E_TESTING_REPO }}/git/ref/heads/main --jq .object.sha) - - gh api \ - --method POST \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - /repos/${{ secrets.E2E_TESTING_REPO }}/git/refs \ - -f ref='refs/heads/e2e-i${{ github.run_id }}n${{ github.run_number }}r' \ - -f sha=$MAIN_SHA - - gh workflow run test.yaml \ - -R ${{ secrets.E2E_TESTING_REPO }} \ - --ref e2e-i${{ github.run_id }}n${{ github.run_number }}r \ - -f runner=e2e-i${{ github.run_id }}n${{ github.run_number }}r - - gh run list \ - --workflow=test.yaml \ - -R ${{ secrets.E2E_TESTING_REPO }} \ - -b e2e-i${{ github.run_id }}n${{ github.run_number }}r \ - --json workflowDatabaseId,status - - get-workflow-status() { - output=$(gh run list \ - --workflow=test.yaml \ - -R ${{ secrets.E2E_TESTING_REPO }} \ - -b e2e-i${{ github.run_id }}n${{ github.run_number }}r \ - --json workflowDatabaseId,status) - - if [ $(echo "$output" | jq 'length') -eq 0 ] - then - echo "not-started" - else - # Parse output with jq to get the status field of the first object - status=$(echo "$output" | jq -r '.[0].status') - echo "$status" - fi - } - - juju debug-log & + download-charm: + runs-on: ubuntu-latest + needs: build-charm + steps: + - name: Download github-runner Charm + uses: actions/download-artifact@v3 + with: + name: github-runner.charm + - run: ls -lah - for i in {1..1200} - do - echo workflow status: $(get-workflow-status) - sleep 3 - done; kill $(jobs -p) & +# deploy-e2e-test-runner: +# runs-on: [self-hosted, linux, x64, e2e-test] +# steps: +# - uses: actions/checkout@v3 +# +# - name: Setup LXD +# uses: canonical/setup-lxd@main +# +# - name: Install charmcraft +# run: sudo snap install charmcraft --classic +# +# - name: Install juju +# run: sudo snap install juju --channel=3.1/stable +# +# - name: Pack github-runner Charm +# run: charmcraft pack || ( cat /home/ubuntu/.local/state/charmcraft/log/* 1 && exit 1 ) +# +# - name: Bootstrap Juju LXD controller +# run: juju bootstrap lxd +# +# - name: Create Testing Juju Model +# run: juju add-model testing +# +# - name: Setting Testing Model Constraints +# run: juju set-model-constraints "virt-type=virtual-machine mem=16G cores=4" +# +# - name: Change Testing Model Logging Level +# run: juju model-config logging-config="=INFO;unit=DEBUG" +# +# - name: Deploy github-runner Charm +# run: | +# juju deploy ./github-runner_ubuntu-22.04-amd64.charm \ +# e2e-i${{ github.run_id }}n${{ github.run_number }}r \ +# --config path=canonical/github-runner-operator \ +# --config token=${{ secrets.E2E_TESTING_TOKEN }} \ +# --config virtual-machines=1 +# +# - name: Install GitHub Cli +# run: which gh || sudo apt install gh -y +# +# - name: Dispatch Workflow on Testing Runner +# env: +# GH_TOKEN: ${{ secrets.E2E_TESTING_TOKEN }} +# run: | +# MAIN_SHA=$(gh api \ +# -H "Accept: application/vnd.github+json" \ +# -H "X-GitHub-Api-Version: 2022-11-28" \ +# /repos/${{ secrets.E2E_TESTING_REPO }}/git/ref/heads/main --jq .object.sha) +# +# gh api \ +# --method POST \ +# -H "Accept: application/vnd.github+json" \ +# -H "X-GitHub-Api-Version: 2022-11-28" \ +# /repos/${{ secrets.E2E_TESTING_REPO }}/git/refs \ +# -f ref='refs/heads/e2e-i${{ github.run_id }}n${{ github.run_number }}r' \ +# -f sha=$MAIN_SHA +# +# gh workflow run test.yaml \ +# -R ${{ secrets.E2E_TESTING_REPO }} \ +# --ref e2e-i${{ github.run_id }}n${{ github.run_number }}r \ +# -f runner=e2e-i${{ github.run_id }}n${{ github.run_number }}r +# +# gh run list \ +# --workflow=test.yaml \ +# -R ${{ secrets.E2E_TESTING_REPO }} \ +# -b e2e-i${{ github.run_id }}n${{ github.run_number }}r \ +# --json workflowDatabaseId,status +# +# get-workflow-status() { +# output=$(gh run list \ +# --workflow=test.yaml \ +# -R ${{ secrets.E2E_TESTING_REPO }} \ +# -b e2e-i${{ github.run_id }}n${{ github.run_number }}r \ +# --json workflowDatabaseId,status) +# +# if [ $(echo "$output" | jq 'length') -eq 0 ] +# then +# echo "not-started" +# else +# # Parse output with jq to get the status field of the first object +# status=$(echo "$output" | jq -r '.[0].status') +# echo "$status" +# fi +# } +# +# juju debug-log & +# +# for i in {1..1200} +# do +# echo workflow status: $(get-workflow-status) +# sleep 3 +# done; kill $(jobs -p) & From c54a48e484117f1af4055f6c7d2c99946cb49116 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 00:43:19 +0800 Subject: [PATCH 017/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 27bbbbdb7..268482eb7 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -15,13 +15,22 @@ jobs: - name: Install charmcraft run: sudo snap install charmcraft --classic + - name: Cache github-runner Charm + uses: actions/cache@v3 + id: cache-charm + with: + path: github-runner_ubuntu-22.04-amd64.charm + key: github-runner-charm-${{ hashFiles('**/*') }} + - name: Pack github-runner Charm + if: steps.cache-charm.outputs.cache-hit != 'true' run: charmcraft pack || ( cat /home/ubuntu/.local/state/charmcraft/log/* 1 && exit 1 ) + - name: Upload github-runner Charm uses: actions/upload-artifact@v3 with: - name: github-runner.charm + name: github-runner_ubuntu-22.04-amd64.charm path: github-runner_ubuntu-22.04-amd64.charm download-charm: From 31f4f8ad1679261c7a9c77de4e95033b6e9b6b55 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 00:56:24 +0800 Subject: [PATCH 018/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 268482eb7..ccd76f8bf 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -26,7 +26,6 @@ jobs: if: steps.cache-charm.outputs.cache-hit != 'true' run: charmcraft pack || ( cat /home/ubuntu/.local/state/charmcraft/log/* 1 && exit 1 ) - - name: Upload github-runner Charm uses: actions/upload-artifact@v3 with: @@ -40,7 +39,7 @@ jobs: - name: Download github-runner Charm uses: actions/download-artifact@v3 with: - name: github-runner.charm + name: github-runner_ubuntu-22.04-amd64.charm - run: ls -lah # deploy-e2e-test-runner: From 3c92c84241ff07c48d3fa485bcb80d6afddf097e Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 00:59:49 +0800 Subject: [PATCH 019/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 181 ++++++++++++-------------- 1 file changed, 84 insertions(+), 97 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index ccd76f8bf..d48502efa 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -32,105 +32,92 @@ jobs: name: github-runner_ubuntu-22.04-amd64.charm path: github-runner_ubuntu-22.04-amd64.charm - download-charm: - runs-on: ubuntu-latest - needs: build-charm + deploy-e2e-test-runner: + runs-on: [self-hosted, linux, x64, e2e-test] steps: - name: Download github-runner Charm uses: actions/download-artifact@v3 with: name: github-runner_ubuntu-22.04-amd64.charm - - run: ls -lah - -# deploy-e2e-test-runner: -# runs-on: [self-hosted, linux, x64, e2e-test] -# steps: -# - uses: actions/checkout@v3 -# -# - name: Setup LXD -# uses: canonical/setup-lxd@main -# -# - name: Install charmcraft -# run: sudo snap install charmcraft --classic -# -# - name: Install juju -# run: sudo snap install juju --channel=3.1/stable -# -# - name: Pack github-runner Charm -# run: charmcraft pack || ( cat /home/ubuntu/.local/state/charmcraft/log/* 1 && exit 1 ) -# -# - name: Bootstrap Juju LXD controller -# run: juju bootstrap lxd -# -# - name: Create Testing Juju Model -# run: juju add-model testing -# -# - name: Setting Testing Model Constraints -# run: juju set-model-constraints "virt-type=virtual-machine mem=16G cores=4" -# -# - name: Change Testing Model Logging Level -# run: juju model-config logging-config="=INFO;unit=DEBUG" -# -# - name: Deploy github-runner Charm -# run: | -# juju deploy ./github-runner_ubuntu-22.04-amd64.charm \ -# e2e-i${{ github.run_id }}n${{ github.run_number }}r \ -# --config path=canonical/github-runner-operator \ -# --config token=${{ secrets.E2E_TESTING_TOKEN }} \ -# --config virtual-machines=1 -# -# - name: Install GitHub Cli -# run: which gh || sudo apt install gh -y -# -# - name: Dispatch Workflow on Testing Runner -# env: -# GH_TOKEN: ${{ secrets.E2E_TESTING_TOKEN }} -# run: | -# MAIN_SHA=$(gh api \ -# -H "Accept: application/vnd.github+json" \ -# -H "X-GitHub-Api-Version: 2022-11-28" \ -# /repos/${{ secrets.E2E_TESTING_REPO }}/git/ref/heads/main --jq .object.sha) -# -# gh api \ -# --method POST \ -# -H "Accept: application/vnd.github+json" \ -# -H "X-GitHub-Api-Version: 2022-11-28" \ -# /repos/${{ secrets.E2E_TESTING_REPO }}/git/refs \ -# -f ref='refs/heads/e2e-i${{ github.run_id }}n${{ github.run_number }}r' \ -# -f sha=$MAIN_SHA -# -# gh workflow run test.yaml \ -# -R ${{ secrets.E2E_TESTING_REPO }} \ -# --ref e2e-i${{ github.run_id }}n${{ github.run_number }}r \ -# -f runner=e2e-i${{ github.run_id }}n${{ github.run_number }}r -# -# gh run list \ -# --workflow=test.yaml \ -# -R ${{ secrets.E2E_TESTING_REPO }} \ -# -b e2e-i${{ github.run_id }}n${{ github.run_number }}r \ -# --json workflowDatabaseId,status -# -# get-workflow-status() { -# output=$(gh run list \ -# --workflow=test.yaml \ -# -R ${{ secrets.E2E_TESTING_REPO }} \ -# -b e2e-i${{ github.run_id }}n${{ github.run_number }}r \ -# --json workflowDatabaseId,status) -# -# if [ $(echo "$output" | jq 'length') -eq 0 ] -# then -# echo "not-started" -# else -# # Parse output with jq to get the status field of the first object -# status=$(echo "$output" | jq -r '.[0].status') -# echo "$status" -# fi -# } -# -# juju debug-log & -# -# for i in {1..1200} -# do -# echo workflow status: $(get-workflow-status) -# sleep 3 -# done; kill $(jobs -p) & + + - name: Install juju + run: sudo snap install juju --channel=3.1/stable + + - name: Pack github-runner Charm + run: charmcraft pack || ( cat /home/ubuntu/.local/state/charmcraft/log/* 1 && exit 1 ) + + - name: Bootstrap Juju LXD controller + run: juju bootstrap lxd + + - name: Create Testing Juju Model + run: juju add-model testing + + - name: Setting Testing Model Constraints + run: juju set-model-constraints "virt-type=virtual-machine mem=16G cores=4" + + - name: Change Testing Model Logging Level + run: juju model-config logging-config="=INFO;unit=DEBUG" + + - name: Deploy github-runner Charm + run: | + juju deploy ./github-runner_ubuntu-22.04-amd64.charm \ + e2e-i${{ github.run_id }}n${{ github.run_number }}r \ + --config path=canonical/github-runner-operator \ + --config token=${{ secrets.E2E_TESTING_TOKEN }} \ + --config virtual-machines=1 + + - name: Install GitHub Cli + run: which gh || sudo apt install gh -y + + - name: Dispatch Workflow on Testing Runner + env: + GH_TOKEN: ${{ secrets.E2E_TESTING_TOKEN }} + run: | + MAIN_SHA=$(gh api \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + /repos/${{ secrets.E2E_TESTING_REPO }}/git/ref/heads/main --jq .object.sha) + + gh api \ + --method POST \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + /repos/${{ secrets.E2E_TESTING_REPO }}/git/refs \ + -f ref='refs/heads/e2e-i${{ github.run_id }}n${{ github.run_number }}r' \ + -f sha=$MAIN_SHA + + gh workflow run test.yaml \ + -R ${{ secrets.E2E_TESTING_REPO }} \ + --ref e2e-i${{ github.run_id }}n${{ github.run_number }}r \ + -f runner=e2e-i${{ github.run_id }}n${{ github.run_number }}r + + gh run list \ + --workflow=test.yaml \ + -R ${{ secrets.E2E_TESTING_REPO }} \ + -b e2e-i${{ github.run_id }}n${{ github.run_number }}r \ + --json workflowDatabaseId,status + + get-workflow-status() { + output=$(gh run list \ + --workflow=test.yaml \ + -R ${{ secrets.E2E_TESTING_REPO }} \ + -b e2e-i${{ github.run_id }}n${{ github.run_number }}r \ + --json workflowDatabaseId,status) + + if [ $(echo "$output" | jq 'length') -eq 0 ] + then + echo "not-started" + else + # Parse output with jq to get the status field of the first object + status=$(echo "$output" | jq -r '.[0].status') + echo "$status" + fi + } + + juju debug-log & + + for i in {1..1200} + do + echo workflow status: $(get-workflow-status) + sleep 3 + done; kill $(jobs -p) & From a493293280b9579aaf2606a75ba183bd03ed6c3e Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 01:05:35 +0800 Subject: [PATCH 020/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index d48502efa..7b809db2f 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -15,6 +15,11 @@ jobs: - name: Install charmcraft run: sudo snap install charmcraft --classic + - name: Remove Unnecessary Components + run: | + rm -rf .git + rm -rf .github + - name: Cache github-runner Charm uses: actions/cache@v3 id: cache-charm @@ -34,6 +39,7 @@ jobs: deploy-e2e-test-runner: runs-on: [self-hosted, linux, x64, e2e-test] + needs: build-charm steps: - name: Download github-runner Charm uses: actions/download-artifact@v3 From 404fc825ddd4b3a84f11ed1407fe116acb6c1a0a Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 01:20:07 +0800 Subject: [PATCH 021/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 7b809db2f..b8c94c892 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -49,9 +49,6 @@ jobs: - name: Install juju run: sudo snap install juju --channel=3.1/stable - - name: Pack github-runner Charm - run: charmcraft pack || ( cat /home/ubuntu/.local/state/charmcraft/log/* 1 && exit 1 ) - - name: Bootstrap Juju LXD controller run: juju bootstrap lxd From 8842e0c9c1df882ec2d05810fdcec304c15b3cd4 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 01:22:20 +0800 Subject: [PATCH 022/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index b8c94c892..ff9d26210 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -9,12 +9,6 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Setup LXD - uses: canonical/setup-lxd@main - - - name: Install charmcraft - run: sudo snap install charmcraft --classic - - name: Remove Unnecessary Components run: | rm -rf .git @@ -27,6 +21,10 @@ jobs: path: github-runner_ubuntu-22.04-amd64.charm key: github-runner-charm-${{ hashFiles('**/*') }} + - name: Install charmcraft + if: steps.cache-charm.outputs.cache-hit != 'true' + run: sudo snap install charmcraft --classic + - name: Pack github-runner Charm if: steps.cache-charm.outputs.cache-hit != 'true' run: charmcraft pack || ( cat /home/ubuntu/.local/state/charmcraft/log/* 1 && exit 1 ) @@ -38,7 +36,7 @@ jobs: path: github-runner_ubuntu-22.04-amd64.charm deploy-e2e-test-runner: - runs-on: [self-hosted, linux, x64, e2e-test] + runs-on: [ self-hosted, linux, x64, e2e-test ] needs: build-charm steps: - name: Download github-runner Charm @@ -46,6 +44,9 @@ jobs: with: name: github-runner_ubuntu-22.04-amd64.charm + - name: Setup LXD + uses: canonical/setup-lxd@main + - name: Install juju run: sudo snap install juju --channel=3.1/stable From 511e97ee0378a553055bea6eb1413b5d12d0f30f Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 01:30:29 +0800 Subject: [PATCH 023/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index ff9d26210..b46b11285 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -44,14 +44,11 @@ jobs: with: name: github-runner_ubuntu-22.04-amd64.charm - - name: Setup LXD - uses: canonical/setup-lxd@main - - - name: Install juju - run: sudo snap install juju --channel=3.1/stable - - - name: Bootstrap Juju LXD controller - run: juju bootstrap lxd + - name: Setup Lxd Controller + uses: charmed-kubernetes/actions-operator@main + with: + juju-channel: 3.1/stable + provider: lxd - name: Create Testing Juju Model run: juju add-model testing From 868e7335e503fb542985d28d515ec3a27f2944b6 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 01:39:08 +0800 Subject: [PATCH 024/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index b46b11285..1216dc6d9 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -39,11 +39,6 @@ jobs: runs-on: [ self-hosted, linux, x64, e2e-test ] needs: build-charm steps: - - name: Download github-runner Charm - uses: actions/download-artifact@v3 - with: - name: github-runner_ubuntu-22.04-amd64.charm - - name: Setup Lxd Controller uses: charmed-kubernetes/actions-operator@main with: @@ -59,6 +54,13 @@ jobs: - name: Change Testing Model Logging Level run: juju model-config logging-config="=INFO;unit=DEBUG" + - name: Download github-runner Charm + uses: actions/download-artifact@v3 + with: + name: github-runner_ubuntu-22.04-amd64.charm + + - run: ls -lah + - name: Deploy github-runner Charm run: | juju deploy ./github-runner_ubuntu-22.04-amd64.charm \ From 36cb5ab50daf7d499a6379b68c6ba659b663aa67 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 01:49:16 +0800 Subject: [PATCH 025/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 1216dc6d9..c47e92331 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -63,8 +63,9 @@ jobs: - name: Deploy github-runner Charm run: | - juju deploy ./github-runner_ubuntu-22.04-amd64.charm \ + juju deploy ${{ github.workspace }}/github-runner_ubuntu-22.04-amd64.charm \ e2e-i${{ github.run_id }}n${{ github.run_number }}r \ + ---base ubuntu@22.04 \ --config path=canonical/github-runner-operator \ --config token=${{ secrets.E2E_TESTING_TOKEN }} \ --config virtual-machines=1 From 869c8930e4042f02b6c9c2a9cff45a8aa338f6d4 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 01:54:04 +0800 Subject: [PATCH 026/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index c47e92331..303268777 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -63,9 +63,10 @@ jobs: - name: Deploy github-runner Charm run: | + ls -lah ${{ github.workspace }}/github-runner_ubuntu-22.04-amd64.charm juju deploy ${{ github.workspace }}/github-runner_ubuntu-22.04-amd64.charm \ e2e-i${{ github.run_id }}n${{ github.run_number }}r \ - ---base ubuntu@22.04 \ + --base ubuntu@22.04 \ --config path=canonical/github-runner-operator \ --config token=${{ secrets.E2E_TESTING_TOKEN }} \ --config virtual-machines=1 From 6d0c11d78b372b4ae510d4b9618d1e9c9fbef49a Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 02:03:23 +0800 Subject: [PATCH 027/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 303268777..860f1eefb 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -63,8 +63,9 @@ jobs: - name: Deploy github-runner Charm run: | - ls -lah ${{ github.workspace }}/github-runner_ubuntu-22.04-amd64.charm - juju deploy ${{ github.workspace }}/github-runner_ubuntu-22.04-amd64.charm \ + cp github-runner_ubuntu-22.04-amd64.charm /var/snap/juju/common/github-runner_ubuntu-22.04-amd64.charm + chmod 777 /var/snap/juju/common/github-runner_ubuntu-22.04-amd64.charm + juju deploy /var/snap/juju/common/github-runner_ubuntu-22.04-amd64.charm \ e2e-i${{ github.run_id }}n${{ github.run_number }}r \ --base ubuntu@22.04 \ --config path=canonical/github-runner-operator \ From a0b00b99b7bc9f341dad04bf216277c5866e6b8d Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 02:11:39 +0800 Subject: [PATCH 028/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 860f1eefb..e111ec1c2 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -63,9 +63,8 @@ jobs: - name: Deploy github-runner Charm run: | - cp github-runner_ubuntu-22.04-amd64.charm /var/snap/juju/common/github-runner_ubuntu-22.04-amd64.charm - chmod 777 /var/snap/juju/common/github-runner_ubuntu-22.04-amd64.charm - juju deploy /var/snap/juju/common/github-runner_ubuntu-22.04-amd64.charm \ + cp github-runner_ubuntu-22.04-amd64.charm /home/ubuntu/github-runner_ubuntu-22.04-amd64.charm + juju deploy /home/ubuntu/github-runner_ubuntu-22.04-amd64.charm \ e2e-i${{ github.run_id }}n${{ github.run_number }}r \ --base ubuntu@22.04 \ --config path=canonical/github-runner-operator \ From 5575da9017e132a72184e05d5b2069fa694c5d6d Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 02:36:42 +0800 Subject: [PATCH 029/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index e111ec1c2..68c486464 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -95,19 +95,21 @@ jobs: -R ${{ secrets.E2E_TESTING_REPO }} \ --ref e2e-i${{ github.run_id }}n${{ github.run_number }}r \ -f runner=e2e-i${{ github.run_id }}n${{ github.run_number }}r - - gh run list \ - --workflow=test.yaml \ + + sleep 5 + + gh run list -R ${{ secrets.E2E_TESTING_REPO }} \ - -b e2e-i${{ github.run_id }}n${{ github.run_number }}r \ - --json workflowDatabaseId,status + -L 100 \ + --json headBranch,status,workflowDatabaseId \ + | jq '.[] | select(.headBranch=="e2e-i${{ github.run_id }}n${{ github.run_number }}r")' get-workflow-status() { - output=$(gh run list \ - --workflow=test.yaml \ + output=$(gh run list -R ${{ secrets.E2E_TESTING_REPO }} \ - -b e2e-i${{ github.run_id }}n${{ github.run_number }}r \ - --json workflowDatabaseId,status) + -L 100 \ + --json headBranch,status \ + | jq '[.[] | select(.headBranch=="e2e-i${{ github.run_id }}n${{ github.run_number }}r")]') if [ $(echo "$output" | jq 'length') -eq 0 ] then From e6ceb3c2a5aca23c413546a57c4d558ea2ebff89 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 02:43:02 +0800 Subject: [PATCH 030/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 68c486464..4b5a58eb2 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -59,8 +59,6 @@ jobs: with: name: github-runner_ubuntu-22.04-amd64.charm - - run: ls -lah - - name: Deploy github-runner Charm run: | cp github-runner_ubuntu-22.04-amd64.charm /home/ubuntu/github-runner_ubuntu-22.04-amd64.charm @@ -105,7 +103,7 @@ jobs: | jq '.[] | select(.headBranch=="e2e-i${{ github.run_id }}n${{ github.run_number }}r")' get-workflow-status() { - output=$(gh run list + output=$(gh run list \ -R ${{ secrets.E2E_TESTING_REPO }} \ -L 100 \ --json headBranch,status \ From 845136d7ef40c51f4d0af24500d4ef8331b82f69 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 10:28:36 +0800 Subject: [PATCH 031/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 4b5a58eb2..1c8089a45 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -95,8 +95,12 @@ jobs: -f runner=e2e-i${{ github.run_id }}n${{ github.run_number }}r sleep 5 - - gh run list + + - name: Watch github-runner + env: + GH_TOKEN: ${{ secrets.E2E_TESTING_TOKEN }} + run: | + gh run list \ -R ${{ secrets.E2E_TESTING_REPO }} \ -L 100 \ --json headBranch,status,workflowDatabaseId \ From 9eedbc11cd63e552bf7cffd82ed1a58b05719536 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 10:56:41 +0800 Subject: [PATCH 032/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 1c8089a45..856e0c8b1 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -39,7 +39,7 @@ jobs: runs-on: [ self-hosted, linux, x64, e2e-test ] needs: build-charm steps: - - name: Setup Lxd Controller + - name: Setup Lxd Juju Controller uses: charmed-kubernetes/actions-operator@main with: juju-channel: 3.1/stable @@ -54,6 +54,12 @@ jobs: - name: Change Testing Model Logging Level run: juju model-config logging-config="=INFO;unit=DEBUG" + - name: Set Testing Model Proxy Configuration + run: | + juju model-config juju-http-proxy=$http_proxy + juju model-config juju-https-proxy=$https_proxy + juju model-config juju-no-proxy=$no_proxy + - name: Download github-runner Charm uses: actions/download-artifact@v3 with: @@ -123,10 +129,10 @@ jobs: fi } - juju debug-log & + juju debug-log --replay --tail & - for i in {1..1200} + for i in {1..360} do echo workflow status: $(get-workflow-status) - sleep 3 + sleep 10 done; kill $(jobs -p) & From 550a99460edd9b6b1318ae8d52a61d42d7f5060e Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 11:48:03 +0800 Subject: [PATCH 033/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 856e0c8b1..5abfacae4 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -71,7 +71,7 @@ jobs: juju deploy /home/ubuntu/github-runner_ubuntu-22.04-amd64.charm \ e2e-i${{ github.run_id }}n${{ github.run_number }}r \ --base ubuntu@22.04 \ - --config path=canonical/github-runner-operator \ + --config path=${{ secrets.E2E_TESTING_REPO }} \ --config token=${{ secrets.E2E_TESTING_TOKEN }} \ --config virtual-machines=1 From 32745f860e51c94617a83c31702de8eb61da389c Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 12:37:11 +0800 Subject: [PATCH 034/113] Update lxd.py --- src/lxd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lxd.py b/src/lxd.py index 0896bda56..97c6829a2 100644 --- a/src/lxd.py +++ b/src/lxd.py @@ -198,8 +198,8 @@ def start(self, timeout: int = 30, force: bool = True, wait: bool = False) -> No LxdException: Unable to start the LXD instance. """ try: - self._pylxd_instance.start(timeout, force, wait) - except pylxd.exceptions.LXDAPIException as err: + execute_command(["/snap/bin/lxc", "start", self.name]) + except SubprocessError as err: logger.exception("Failed to start LXD instance") raise LxdError(f"Unable to start LXD instance {self.name}") from err From 16d30d76a8bc736141c1c50401f6853ecdb1a7a6 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 12:39:31 +0800 Subject: [PATCH 035/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 5abfacae4..348e0d94c 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -21,6 +21,10 @@ jobs: path: github-runner_ubuntu-22.04-amd64.charm key: github-runner-charm-${{ hashFiles('**/*') }} + - name: Setup LXD + if: steps.cache-charm.outputs.cache-hit != 'true' + uses: canonical/setup-lxd + - name: Install charmcraft if: steps.cache-charm.outputs.cache-hit != 'true' run: sudo snap install charmcraft --classic From 91e26c1c885526b77ad3190b0d432c0f707f26d3 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 12:45:30 +0800 Subject: [PATCH 036/113] Test --- .github/workflows/build_charm.yaml | 2 +- .github/workflows/start_e2e_test.yaml | 2 +- .github/workflows/test.yaml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_charm.yaml b/.github/workflows/build_charm.yaml index 41122d32d..13584e64c 100644 --- a/.github/workflows/build_charm.yaml +++ b/.github/workflows/build_charm.yaml @@ -1,7 +1,7 @@ name: Build charm on: - pull_request: +# pull_request: workflow_call: workflow_dispatch: diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 348e0d94c..552114b62 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -23,7 +23,7 @@ jobs: - name: Setup LXD if: steps.cache-charm.outputs.cache-hit != 'true' - uses: canonical/setup-lxd + uses: canonical/setup-lxd@main - name: Install charmcraft if: steps.cache-charm.outputs.cache-hit != 'true' diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index ee5fa3eee..672005ade 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,7 +1,7 @@ name: Tests -on: - pull_request: +on: {} +# pull_request: jobs: unit-tests: From 61c45a570db3b1a82b69e47e52cdcf61a4035d7f Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 13:25:43 +0800 Subject: [PATCH 037/113] test --- .github/workflows/start_e2e_test.yaml | 1 + src/runner.py | 44 ++++++++++++++++++--------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 552114b62..063650388 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -5,6 +5,7 @@ on: jobs: build-charm: + name: Build Charm runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/src/runner.py b/src/runner.py index 9bc246808..e2bde7083 100644 --- a/src/runner.py +++ b/src/runner.py @@ -29,7 +29,7 @@ RunnerStatus, VirtualMachineResources, ) -from utilities import retry +from utilities import retry, execute_command logger = logging.getLogger(__name__) @@ -54,11 +54,11 @@ class Runner: pre_job_script = runner_application / "pre-job.sh" def __init__( - self, - clients: RunnerClients, - runner_config: RunnerConfig, - runner_status: RunnerStatus, - instance: Optional[LxdInstance] = None, + self, + clients: RunnerClients, + runner_config: RunnerConfig, + runner_status: RunnerStatus, + instance: Optional[LxdInstance] = None, ): """Construct the runner instance. @@ -74,11 +74,11 @@ def __init__( self.instance = instance def create( - self, - image: str, - resources: VirtualMachineResources, - binary_path: Path, - registration_token: str, + self, + image: str, + resources: VirtualMachineResources, + binary_path: Path, + registration_token: str, ): """Create the runner instance on LXD and register it on GitHub. @@ -187,7 +187,7 @@ def remove(self, remove_token: str) -> None: @retry(tries=5, delay=1, local_logger=logger) def _create_instance( - self, image: str, resources: VirtualMachineResources, ephemeral: bool = True + self, image: str, resources: VirtualMachineResources, ephemeral: bool = True ) -> LxdInstance: """Create an instance of runner. @@ -218,8 +218,24 @@ def _create_instance( "ephemeral": ephemeral, "profiles": ["default", "runner", resource_profile], } - - instance = self._clients.lxd.instances.create(config=instance_config, wait=True) + execute_command( + [ + "/snap/bin/lxc", + "init", "ubuntu:22.04", + self.config.name, + "--vm", + "--ephemeral", + "--profile", + "default", + "--profile", + "runner", + "--profile", + resource_profile + ] + ) + instances = self._clients.lxd.instances.all() + instance = [i for i in instances if i.name == self.config.name][0] + # instance = self._clients.lxd.instances.create(config=instance_config, wait=True) self.status.exist = True return instance From 3a9c3d728b3172c887ebee53d9c9e3719c09cc9c Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 14:02:25 +0800 Subject: [PATCH 038/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 063650388..7da531c53 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -74,7 +74,7 @@ jobs: run: | cp github-runner_ubuntu-22.04-amd64.charm /home/ubuntu/github-runner_ubuntu-22.04-amd64.charm juju deploy /home/ubuntu/github-runner_ubuntu-22.04-amd64.charm \ - e2e-i${{ github.run_id }}n${{ github.run_number }}r \ + e${{ github.run_id }}n${{ github.run_number }}r \ --base ubuntu@22.04 \ --config path=${{ secrets.E2E_TESTING_REPO }} \ --config token=${{ secrets.E2E_TESTING_TOKEN }} \ @@ -97,13 +97,13 @@ jobs: -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ /repos/${{ secrets.E2E_TESTING_REPO }}/git/refs \ - -f ref='refs/heads/e2e-i${{ github.run_id }}n${{ github.run_number }}r' \ + -f ref='refs/heads/e${{ github.run_id }}n${{ github.run_number }}r' \ -f sha=$MAIN_SHA gh workflow run test.yaml \ -R ${{ secrets.E2E_TESTING_REPO }} \ - --ref e2e-i${{ github.run_id }}n${{ github.run_number }}r \ - -f runner=e2e-i${{ github.run_id }}n${{ github.run_number }}r + --ref e${{ github.run_id }}n${{ github.run_number }}r \ + -f runner=e${{ github.run_id }}n${{ github.run_number }}r sleep 5 @@ -115,14 +115,14 @@ jobs: -R ${{ secrets.E2E_TESTING_REPO }} \ -L 100 \ --json headBranch,status,workflowDatabaseId \ - | jq '.[] | select(.headBranch=="e2e-i${{ github.run_id }}n${{ github.run_number }}r")' + | jq '.[] | select(.headBranch=="e${{ github.run_id }}n${{ github.run_number }}r")' get-workflow-status() { output=$(gh run list \ -R ${{ secrets.E2E_TESTING_REPO }} \ -L 100 \ --json headBranch,status \ - | jq '[.[] | select(.headBranch=="e2e-i${{ github.run_id }}n${{ github.run_number }}r")]') + | jq '[.[] | select(.headBranch=="e${{ github.run_id }}n${{ github.run_number }}r")]') if [ $(echo "$output" | jq 'length') -eq 0 ] then From ed56ab3e063e3339466181fb68ae082e4ad1a322 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 14:14:32 +0800 Subject: [PATCH 039/113] Update lxd.py --- src/lxd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lxd.py b/src/lxd.py index 97c6829a2..0896bda56 100644 --- a/src/lxd.py +++ b/src/lxd.py @@ -198,8 +198,8 @@ def start(self, timeout: int = 30, force: bool = True, wait: bool = False) -> No LxdException: Unable to start the LXD instance. """ try: - execute_command(["/snap/bin/lxc", "start", self.name]) - except SubprocessError as err: + self._pylxd_instance.start(timeout, force, wait) + except pylxd.exceptions.LXDAPIException as err: logger.exception("Failed to start LXD instance") raise LxdError(f"Unable to start LXD instance {self.name}") from err From 1748cd8cb360f43513955dcd30bfd60205b23fa5 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 14:14:41 +0800 Subject: [PATCH 040/113] Revert "test" This reverts commit 61c45a570db3b1a82b69e47e52cdcf61a4035d7f. --- .github/workflows/start_e2e_test.yaml | 1 - src/runner.py | 44 +++++++++------------------ 2 files changed, 14 insertions(+), 31 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 7da531c53..f9ea3cbed 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -5,7 +5,6 @@ on: jobs: build-charm: - name: Build Charm runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/src/runner.py b/src/runner.py index e2bde7083..9bc246808 100644 --- a/src/runner.py +++ b/src/runner.py @@ -29,7 +29,7 @@ RunnerStatus, VirtualMachineResources, ) -from utilities import retry, execute_command +from utilities import retry logger = logging.getLogger(__name__) @@ -54,11 +54,11 @@ class Runner: pre_job_script = runner_application / "pre-job.sh" def __init__( - self, - clients: RunnerClients, - runner_config: RunnerConfig, - runner_status: RunnerStatus, - instance: Optional[LxdInstance] = None, + self, + clients: RunnerClients, + runner_config: RunnerConfig, + runner_status: RunnerStatus, + instance: Optional[LxdInstance] = None, ): """Construct the runner instance. @@ -74,11 +74,11 @@ def __init__( self.instance = instance def create( - self, - image: str, - resources: VirtualMachineResources, - binary_path: Path, - registration_token: str, + self, + image: str, + resources: VirtualMachineResources, + binary_path: Path, + registration_token: str, ): """Create the runner instance on LXD and register it on GitHub. @@ -187,7 +187,7 @@ def remove(self, remove_token: str) -> None: @retry(tries=5, delay=1, local_logger=logger) def _create_instance( - self, image: str, resources: VirtualMachineResources, ephemeral: bool = True + self, image: str, resources: VirtualMachineResources, ephemeral: bool = True ) -> LxdInstance: """Create an instance of runner. @@ -218,24 +218,8 @@ def _create_instance( "ephemeral": ephemeral, "profiles": ["default", "runner", resource_profile], } - execute_command( - [ - "/snap/bin/lxc", - "init", "ubuntu:22.04", - self.config.name, - "--vm", - "--ephemeral", - "--profile", - "default", - "--profile", - "runner", - "--profile", - resource_profile - ] - ) - instances = self._clients.lxd.instances.all() - instance = [i for i in instances if i.name == self.config.name][0] - # instance = self._clients.lxd.instances.create(config=instance_config, wait=True) + + instance = self._clients.lxd.instances.create(config=instance_config, wait=True) self.status.exist = True return instance From ca815f126e1db1891b0f31ea154367fec99fca06 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 14:36:34 +0800 Subject: [PATCH 041/113] Update runner.py --- src/runner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runner.py b/src/runner.py index 9bc246808..e3adabe9f 100644 --- a/src/runner.py +++ b/src/runner.py @@ -306,7 +306,7 @@ def _start_instance(self) -> None: # Setting `wait=True` only ensure the instance has begin to boot up. self.instance.start(wait=True) - @retry(tries=20, delay=30, local_logger=logger) + @retry(tries=60, delay=30, local_logger=logger) def _wait_boot_up(self) -> None: if self.instance is None: raise RunnerError("Runner operation called prior to runner creation.") From 1c0a7e9f4cc8a9e58cb1a13f82b16da60f2671ab Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 15:50:19 +0800 Subject: [PATCH 042/113] test --- .github/workflows/start_e2e_test.yaml | 10 ++++++---- src/runner.py | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index f9ea3cbed..3368af423 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -53,7 +53,7 @@ jobs: run: juju add-model testing - name: Setting Testing Model Constraints - run: juju set-model-constraints "virt-type=virtual-machine mem=16G cores=4" + run: juju set-model-constraints "virt-type=virtual-machine mem=24G cores=6" - name: Change Testing Model Logging Level run: juju model-config logging-config="=INFO;unit=DEBUG" @@ -77,7 +77,9 @@ jobs: --base ubuntu@22.04 \ --config path=${{ secrets.E2E_TESTING_REPO }} \ --config token=${{ secrets.E2E_TESTING_TOKEN }} \ - --config virtual-machines=1 + --config virtual-machines=1 \ + --config vm-cpu=4 \ + --config vm-cpu=16GiB - name: Install GitHub Cli run: which gh || sudo apt install gh -y @@ -135,8 +137,8 @@ jobs: juju debug-log --replay --tail & - for i in {1..360} + for i in {1..120} do echo workflow status: $(get-workflow-status) - sleep 10 + sleep 30 done; kill $(jobs -p) & diff --git a/src/runner.py b/src/runner.py index e3adabe9f..d831b6e1f 100644 --- a/src/runner.py +++ b/src/runner.py @@ -306,7 +306,7 @@ def _start_instance(self) -> None: # Setting `wait=True` only ensure the instance has begin to boot up. self.instance.start(wait=True) - @retry(tries=60, delay=30, local_logger=logger) + @retry(tries=120, delay=30, local_logger=logger) def _wait_boot_up(self) -> None: if self.instance is None: raise RunnerError("Runner operation called prior to runner creation.") From 05c55fa1376e602b5b844f5d82e703b1f8968052 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Fri, 16 Jun 2023 16:04:42 +0800 Subject: [PATCH 043/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 3368af423..e09ba32f8 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -79,7 +79,7 @@ jobs: --config token=${{ secrets.E2E_TESTING_TOKEN }} \ --config virtual-machines=1 \ --config vm-cpu=4 \ - --config vm-cpu=16GiB + --config vm-memory=16GiB - name: Install GitHub Cli run: which gh || sudo apt install gh -y From 0d479f552d79efe1a97a44d50f38c73f7c807f01 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sat, 17 Jun 2023 01:17:02 +0800 Subject: [PATCH 044/113] Update runner.py --- src/runner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runner.py b/src/runner.py index d831b6e1f..b096905f3 100644 --- a/src/runner.py +++ b/src/runner.py @@ -207,7 +207,7 @@ def _create_instance( # Create runner instance. instance_config: LxdInstanceConfig = { "name": self.config.name, - "type": "virtual-machine", + "type": "container", "source": { "type": "image", "mode": "pull", From 05ac636ee98da94b93f4fab8c40109536904ac29 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 15:05:41 +0800 Subject: [PATCH 045/113] using nested LXD --- .github/workflows/start_e2e_test.yaml | 199 +++++++++++++++++++++----- .gitignore | 1 + src/runner.py | 33 +++-- templates/pre-job.j2 | 12 +- 4 files changed, 192 insertions(+), 53 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index e09ba32f8..3a9359e91 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -14,6 +14,15 @@ jobs: rm -rf .git rm -rf .github + - name: Write lxd-profile.yaml + run: | + cat << EOF > ./lxd-profile.yaml + config: + security.nesting: true + security.privileged: true + raw.lxc: lxc.apparmor.profile=unconfined + EOF + - name: Cache github-runner Charm uses: actions/cache@v3 id: cache-charm @@ -23,7 +32,43 @@ jobs: - name: Setup LXD if: steps.cache-charm.outputs.cache-hit != 'true' - uses: canonical/setup-lxd@main + run: | + if ! snap info lxd | grep "installed"; then + sudo snap install lxd + fi + sudo lxd waitready + cat < None: @retry(tries=5, delay=1, local_logger=logger) def _create_instance( - self, image: str, resources: VirtualMachineResources, ephemeral: bool = True + self, image: str, resources: VirtualMachineResources, ephemeral: bool = True ) -> LxdInstance: """Create an instance of runner. @@ -207,7 +213,7 @@ def _create_instance( # Create runner instance. instance_config: LxdInstanceConfig = { "name": self.config.name, - "type": "container", + "type": "container" if _LXD_PROFILE_YAML.exists() else "virtual-machine", "source": { "type": "image", "mode": "pull", @@ -235,6 +241,9 @@ def _ensure_runner_profile(self) -> None: profile_config = { "security.nesting": "true", } + if _LXD_PROFILE_YAML.exists(): + additional_configs = yaml.safe_load(_LXD_PROFILE_YAML.read_text())["config"] + profile_config.update({k: json.dumps(v) for k, v in additional_configs.items()}) self._clients.lxd.profiles.create("runner", profile_config, {}) # Verify the action is successful. diff --git a/templates/pre-job.j2 b/templates/pre-job.j2 index 968a77dbb..4a2b57ea9 100644 --- a/templates/pre-job.j2 +++ b/templates/pre-job.j2 @@ -3,9 +3,9 @@ GITHUB_SOURCE_REPOSITORY=$(cat "${GITHUB_EVENT_PATH}" | jq -r '.pull_request.head.repo.full_name') # Request repo-policy-compliance service check. -curl --noproxy '*' \ - --fail-with-body \ - -H 'Authorization: Bearer {{one_time_token}}' \ - -H 'Content-Type: application/json' \ - -d "{\"repository_name\": \"${GITHUB_REPOSITORY}\", \"source_repository_name\": \"${GITHUB_SOURCE_REPOSITORY}\", \"target_branch_name\": \"${GITHUB_BASE_REF}\", \"source_branch_name\": \"${GITHUB_HEAD_REF}\", \"commit_sha\": \"${GITHUB_SHA}\"}" \ - http://{{host_ip}}:8080/check-run +#curl --noproxy '*' \ +# --fail-with-body \ +# -H 'Authorization: Bearer {{one_time_token}}' \ +# -H 'Content-Type: application/json' \ +# -d "{\"repository_name\": \"${GITHUB_REPOSITORY}\", \"source_repository_name\": \"${GITHUB_SOURCE_REPOSITORY}\", \"target_branch_name\": \"${GITHUB_BASE_REF}\", \"source_branch_name\": \"${GITHUB_HEAD_REF}\", \"commit_sha\": \"${GITHUB_SHA}\"}" \ +# http://{{host_ip}}:8080/check-run From 3636f410e03520e0fddfc459901bce6a21281b37 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 15:06:44 +0800 Subject: [PATCH 046/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 3a9359e91..49dfe2c23 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -37,7 +37,7 @@ jobs: sudo snap install lxd fi sudo lxd waitready - cat < Date: Sun, 18 Jun 2023 15:10:24 +0800 Subject: [PATCH 047/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 49dfe2c23..499cc375b 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -38,37 +38,16 @@ jobs: fi sudo lxd waitready cat < Date: Sun, 18 Jun 2023 15:13:03 +0800 Subject: [PATCH 048/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 499cc375b..2f571a652 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -38,12 +38,36 @@ jobs: fi sudo lxd waitready cat < Date: Sun, 18 Jun 2023 15:22:52 +0800 Subject: [PATCH 049/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 2f571a652..19f8f0d5e 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -4,7 +4,8 @@ on: pull_request: jobs: - build-charm: + end-to-end-test: + name: Run End-to-End Test runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -71,7 +72,7 @@ jobs: EOF sudo snap set lxd daemon.group=adm sudo snap restart lxd - sudo lxc storage list + sudo lxc profile list - name: Install charmcraft if: steps.cache-charm.outputs.cache-hit != 'true' @@ -79,7 +80,7 @@ jobs: - name: Pack github-runner Charm if: steps.cache-charm.outputs.cache-hit != 'true' - run: charmcraft pack || ( cat /home/ubuntu/.local/state/charmcraft/log/* 1 && exit 1 ) + run: charmcraft pack || ( cat ~/.local/state/charmcraft/log/* 1 && exit 1 ) # - name: Upload github-runner Charm # uses: actions/upload-artifact@v3 From 77dd7099aad7f3ab40dd3af2af0afd45598ef6a7 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 15:29:07 +0800 Subject: [PATCH 050/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 51 +++++---------------------- 1 file changed, 8 insertions(+), 43 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 19f8f0d5e..3f10e9366 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -15,6 +15,14 @@ jobs: rm -rf .git rm -rf .github + - name: Setup LXD + uses: canonical/setup-lxd@main + + - name: Update LXD Storage + run: | + sudo lxc storage create default-btrfs btrfs size=50GiB + sudo lxc profile device set default root pool=default-btrfs + - name: Write lxd-profile.yaml run: | cat << EOF > ./lxd-profile.yaml @@ -31,49 +39,6 @@ jobs: path: github-runner_ubuntu-22.04-amd64.charm key: github-runner-charm-${{ hashFiles('**/*') }} - - name: Setup LXD - if: steps.cache-charm.outputs.cache-hit != 'true' - run: | - if ! snap info lxd | grep "installed"; then - sudo snap install lxd - fi - sudo lxd waitready - cat < Date: Sun, 18 Jun 2023 15:43:04 +0800 Subject: [PATCH 051/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 3f10e9366..0957c4266 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -53,9 +53,11 @@ jobs: # name: github-runner_ubuntu-22.04-amd64.charm # path: github-runner_ubuntu-22.04-amd64.charm - - name: Setup LXD Juju Controller + - name: Install Juju + run: sudo snap install juju --classic --channel=3.1/stable + + - name: Bootstrap Juju LXD Controller run: | - sudo snap install juju --classic --channel=3.1/stable sudo sg lxd -c juju bootstrap --debug --verbose lxd \ --model-default test-mode=true \ --model-default automatically-retry-hooks=false \ From 2aedd54460f3a13ebf3a345609bedb37add7325b Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 15:45:43 +0800 Subject: [PATCH 052/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 36 ++++++++++++++++++--------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 0957c4266..64b689a35 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -4,8 +4,8 @@ on: pull_request: jobs: - end-to-end-test: - name: Run End-to-End Test + build-charm: + name: Build Charm runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -18,11 +18,6 @@ jobs: - name: Setup LXD uses: canonical/setup-lxd@main - - name: Update LXD Storage - run: | - sudo lxc storage create default-btrfs btrfs size=50GiB - sudo lxc profile device set default root pool=default-btrfs - - name: Write lxd-profile.yaml run: | cat << EOF > ./lxd-profile.yaml @@ -47,11 +42,23 @@ jobs: if: steps.cache-charm.outputs.cache-hit != 'true' run: charmcraft pack || ( cat ~/.local/state/charmcraft/log/* 1 && exit 1 ) -# - name: Upload github-runner Charm -# uses: actions/upload-artifact@v3 -# with: -# name: github-runner_ubuntu-22.04-amd64.charm -# path: github-runner_ubuntu-22.04-amd64.charm + - name: Upload github-runner Charm + uses: actions/upload-artifact@v3 + with: + name: github-runner_ubuntu-22.04-amd64.charm + path: github-runner_ubuntu-22.04-amd64.charm + + deploy-e2e-test-runner: + runs-on: ubuntu-latest + needs: build-charm + steps: + - name: Setup LXD + uses: canonical/setup-lxd@main + + - name: Update LXD Storage + run: | + sudo lxc storage create default-btrfs btrfs size=50GiB + sudo lxc profile device set default root pool=default-btrfs - name: Install Juju run: sudo snap install juju --classic --channel=3.1/stable @@ -67,6 +74,11 @@ jobs: - name: Create Testing Juju Model run: juju add-model testing + - name: Download github-runner Charm + uses: actions/download-artifact@v3 + with: + name: github-runner_ubuntu-22.04-amd64.charm + - name: Deploy github-runner Charm run: | cp github-runner_ubuntu-22.04-amd64.charm /home/ubuntu/github-runner_ubuntu-22.04-amd64.charm From 29167396488beb9278c77fd95541282418c41472 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 15:58:29 +0800 Subject: [PATCH 053/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 64b689a35..a396d50af 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -52,24 +52,27 @@ jobs: runs-on: ubuntu-latest needs: build-charm steps: - - name: Setup LXD - uses: canonical/setup-lxd@main + - name: Setup Lxd Juju Controller + uses: charmed-kubernetes/actions-operator@main + with: + juju-channel: 3.1/stable + provider: lxd - name: Update LXD Storage run: | sudo lxc storage create default-btrfs btrfs size=50GiB sudo lxc profile device set default root pool=default-btrfs - - name: Install Juju - run: sudo snap install juju --classic --channel=3.1/stable - - - name: Bootstrap Juju LXD Controller - run: | - sudo sg lxd -c juju bootstrap --debug --verbose lxd \ - --model-default test-mode=true \ - --model-default automatically-retry-hooks=false \ - --model-default logging-config="=DEBUG" \ - --bootstrap-constraints="cores=2 mem=4G" +# - name: Install Juju +# run: sudo snap install juju --classic --channel=3.1/stable +# +# - name: Bootstrap Juju LXD Controller +# run: | +# sudo sg lxd -c juju bootstrap --debug --verbose lxd \ +# --model-default test-mode=true \ +# --model-default automatically-retry-hooks=false \ +# --model-default logging-config="=DEBUG" \ +# --bootstrap-constraints="cores=2 mem=4G" - name: Create Testing Juju Model run: juju add-model testing From 97a0c1ccbadefa82b02c27b653600f1d7ce40bf6 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 16:06:12 +0800 Subject: [PATCH 054/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 40 +++++++++++++++------------ 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index a396d50af..8a287f307 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -52,27 +52,33 @@ jobs: runs-on: ubuntu-latest needs: build-charm steps: - - name: Setup Lxd Juju Controller - uses: charmed-kubernetes/actions-operator@main - with: - juju-channel: 3.1/stable - provider: lxd - - - name: Update LXD Storage +# - name: Setup Lxd Juju Controller +# uses: charmed-kubernetes/actions-operator@main +# with: +# juju-channel: 3.1/stable +# provider: lxd + - name: Initialize LXD run: | + sudo snap refresh lxd --channel=latest/stable + sudo lxd waitready + sudo lxd init --auto + sudo chmod a+wr /var/snap/lxd/common/lxd/unix.socket + sudo lxc network set lxdbr0 ipv6.address none sudo lxc storage create default-btrfs btrfs size=50GiB sudo lxc profile device set default root pool=default-btrfs + sudo iptables -F FORWARD + sudo iptables -P FORWARD ACCEPT -# - name: Install Juju -# run: sudo snap install juju --classic --channel=3.1/stable -# -# - name: Bootstrap Juju LXD Controller -# run: | -# sudo sg lxd -c juju bootstrap --debug --verbose lxd \ -# --model-default test-mode=true \ -# --model-default automatically-retry-hooks=false \ -# --model-default logging-config="=DEBUG" \ -# --bootstrap-constraints="cores=2 mem=4G" + - name: Install Juju + run: sudo snap install juju --classic --channel=3.1/stable + + - name: Bootstrap Juju LXD Controller + run: | + sudo sg lxd -c juju bootstrap --debug --verbose lxd \ + --model-default test-mode=true \ + --model-default automatically-retry-hooks=false \ + --model-default logging-config="=DEBUG" \ + --bootstrap-constraints="cores=2 mem=4G" - name: Create Testing Juju Model run: juju add-model testing From 4074c2e361f0fdb29125851a704d9deac43a5426 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 16:08:45 +0800 Subject: [PATCH 055/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 8a287f307..fc072cd9a 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -74,7 +74,7 @@ jobs: - name: Bootstrap Juju LXD Controller run: | - sudo sg lxd -c juju bootstrap --debug --verbose lxd \ + lxd -c juju bootstrap --debug --verbose lxd \ --model-default test-mode=true \ --model-default automatically-retry-hooks=false \ --model-default logging-config="=DEBUG" \ From 3fd472bdc10f082f938a6ed3c0c4261dd96b1dc6 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 16:09:00 +0800 Subject: [PATCH 056/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index fc072cd9a..05304fa28 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -74,7 +74,7 @@ jobs: - name: Bootstrap Juju LXD Controller run: | - lxd -c juju bootstrap --debug --verbose lxd \ + juju bootstrap --debug --verbose lxd \ --model-default test-mode=true \ --model-default automatically-retry-hooks=false \ --model-default logging-config="=DEBUG" \ From 2806fde3bf248f76232b18777ca9842b780e5f38 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 16:13:59 +0800 Subject: [PATCH 057/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 05304fa28..54d2bd1b1 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -90,7 +90,6 @@ jobs: - name: Deploy github-runner Charm run: | - cp github-runner_ubuntu-22.04-amd64.charm /home/ubuntu/github-runner_ubuntu-22.04-amd64.charm juju deploy /home/ubuntu/github-runner_ubuntu-22.04-amd64.charm \ e${{ github.run_id }}n${{ github.run_number }}r \ --base ubuntu@22.04 \ From 375b448bd836f8d40489e3aa490c3293bdaf13fb Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 16:14:30 +0800 Subject: [PATCH 058/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 54d2bd1b1..498cc7372 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -90,7 +90,8 @@ jobs: - name: Deploy github-runner Charm run: | - juju deploy /home/ubuntu/github-runner_ubuntu-22.04-amd64.charm \ + cp github-runner_ubuntu-22.04-amd64.charm /home/$USER/github-runner_ubuntu-22.04-amd64.charm + juju deploy /home/$USER/github-runner_ubuntu-22.04-amd64.charm \ e${{ github.run_id }}n${{ github.run_number }}r \ --base ubuntu@22.04 \ --config path=${{ secrets.E2E_TESTING_REPO }} \ From 73fae164de90d1a10aa54b610427666a193c592f Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 16:45:13 +0800 Subject: [PATCH 059/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 124 +++----------------------- 1 file changed, 11 insertions(+), 113 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 498cc7372..3de2d4e6b 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -52,11 +52,6 @@ jobs: runs-on: ubuntu-latest needs: build-charm steps: -# - name: Setup Lxd Juju Controller -# uses: charmed-kubernetes/actions-operator@main -# with: -# juju-channel: 3.1/stable -# provider: lxd - name: Initialize LXD run: | sudo snap refresh lxd --channel=latest/stable @@ -144,7 +139,7 @@ jobs: if [ $(echo "$output" | jq 'length') -eq 0 ] then - echo "not-started" + echo "not_started" else # Parse output with jq to get the status field of the first object status=$(echo "$output" | jq -r '.[0].status') @@ -156,110 +151,13 @@ jobs: for i in {1..120} do - echo workflow status: $(get-workflow-status) - sleep 30 - done; kill $(jobs -p) & -# -# deploy-e2e-test-runner: -# runs-on: ubuntu-latest -# needs: build-charm -# steps: -# - name: Setup Lxd Juju Controller -# uses: charmed-kubernetes/actions-operator@main -# with: -# juju-channel: 3.1/stable -# provider: lxd -# -# - name: Create Testing Juju Model -# run: juju add-model testing -# -# - name: Setting Testing Model Constraints -# run: juju set-model-constraints "virt-type=virtual-machine mem=24G cores=6" -# -# - name: Change Testing Model Logging Level -# run: juju model-config logging-config="=INFO;unit=DEBUG" -# -# - name: Set Testing Model Proxy Configuration -# run: | -# juju model-config juju-http-proxy=$http_proxy -# juju model-config juju-https-proxy=$https_proxy -# juju model-config juju-no-proxy=$no_proxy -# -# - name: Download github-runner Charm -# uses: actions/download-artifact@v3 -# with: -# name: github-runner_ubuntu-22.04-amd64.charm -# -# - name: Deploy github-runner Charm -# run: | -# cp github-runner_ubuntu-22.04-amd64.charm /home/ubuntu/github-runner_ubuntu-22.04-amd64.charm -# juju deploy /home/ubuntu/github-runner_ubuntu-22.04-amd64.charm \ -# e${{ github.run_id }}n${{ github.run_number }}r \ -# --base ubuntu@22.04 \ -# --config path=${{ secrets.E2E_TESTING_REPO }} \ -# --config token=${{ secrets.E2E_TESTING_TOKEN }} \ -# --config virtual-machines=1 \ -# --config vm-cpu=4 \ -# --config vm-memory=16GiB -# -# - name: Install GitHub Cli -# run: which gh || sudo apt install gh -y -# -# - name: Dispatch Workflow on Testing Runner -# env: -# GH_TOKEN: ${{ secrets.E2E_TESTING_TOKEN }} -# run: | -# MAIN_SHA=$(gh api \ -# -H "Accept: application/vnd.github+json" \ -# -H "X-GitHub-Api-Version: 2022-11-28" \ -# /repos/${{ secrets.E2E_TESTING_REPO }}/git/ref/heads/main --jq .object.sha) -# -# gh api \ -# --method POST \ -# -H "Accept: application/vnd.github+json" \ -# -H "X-GitHub-Api-Version: 2022-11-28" \ -# /repos/${{ secrets.E2E_TESTING_REPO }}/git/refs \ -# -f ref='refs/heads/e${{ github.run_id }}n${{ github.run_number }}r' \ -# -f sha=$MAIN_SHA -# -# gh workflow run test.yaml \ -# -R ${{ secrets.E2E_TESTING_REPO }} \ -# --ref e${{ github.run_id }}n${{ github.run_number }}r \ -# -f runner=e${{ github.run_id }}n${{ github.run_number }}r -# -# sleep 5 -# -# - name: Watch github-runner -# env: -# GH_TOKEN: ${{ secrets.E2E_TESTING_TOKEN }} -# run: | -# gh run list \ -# -R ${{ secrets.E2E_TESTING_REPO }} \ -# -L 100 \ -# --json headBranch,status,workflowDatabaseId \ -# | jq '.[] | select(.headBranch=="e${{ github.run_id }}n${{ github.run_number }}r")' -# -# get-workflow-status() { -# output=$(gh run list \ -# -R ${{ secrets.E2E_TESTING_REPO }} \ -# -L 100 \ -# --json headBranch,status \ -# | jq '[.[] | select(.headBranch=="e${{ github.run_id }}n${{ github.run_number }}r")]') -# -# if [ $(echo "$output" | jq 'length') -eq 0 ] -# then -# echo "not-started" -# else -# # Parse output with jq to get the status field of the first object -# status=$(echo "$output" | jq -r '.[0].status') -# echo "$status" -# fi -# } -# -# juju debug-log --replay --tail & -# -# for i in {1..120} -# do -# echo workflow status: $(get-workflow-status) -# sleep 30 -# done; kill $(jobs -p) & + sleep 30 + echo workflow status: $(get-workflow-status) + if [[ $status != "not-started" && $status != "queued" && $status != "in_progress" ]]; then + break + fi + done + kill $(jobs -p) + if [[ $status != "not-started" && $status != "queued" && $status != "in_progress" ]]; then + exit 1 + fi From 202577dfc8d01a4a5c3a6b4af654ff2283f567ce Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 16:49:41 +0800 Subject: [PATCH 060/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 3de2d4e6b..77b10c8c3 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -149,15 +149,17 @@ jobs: juju debug-log --replay --tail & - for i in {1..120} + for i in {1..90} do - sleep 30 + sleep 10 echo workflow status: $(get-workflow-status) if [[ $status != "not-started" && $status != "queued" && $status != "in_progress" ]]; then break fi done + kill $(jobs -p) + if [[ $status != "not-started" && $status != "queued" && $status != "in_progress" ]]; then exit 1 fi From b0ed3e807e0135bc2f72921f24a7bf6703351abd Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 16:56:17 +0800 Subject: [PATCH 061/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 77b10c8c3..3a594b0cc 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -151,11 +151,12 @@ jobs: for i in {1..90} do - sleep 10 - echo workflow status: $(get-workflow-status) + status=$(get-workflow-status) + echo "workflow status: $status" if [[ $status != "not-started" && $status != "queued" && $status != "in_progress" ]]; then break fi + sleep 10 done kill $(jobs -p) From a9d5da81291d8ade92e85398f9b764d9d6a2dda3 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 17:17:10 +0800 Subject: [PATCH 062/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 3a594b0cc..903cdce7c 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -127,7 +127,7 @@ jobs: gh run list \ -R ${{ secrets.E2E_TESTING_REPO }} \ -L 100 \ - --json headBranch,status,workflowDatabaseId \ + --json headBranch,status,workflowDatabaseId,conclusion \ | jq '.[] | select(.headBranch=="e${{ github.run_id }}n${{ github.run_number }}r")' get-workflow-status() { @@ -161,6 +161,13 @@ jobs: kill $(jobs -p) - if [[ $status != "not-started" && $status != "queued" && $status != "in_progress" ]]; then + conclusion=$(gh run list \ + -R ${{ secrets.E2E_TESTING_REPO }} \ + -L 100 \ + --json headBranch,conclusion \ + | jq '.[] | select(.headBranch=="e${{ github.run_id }}n${{ github.run_number }}r") | .[0].conclusion') + + if [[ $status != "completed" || $conclusion != "success" ]]; then + echo test workflow failed exit 1 fi From 36469a9ed1a52d451c9d750013a5bef7b65aede3 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 17:31:07 +0800 Subject: [PATCH 063/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 903cdce7c..c1a52cb90 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -168,6 +168,6 @@ jobs: | jq '.[] | select(.headBranch=="e${{ github.run_id }}n${{ github.run_number }}r") | .[0].conclusion') if [[ $status != "completed" || $conclusion != "success" ]]; then - echo test workflow failed + echo "test workflow failed with status: $status, conclusion: $conclusion" exit 1 fi From 9cd29c937f66693bdc2d44e5417c5ceeb6d93fdf Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 17:33:30 +0800 Subject: [PATCH 064/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index c1a52cb90..a5b88316a 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -165,7 +165,7 @@ jobs: -R ${{ secrets.E2E_TESTING_REPO }} \ -L 100 \ --json headBranch,conclusion \ - | jq '.[] | select(.headBranch=="e${{ github.run_id }}n${{ github.run_number }}r") | .[0].conclusion') + | jq '.[] | select(.headBranch=="e${{ github.run_id }}n${{ github.run_number }}r") | .conclusion') if [[ $status != "completed" || $conclusion != "success" ]]; then echo "test workflow failed with status: $status, conclusion: $conclusion" From 5c67e9aba027d0cb85d40b06fe2c30847debd33a Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 18:05:57 +0800 Subject: [PATCH 065/113] Update pre-job.j2 --- templates/pre-job.j2 | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/templates/pre-job.j2 b/templates/pre-job.j2 index 4a2b57ea9..90a9e48ca 100644 --- a/templates/pre-job.j2 +++ b/templates/pre-job.j2 @@ -1,11 +1,33 @@ -#!/usr/bin/env bash +#!/usr/bin/env python3 -GITHUB_SOURCE_REPOSITORY=$(cat "${GITHUB_EVENT_PATH}" | jq -r '.pull_request.head.repo.full_name') +import os +import json +import requests -# Request repo-policy-compliance service check. -#curl --noproxy '*' \ -# --fail-with-body \ -# -H 'Authorization: Bearer {{one_time_token}}' \ -# -H 'Content-Type: application/json' \ -# -d "{\"repository_name\": \"${GITHUB_REPOSITORY}\", \"source_repository_name\": \"${GITHUB_SOURCE_REPOSITORY}\", \"target_branch_name\": \"${GITHUB_BASE_REF}\", \"source_branch_name\": \"${GITHUB_HEAD_REF}\", \"commit_sha\": \"${GITHUB_SHA}\"}" \ -# http://{{host_ip}}:8080/check-run +event_name = os.environ["GITHUB_EVENT_NAME"] +if event_name not in ("pull_request", "workflow_dispatch"): + raise ValueError(f"github event {event_name} is not supported") +commit_sha = os.environ["GITHUB_SHA"] +repository_name = os.environ["GITHUB_REPOSITORY"] +if event_name == "pull_request": + event_path = os.environ["GITHUB_EVENT_PATH"] + with open(event_path) as fo: + source_repository_name = json.load(fo)["pull_request"]["head"]["repo"]["full_name"] + target_branch_name = os.environ["GITHUB_BASE_REF"] + source_branch_name = os.environ["GITHUB_HEAD_REF"] +else: + source_repository_name = os.environ["GITHUB_REPOSITORY"] + target_branch_name = os.environ["GITHUB_REF"] + source_branch_name = os.environ["GITHUB_REF"] + +session = requests.session() +session.headers["Authorization"] = "Bearer {{one_time_token}}" +session.trust_env = False +response = session.post("http://{{host_ip}}:8080/check-run", timeout=10, json={ + "repository_name": repository_name, + "source_repository_name": source_repository_name, + "target_branch_name": target_branch_name, + "source_branch_name": source_branch_name, + "commit_sha": commit_sha +}) +response.raise_for_status() From 24e3b9f2ac0aad9fec598b919240886be596199f Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 18:40:25 +0800 Subject: [PATCH 066/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index a5b88316a..34fae5c5c 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -83,11 +83,22 @@ jobs: with: name: github-runner_ubuntu-22.04-amd64.charm + - name: Generate Run ID + id: run-id + shell: python + run: | + import random + import os + import strings + with open(os.environ['GITHUB_OUTPUT'], 'a') as f: + run_id = "".join(random.choice(string.ascii_lowercase) for _ in range(8)) + f.write(f"run-id={run_id}\n") + - name: Deploy github-runner Charm run: | cp github-runner_ubuntu-22.04-amd64.charm /home/$USER/github-runner_ubuntu-22.04-amd64.charm juju deploy /home/$USER/github-runner_ubuntu-22.04-amd64.charm \ - e${{ github.run_id }}n${{ github.run_number }}r \ + ${{ steps.run-id.outputs.run-id }} \ --base ubuntu@22.04 \ --config path=${{ secrets.E2E_TESTING_REPO }} \ --config token=${{ secrets.E2E_TESTING_TOKEN }} \ @@ -110,13 +121,13 @@ jobs: -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ /repos/${{ secrets.E2E_TESTING_REPO }}/git/refs \ - -f ref='refs/heads/e${{ github.run_id }}n${{ github.run_number }}r' \ + -f ref='refs/heads/${{ steps.run-id.outputs.run-id }}' \ -f sha=$MAIN_SHA gh workflow run test.yaml \ -R ${{ secrets.E2E_TESTING_REPO }} \ - --ref e${{ github.run_id }}n${{ github.run_number }}r \ - -f runner=e${{ github.run_id }}n${{ github.run_number }}r + --ref ${{ steps.run-id.outputs.run-id }} \ + -f runner=${{ steps.run-id.outputs.run-id }} sleep 5 @@ -128,14 +139,14 @@ jobs: -R ${{ secrets.E2E_TESTING_REPO }} \ -L 100 \ --json headBranch,status,workflowDatabaseId,conclusion \ - | jq '.[] | select(.headBranch=="e${{ github.run_id }}n${{ github.run_number }}r")' + | jq '.[] | select(.headBranch=="${{ steps.run-id.outputs.run-id }}")' get-workflow-status() { output=$(gh run list \ -R ${{ secrets.E2E_TESTING_REPO }} \ -L 100 \ --json headBranch,status \ - | jq '[.[] | select(.headBranch=="e${{ github.run_id }}n${{ github.run_number }}r")]') + | jq '[.[] | select(.headBranch=="${{ steps.run-id.outputs.run-id }}")]') if [ $(echo "$output" | jq 'length') -eq 0 ] then @@ -165,7 +176,7 @@ jobs: -R ${{ secrets.E2E_TESTING_REPO }} \ -L 100 \ --json headBranch,conclusion \ - | jq '.[] | select(.headBranch=="e${{ github.run_id }}n${{ github.run_number }}r") | .conclusion') + | jq '.[] | select(.headBranch=="${{ steps.run-id.outputs.run-id }}") | .conclusion') if [[ $status != "completed" || $conclusion != "success" ]]; then echo "test workflow failed with status: $status, conclusion: $conclusion" From 1ea8a06f04eb5d9fadd1c013e118de350d21344d Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 18:46:17 +0800 Subject: [PATCH 067/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 34fae5c5c..e5e2b1d8b 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -87,9 +87,9 @@ jobs: id: run-id shell: python run: | - import random import os - import strings + import random + import string with open(os.environ['GITHUB_OUTPUT'], 'a') as f: run_id = "".join(random.choice(string.ascii_lowercase) for _ in range(8)) f.write(f"run-id={run_id}\n") From effcdb53e18ad4c089bff898ba03210d29c2b81d Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 19:02:38 +0800 Subject: [PATCH 068/113] test --- .github/workflows/start_e2e_test.yaml | 3 ++- src/runner.py | 4 +--- templates/pre-job.j2 | 4 +++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index e5e2b1d8b..4cef3217e 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -92,7 +92,7 @@ jobs: import string with open(os.environ['GITHUB_OUTPUT'], 'a') as f: run_id = "".join(random.choice(string.ascii_lowercase) for _ in range(8)) - f.write(f"run-id={run_id}\n") + f.write(f"run-id=e2e-{run_id}\n") - name: Deploy github-runner Charm run: | @@ -180,5 +180,6 @@ jobs: if [[ $status != "completed" || $conclusion != "success" ]]; then echo "test workflow failed with status: $status, conclusion: $conclusion" + exit 1 fi diff --git a/src/runner.py b/src/runner.py index 9374c9fe1..93e1eade0 100644 --- a/src/runner.py +++ b/src/runner.py @@ -238,9 +238,7 @@ def _ensure_runner_profile(self) -> None: """ if not self._clients.lxd.profiles.exists("runner"): logger.info("Creating runner LXD profile") - profile_config = { - "security.nesting": "true", - } + profile_config = {} if _LXD_PROFILE_YAML.exists(): additional_configs = yaml.safe_load(_LXD_PROFILE_YAML.read_text())["config"] profile_config.update({k: json.dumps(v) for k, v in additional_configs.items()}) diff --git a/templates/pre-job.j2 b/templates/pre-job.j2 index 90a9e48ca..58efe8c84 100644 --- a/templates/pre-job.j2 +++ b/templates/pre-job.j2 @@ -1,5 +1,6 @@ -#!/usr/bin/env python3 +#!/usr/bin/env bash +python3 - | << EOF import os import json import requests @@ -31,3 +32,4 @@ response = session.post("http://{{host_ip}}:8080/check-run", timeout=10, json={ "commit_sha": commit_sha }) response.raise_for_status() +EOF \ No newline at end of file From db551e87bb27ef4596c301aaa2c65588b31ea8a0 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 19:04:34 +0800 Subject: [PATCH 069/113] Update pre-job.j2 --- templates/pre-job.j2 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/templates/pre-job.j2 b/templates/pre-job.j2 index 58efe8c84..ef243103c 100644 --- a/templates/pre-job.j2 +++ b/templates/pre-job.j2 @@ -24,12 +24,14 @@ else: session = requests.session() session.headers["Authorization"] = "Bearer {{one_time_token}}" session.trust_env = False -response = session.post("http://{{host_ip}}:8080/check-run", timeout=10, json={ +payload = { "repository_name": repository_name, "source_repository_name": source_repository_name, "target_branch_name": target_branch_name, "source_branch_name": source_branch_name, "commit_sha": commit_sha -}) +} +print("repo policy compliance check with payload: {payload}") +response = session.post("http://{{host_ip}}:8080/check-run", timeout=10, json=payload) response.raise_for_status() EOF \ No newline at end of file From 03ee22a79255422d801168a552a6ff7f98bdc0d5 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 19:32:55 +0800 Subject: [PATCH 070/113] Update pre-job.j2 --- templates/pre-job.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/pre-job.j2 b/templates/pre-job.j2 index ef243103c..a7c6cbfc0 100644 --- a/templates/pre-job.j2 +++ b/templates/pre-job.j2 @@ -1,6 +1,6 @@ #!/usr/bin/env bash -python3 - | << EOF +python3 - << EOF import os import json import requests From 0a298e86fad893db9f2b985bac9ac2f5536e1a69 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 19:37:33 +0800 Subject: [PATCH 071/113] Update runner.py --- src/runner.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/runner.py b/src/runner.py index 93e1eade0..a1693a3e0 100644 --- a/src/runner.py +++ b/src/runner.py @@ -239,10 +239,12 @@ def _ensure_runner_profile(self) -> None: if not self._clients.lxd.profiles.exists("runner"): logger.info("Creating runner LXD profile") profile_config = {} + profile_devices = {} if _LXD_PROFILE_YAML.exists(): - additional_configs = yaml.safe_load(_LXD_PROFILE_YAML.read_text())["config"] - profile_config.update({k: json.dumps(v) for k, v in additional_configs.items()}) - self._clients.lxd.profiles.create("runner", profile_config, {}) + additional_lxc_profile = yaml.safe_load(_LXD_PROFILE_YAML.read_text()) + profile_config = {k: json.dumps(v) for k, v in additional_lxc_profile["config"].items()} + profile_devices = additional_lxc_profile["devices"] + self._clients.lxd.profiles.create("runner", profile_config, profile_devices) # Verify the action is successful. if not self._clients.lxd.profiles.exists("runner"): From e37d182529448d9896d6e908a490709ffb2bea22 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 19:59:02 +0800 Subject: [PATCH 072/113] Update pre-job.j2 --- templates/pre-job.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/pre-job.j2 b/templates/pre-job.j2 index a7c6cbfc0..535ca5464 100644 --- a/templates/pre-job.j2 +++ b/templates/pre-job.j2 @@ -31,7 +31,7 @@ payload = { "source_branch_name": source_branch_name, "commit_sha": commit_sha } -print("repo policy compliance check with payload: {payload}") +print(f"repo policy compliance check with payload: {payload}") response = session.post("http://{{host_ip}}:8080/check-run", timeout=10, json=payload) response.raise_for_status() EOF \ No newline at end of file From 3deb0037797dd964cebb85981678e57f93a2472c Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 20:25:04 +0800 Subject: [PATCH 073/113] Update pre-job.j2 --- templates/pre-job.j2 | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/pre-job.j2 b/templates/pre-job.j2 index 535ca5464..d5c2ea5ab 100644 --- a/templates/pre-job.j2 +++ b/templates/pre-job.j2 @@ -20,6 +20,7 @@ else: source_repository_name = os.environ["GITHUB_REPOSITORY"] target_branch_name = os.environ["GITHUB_REF"] source_branch_name = os.environ["GITHUB_REF"] + exit(0) session = requests.session() session.headers["Authorization"] = "Bearer {{one_time_token}}" From a97c8a845b505859a2a238e74e2e92d5f8559d20 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 20:37:59 +0800 Subject: [PATCH 074/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 28 ++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 4cef3217e..d2d291d3b 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -24,7 +24,33 @@ jobs: config: security.nesting: true security.privileged: true - raw.lxc: lxc.apparmor.profile=unconfined + linux.kernel_modules: ip_vs,ip_vs_rr,ip_vs_wrr,ip_vs_sh,ip_tables,ip6_tables,netlink_diag,nf_nat,overlay,br_netfilter + raw.lxc: | + lxc.apparmor.profile=unconfined + lxc.mount.auto=proc:rw sys:rw cgroup:rw + lxc.cgroup.devices.allow=a + lxc.cap.drop= + devices: + aadisable: + path: /sys/module/nf_conntrack/parameters/hashsize + source: /sys/module/nf_conntrack/parameters/hashsize + type: disk + aadisable2: + path: /dev/zfs + source: /dev/zfs + type: disk + aadisable3: + path: /dev/kmsg + source: /dev/kmsg + type: unix-char + aadisable4: + path: /sys/fs/bpf + source: /sys/fs/bpf + type: disk + aadisable5: + path: /proc/sys/net/netfilter/nf_conntrack_max + source: /proc/sys/net/netfilter/nf_conntrack_max + type: disk EOF - name: Cache github-runner Charm From 89b92749f6096d798f86220d2d24b67629cb34a1 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 21:51:39 +0800 Subject: [PATCH 075/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index d2d291d3b..37507ceb5 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -128,7 +128,8 @@ jobs: --base ubuntu@22.04 \ --config path=${{ secrets.E2E_TESTING_REPO }} \ --config token=${{ secrets.E2E_TESTING_TOKEN }} \ - --config virtual-machines=1 + --config virtual-machines=1 \ + --force - name: Install GitHub Cli run: which gh || sudo apt install gh -y From 23a820187855a8361e64cb832afa210cb7c04d1d Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 22:08:07 +0800 Subject: [PATCH 076/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 37507ceb5..4f3299763 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -24,33 +24,17 @@ jobs: config: security.nesting: true security.privileged: true - linux.kernel_modules: ip_vs,ip_vs_rr,ip_vs_wrr,ip_vs_sh,ip_tables,ip6_tables,netlink_diag,nf_nat,overlay,br_netfilter + linux.kernel_modules: ip_tables,ip6_tables,netlink_diag,nf_nat,overlay,br_netfilter raw.lxc: | lxc.apparmor.profile=unconfined lxc.mount.auto=proc:rw sys:rw cgroup:rw lxc.cgroup.devices.allow=a lxc.cap.drop= devices: - aadisable: - path: /sys/module/nf_conntrack/parameters/hashsize - source: /sys/module/nf_conntrack/parameters/hashsize - type: disk - aadisable2: - path: /dev/zfs - source: /dev/zfs - type: disk - aadisable3: + kmsg: path: /dev/kmsg source: /dev/kmsg type: unix-char - aadisable4: - path: /sys/fs/bpf - source: /sys/fs/bpf - type: disk - aadisable5: - path: /proc/sys/net/netfilter/nf_conntrack_max - source: /proc/sys/net/netfilter/nf_conntrack_max - type: disk EOF - name: Cache github-runner Charm From c49217726416cc5af08914815f7a3033fd71da98 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 22:40:26 +0800 Subject: [PATCH 077/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 4f3299763..ee2bf05a1 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -24,7 +24,6 @@ jobs: config: security.nesting: true security.privileged: true - linux.kernel_modules: ip_tables,ip6_tables,netlink_diag,nf_nat,overlay,br_netfilter raw.lxc: | lxc.apparmor.profile=unconfined lxc.mount.auto=proc:rw sys:rw cgroup:rw From 80d6d0775f18789747f39950b2d56c6842b0810b Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Sun, 18 Jun 2023 23:44:32 +0800 Subject: [PATCH 078/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index ee2bf05a1..17284696a 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -170,7 +170,7 @@ jobs: juju debug-log --replay --tail & - for i in {1..90} + for i in {1..360} do status=$(get-workflow-status) echo "workflow status: $status" From b056cc886d70474809f1efbca554903cafb81cc2 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 00:11:44 +0800 Subject: [PATCH 079/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 17284696a..15c755fe3 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -58,6 +58,7 @@ jobs: path: github-runner_ubuntu-22.04-amd64.charm deploy-e2e-test-runner: + name: Deploy End-to-End Testing Runner runs-on: ubuntu-latest needs: build-charm steps: From 08e1f545e9c30369c6550addab21f6956fb4903a Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 00:33:48 +0800 Subject: [PATCH 080/113] Update end_to_end_test.yaml --- .github/workflows/end_to_end_test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/end_to_end_test.yaml b/.github/workflows/end_to_end_test.yaml index f8e21e184..b97db036d 100644 --- a/.github/workflows/end_to_end_test.yaml +++ b/.github/workflows/end_to_end_test.yaml @@ -1,5 +1,6 @@ name: End to end tests + on: workflow_call: inputs: From 83b7a80b7b6d9f85a6b11d595b765d34d8662fa1 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 10:34:31 +0800 Subject: [PATCH 081/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 15c755fe3..fe0e7df11 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -118,6 +118,9 @@ jobs: - name: Install GitHub Cli run: which gh || sudo apt install gh -y + - name: Setup tmate session + uses: mxschmitt/action-tmate@v3 + - name: Dispatch Workflow on Testing Runner env: GH_TOKEN: ${{ secrets.E2E_TESTING_TOKEN }} From 0797e72e672b7d0b8c25383223755754e37b9c1e Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 11:14:44 +0800 Subject: [PATCH 082/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index fe0e7df11..3e388c7ab 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -69,8 +69,6 @@ jobs: sudo lxd init --auto sudo chmod a+wr /var/snap/lxd/common/lxd/unix.socket sudo lxc network set lxdbr0 ipv6.address none - sudo lxc storage create default-btrfs btrfs size=50GiB - sudo lxc profile device set default root pool=default-btrfs sudo iptables -F FORWARD sudo iptables -P FORWARD ACCEPT @@ -118,8 +116,8 @@ jobs: - name: Install GitHub Cli run: which gh || sudo apt install gh -y - - name: Setup tmate session - uses: mxschmitt/action-tmate@v3 +# - name: Setup tmate session +# uses: mxschmitt/action-tmate@v3 - name: Dispatch Workflow on Testing Runner env: From 24038228cc4a5cac5c17f75cb6014fc1a2aed752 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 11:34:57 +0800 Subject: [PATCH 083/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 3e388c7ab..24151ea84 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -116,8 +116,8 @@ jobs: - name: Install GitHub Cli run: which gh || sudo apt install gh -y -# - name: Setup tmate session -# uses: mxschmitt/action-tmate@v3 + - name: Setup tmate session + uses: mxschmitt/action-tmate@v3 - name: Dispatch Workflow on Testing Runner env: From 759fd31fe4bcb4a013cc9dcc5f56f24f283642a2 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 11:35:47 +0800 Subject: [PATCH 084/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 24151ea84..93fb2ae99 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -6,7 +6,7 @@ on: jobs: build-charm: name: Build Charm - runs-on: ubuntu-latest + runs-on: [self-hosted, linux, x64, e2e-test] steps: - uses: actions/checkout@v3 @@ -116,8 +116,8 @@ jobs: - name: Install GitHub Cli run: which gh || sudo apt install gh -y - - name: Setup tmate session - uses: mxschmitt/action-tmate@v3 +# - name: Setup tmate session +# uses: mxschmitt/action-tmate@v3 - name: Dispatch Workflow on Testing Runner env: From ce51b49e840950a9b98b5e4a0b4b91764a4060ac Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 11:38:53 +0800 Subject: [PATCH 085/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 93fb2ae99..1c67b3d9a 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -86,6 +86,12 @@ jobs: - name: Create Testing Juju Model run: juju add-model testing + - name: Set Testing Model Proxy Configuration + run: | + [[ -z $http_proxy ]] || juju model-config juju-http-proxy=$http_proxy + [[ -z $https_proxy ]] || juju model-config juju-https-proxy=$https_proxy + [[ -z no_proxy ]] ||juju model-config juju-no-proxy=$no_proxy + - name: Download github-runner Charm uses: actions/download-artifact@v3 with: From 1bc7da6a9ac44ea1b49755e065b3318033e97b2a Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 11:39:26 +0800 Subject: [PATCH 086/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 1c67b3d9a..9b9c90609 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -90,7 +90,7 @@ jobs: run: | [[ -z $http_proxy ]] || juju model-config juju-http-proxy=$http_proxy [[ -z $https_proxy ]] || juju model-config juju-https-proxy=$https_proxy - [[ -z no_proxy ]] ||juju model-config juju-no-proxy=$no_proxy + [[ -z $no_proxy ]] ||juju model-config juju-no-proxy=$no_proxy - name: Download github-runner Charm uses: actions/download-artifact@v3 From 0cf96fdc94cfc4319d67b36f9746902055a47cc7 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 11:49:26 +0800 Subject: [PATCH 087/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 9b9c90609..ddb982b1d 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -6,7 +6,7 @@ on: jobs: build-charm: name: Build Charm - runs-on: [self-hosted, linux, x64, e2e-test] + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -59,7 +59,7 @@ jobs: deploy-e2e-test-runner: name: Deploy End-to-End Testing Runner - runs-on: ubuntu-latest + runs-on: [self-hosted, linux, x64, e2e-test] needs: build-charm steps: - name: Initialize LXD From 8651647a25ef7500b5c51431bb71ba50bdec6acc Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 12:10:11 +0800 Subject: [PATCH 088/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 55 ++++++++++++++++----------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index ddb982b1d..6690201d5 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -62,29 +62,35 @@ jobs: runs-on: [self-hosted, linux, x64, e2e-test] needs: build-charm steps: - - name: Initialize LXD - run: | - sudo snap refresh lxd --channel=latest/stable - sudo lxd waitready - sudo lxd init --auto - sudo chmod a+wr /var/snap/lxd/common/lxd/unix.socket - sudo lxc network set lxdbr0 ipv6.address none - sudo iptables -F FORWARD - sudo iptables -P FORWARD ACCEPT - - - name: Install Juju - run: sudo snap install juju --classic --channel=3.1/stable - - - name: Bootstrap Juju LXD Controller - run: | - juju bootstrap --debug --verbose lxd \ - --model-default test-mode=true \ - --model-default automatically-retry-hooks=false \ - --model-default logging-config="=DEBUG" \ - --bootstrap-constraints="cores=2 mem=4G" - - - name: Create Testing Juju Model - run: juju add-model testing +# - name: Initialize LXD +# run: | +# sudo snap refresh lxd --channel=latest/stable +# sudo lxd waitready +# sudo lxd init --auto +# sudo chmod a+wr /var/snap/lxd/common/lxd/unix.socket +# sudo lxc network set lxdbr0 ipv6.address none +# sudo iptables -F FORWARD +# sudo iptables -P FORWARD ACCEPT +# +# - name: Install Juju +# run: sudo snap install juju --classic --channel=3.1/stable +# +# - name: Bootstrap Juju LXD Controller +# run: | +# juju bootstrap --debug --verbose lxd \ +# --model-default test-mode=true \ +# --model-default automatically-retry-hooks=false \ +# --model-default logging-config="=DEBUG" \ +# --bootstrap-constraints="cores=2 mem=4G" +# +# - name: Create Testing Juju Model +# run: juju add-model testing + + - name: Setup Lxd Juju Controller + uses: charmed-kubernetes/actions-operator@main + with: + juju-channel: 3.1/stable + provider: lxd - name: Set Testing Model Proxy Configuration run: | @@ -92,6 +98,9 @@ jobs: [[ -z $https_proxy ]] || juju model-config juju-https-proxy=$https_proxy [[ -z $no_proxy ]] ||juju model-config juju-no-proxy=$no_proxy + - name: Change Testing Model Logging Level + run: juju model-config logging-config="=INFO;unit=DEBUG" + - name: Download github-runner Charm uses: actions/download-artifact@v3 with: From bcfc2eb2260d4e7dc3a79dd40ae9b5e32c2b52fb Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 12:24:45 +0800 Subject: [PATCH 089/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 6690201d5..4e9726009 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -92,6 +92,9 @@ jobs: juju-channel: 3.1/stable provider: lxd + - name: Create Testing Juju Model + run: juju add-model testing + - name: Set Testing Model Proxy Configuration run: | [[ -z $http_proxy ]] || juju model-config juju-http-proxy=$http_proxy From 1f69f96b06f21c618a80164dd71a47b201325155 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 12:47:30 +0800 Subject: [PATCH 090/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 4e9726009..aeb2bada5 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -111,14 +111,8 @@ jobs: - name: Generate Run ID id: run-id - shell: python run: | - import os - import random - import string - with open(os.environ['GITHUB_OUTPUT'], 'a') as f: - run_id = "".join(random.choice(string.ascii_lowercase) for _ in range(8)) - f.write(f"run-id=e2e-{run_id}\n") + echo "run-id=e2e-$(LC_ALL=C tr -dc 'a-z' < /dev/urandom | head -c8)" >> $GITHUB_OUTPUT - name: Deploy github-runner Charm run: | From 618590ba1c7fab1df71e6c70ead5f62f58afdb5b Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 13:01:21 +0800 Subject: [PATCH 091/113] Update pre-job.j2 --- templates/pre-job.j2 | 37 ------------------------------------- 1 file changed, 37 deletions(-) diff --git a/templates/pre-job.j2 b/templates/pre-job.j2 index d5c2ea5ab..f1f641af1 100644 --- a/templates/pre-job.j2 +++ b/templates/pre-job.j2 @@ -1,38 +1 @@ #!/usr/bin/env bash - -python3 - << EOF -import os -import json -import requests - -event_name = os.environ["GITHUB_EVENT_NAME"] -if event_name not in ("pull_request", "workflow_dispatch"): - raise ValueError(f"github event {event_name} is not supported") -commit_sha = os.environ["GITHUB_SHA"] -repository_name = os.environ["GITHUB_REPOSITORY"] -if event_name == "pull_request": - event_path = os.environ["GITHUB_EVENT_PATH"] - with open(event_path) as fo: - source_repository_name = json.load(fo)["pull_request"]["head"]["repo"]["full_name"] - target_branch_name = os.environ["GITHUB_BASE_REF"] - source_branch_name = os.environ["GITHUB_HEAD_REF"] -else: - source_repository_name = os.environ["GITHUB_REPOSITORY"] - target_branch_name = os.environ["GITHUB_REF"] - source_branch_name = os.environ["GITHUB_REF"] - exit(0) - -session = requests.session() -session.headers["Authorization"] = "Bearer {{one_time_token}}" -session.trust_env = False -payload = { - "repository_name": repository_name, - "source_repository_name": source_repository_name, - "target_branch_name": target_branch_name, - "source_branch_name": source_branch_name, - "commit_sha": commit_sha -} -print(f"repo policy compliance check with payload: {payload}") -response = session.post("http://{{host_ip}}:8080/check-run", timeout=10, json=payload) -response.raise_for_status() -EOF \ No newline at end of file From 81fc6b2a899f7ed87acd4130a9cfa1e952bdd26e Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 13:38:46 +0800 Subject: [PATCH 092/113] Use the main repo for testing --- .github/workflows/start_e2e_test.yaml | 186 +++++++++++--------------- 1 file changed, 79 insertions(+), 107 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index aeb2bada5..e74b20c29 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -57,35 +57,22 @@ jobs: name: github-runner_ubuntu-22.04-amd64.charm path: github-runner_ubuntu-22.04-amd64.charm - deploy-e2e-test-runner: - name: Deploy End-to-End Testing Runner - runs-on: [self-hosted, linux, x64, e2e-test] - needs: build-charm + run-id: + name: Generate Run ID + runs-on: ubuntu-latest + outputs: + run-id: ${{ steps.run-id.outputs.run-id }} steps: -# - name: Initialize LXD -# run: | -# sudo snap refresh lxd --channel=latest/stable -# sudo lxd waitready -# sudo lxd init --auto -# sudo chmod a+wr /var/snap/lxd/common/lxd/unix.socket -# sudo lxc network set lxdbr0 ipv6.address none -# sudo iptables -F FORWARD -# sudo iptables -P FORWARD ACCEPT -# -# - name: Install Juju -# run: sudo snap install juju --classic --channel=3.1/stable -# -# - name: Bootstrap Juju LXD Controller -# run: | -# juju bootstrap --debug --verbose lxd \ -# --model-default test-mode=true \ -# --model-default automatically-retry-hooks=false \ -# --model-default logging-config="=DEBUG" \ -# --bootstrap-constraints="cores=2 mem=4G" -# -# - name: Create Testing Juju Model -# run: juju add-model testing + - name: Generate Run ID + id: run-id + run: | + echo "run-id=e2e-$(LC_ALL=C tr -dc 'a-z' < /dev/urandom | head -c8)" >> $GITHUB_OUTPUT + deploy-e2e-test-runner: + name: Deploy End-to-End Test Runner + runs-on: [ self-hosted, linux, x64, e2e-test ] + needs: [ build-charm, run-id ] + steps: - name: Setup Lxd Juju Controller uses: charmed-kubernetes/actions-operator@main with: @@ -97,9 +84,9 @@ jobs: - name: Set Testing Model Proxy Configuration run: | - [[ -z $http_proxy ]] || juju model-config juju-http-proxy=$http_proxy - [[ -z $https_proxy ]] || juju model-config juju-https-proxy=$https_proxy - [[ -z $no_proxy ]] ||juju model-config juju-no-proxy=$no_proxy + juju model-config juju-http-proxy=$http_proxy + juju model-config juju-https-proxy=$https_proxy + juju model-config juju-no-proxy=$no_proxy - name: Change Testing Model Logging Level run: juju model-config logging-config="=INFO;unit=DEBUG" @@ -109,101 +96,86 @@ jobs: with: name: github-runner_ubuntu-22.04-amd64.charm - - name: Generate Run ID - id: run-id - run: | - echo "run-id=e2e-$(LC_ALL=C tr -dc 'a-z' < /dev/urandom | head -c8)" >> $GITHUB_OUTPUT - - name: Deploy github-runner Charm run: | cp github-runner_ubuntu-22.04-amd64.charm /home/$USER/github-runner_ubuntu-22.04-amd64.charm juju deploy /home/$USER/github-runner_ubuntu-22.04-amd64.charm \ - ${{ steps.run-id.outputs.run-id }} \ + ${{ needs.run-id.outputs.run-id }} \ --base ubuntu@22.04 \ --config path=${{ secrets.E2E_TESTING_REPO }} \ --config token=${{ secrets.E2E_TESTING_TOKEN }} \ --config virtual-machines=1 \ + --config vm-cpu=4 \ + --config vm-memory=16GiB \ --force - name: Install GitHub Cli run: which gh || sudo apt install gh -y -# - name: Setup tmate session -# uses: mxschmitt/action-tmate@v3 - - - name: Dispatch Workflow on Testing Runner - env: - GH_TOKEN: ${{ secrets.E2E_TESTING_TOKEN }} + - name: Watch github-runner run: | - MAIN_SHA=$(gh api \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - /repos/${{ secrets.E2E_TESTING_REPO }}/git/ref/heads/main --jq .object.sha) - gh api \ - --method POST \ -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ - /repos/${{ secrets.E2E_TESTING_REPO }}/git/refs \ - -f ref='refs/heads/${{ steps.run-id.outputs.run-id }}' \ - -f sha=$MAIN_SHA + /repos/${{ secrets.E2E_TESTING_REPO }}/actions/runs/$GITHUB_RUN_ID/attempts/$GITHUB_RUN_ATTEMPT/jobs - gh workflow run test.yaml \ - -R ${{ secrets.E2E_TESTING_REPO }} \ - --ref ${{ steps.run-id.outputs.run-id }} \ - -f runner=${{ steps.run-id.outputs.run-id }} - - sleep 5 + juju debug-log --replay --tail - - name: Watch github-runner - env: - GH_TOKEN: ${{ secrets.E2E_TESTING_TOKEN }} + + e2e-test: + name: End-to-End Test + needs: [ build-charm, run-id ] + runs-on: [ self-hosted, linux, x64, "${{ needs.run-id.outputs.run-id }}" ] + steps: + - name: Echo hello world + run: echo "hello world" + - name: File permission for /usr/local/bin + run: ls -ld /usr/local/bin | grep drwxrwxrwx + - name: Test file permission for /usr/local/bin + run: touch /usr/local/bin/test_file + # "Install microk8s" step will test if the proxies settings are correct. + - name: Proxy set in /etc/environment + run: cat /etc/environment | grep HTTP_PROXY + # "Update apt in python docker container" step will test docker default proxy settings due to + # pulling the python image. + - name: Proxy set in docker daemon + run: | + [[ -z "${http_proxy}" && -z "${HTTP_PROXY}" ]] \ + || sudo cat /etc/systemd/system/docker.service.d/http-proxy.conf | grep HTTP_PROXY + # "Update apt in python docker container" step will test docker client default proxy settings. + - name: Proxy set in docker client + run: | + [[ -z "${http_proxy}" && -z "${HTTP_PROXY}" ]] \ + || cat /home/ubuntu/.docker/config.json | grep httpProxy + - name: Install microk8s + run: sudo snap install microk8s --classic + - name: Wait for microk8s run: | - gh run list \ - -R ${{ secrets.E2E_TESTING_REPO }} \ - -L 100 \ - --json headBranch,status,workflowDatabaseId,conclusion \ - | jq '.[] | select(.headBranch=="${{ steps.run-id.outputs.run-id }}")' - - get-workflow-status() { - output=$(gh run list \ - -R ${{ secrets.E2E_TESTING_REPO }} \ - -L 100 \ - --json headBranch,status \ - | jq '[.[] | select(.headBranch=="${{ steps.run-id.outputs.run-id }}")]') - - if [ $(echo "$output" | jq 'length') -eq 0 ] - then - echo "not_started" - else - # Parse output with jq to get the status field of the first object - status=$(echo "$output" | jq -r '.[0].status') - echo "$status" - fi - } - - juju debug-log --replay --tail & - - for i in {1..360} - do - status=$(get-workflow-status) - echo "workflow status: $status" - if [[ $status != "not-started" && $status != "queued" && $status != "in_progress" ]]; then - break - fi - sleep 10 + while :; do + sudo timeout 60 microk8s status --wait-ready \ + && break \ + || sudo microk8s kubectl get pods --all-namespaces || : done - - kill $(jobs -p) - - conclusion=$(gh run list \ - -R ${{ secrets.E2E_TESTING_REPO }} \ - -L 100 \ - --json headBranch,conclusion \ - | jq '.[] | select(.headBranch=="${{ steps.run-id.outputs.run-id }}") | .conclusion') - - if [[ $status != "completed" || $conclusion != "success" ]]; then - echo "test workflow failed with status: $status, conclusion: $conclusion" - - exit 1 - fi + - name: Deploy nginx for testing + run: sudo microk8s kubectl create deployment nginx --image=nginx + - name: Wait for nginx to be ready + run: sudo microk8s kubectl rollout status deployment/nginx --timeout=30m + - name: Update apt in python docker container + run: docker run python:3.10-slim apt update + - name: Docker version + run: docker version + - name: pip version + run: python3 -m pip --version + - name: npm version + run: npm --version + - name: shellcheck version + run: shellcheck --version + - name: jq version + run: jq --version + - name: yq version + run: yq --version + - name: install check-jsonschema + run: python3 -m pip install check-jsonschema + # Test program installed by pip. The directory `~/.local/bin` need to be added to PATH. + - name: test check-jsonschema + run: check-jsonschema --version From 1a8546574cf9db5c741fba3f905c85f2ef6708f9 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 13:44:51 +0800 Subject: [PATCH 093/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index e74b20c29..b0bdd7559 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -113,6 +113,8 @@ jobs: run: which gh || sudo apt install gh -y - name: Watch github-runner + env: + GH_TOKEN: ${{ secrets.E2E_TESTING_TOKEN }} run: | gh api \ -H "Accept: application/vnd.github+json" \ From 49ce2635fb500cca46da086d8004171537063857 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 13:54:01 +0800 Subject: [PATCH 094/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index b0bdd7559..fe62c1483 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -73,6 +73,18 @@ jobs: runs-on: [ self-hosted, linux, x64, e2e-test ] needs: [ build-charm, run-id ] steps: + - name: Install GitHub Cli + run: which gh || sudo apt install gh -y + + - name: Watch github-runner + env: + GH_TOKEN: ${{ secrets.E2E_TESTING_TOKEN }} + run: | + gh api \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + /repos/${{ secrets.E2E_TESTING_REPO }}/actions/runs/$GITHUB_RUN_ID/attempts/$GITHUB_RUN_ATTEMPT/jobs + - name: Setup Lxd Juju Controller uses: charmed-kubernetes/actions-operator@main with: @@ -113,8 +125,6 @@ jobs: run: which gh || sudo apt install gh -y - name: Watch github-runner - env: - GH_TOKEN: ${{ secrets.E2E_TESTING_TOKEN }} run: | gh api \ -H "Accept: application/vnd.github+json" \ From 632993264dabee7e5732f6c4b891c3f0fb4b6b10 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 13:58:44 +0800 Subject: [PATCH 095/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index fe62c1483..8840df2c4 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -15,9 +15,6 @@ jobs: rm -rf .git rm -rf .github - - name: Setup LXD - uses: canonical/setup-lxd@main - - name: Write lxd-profile.yaml run: | cat << EOF > ./lxd-profile.yaml @@ -43,6 +40,10 @@ jobs: path: github-runner_ubuntu-22.04-amd64.charm key: github-runner-charm-${{ hashFiles('**/*') }} + - name: Setup LXD + if: steps.cache-charm.outputs.cache-hit != 'true' + uses: canonical/setup-lxd@main + - name: Install charmcraft if: steps.cache-charm.outputs.cache-hit != 'true' run: sudo snap install charmcraft --classic From 85257a33700021df2b7d6155d50f11e98aef2455 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 14:10:14 +0800 Subject: [PATCH 096/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 36 +++++++++++++-------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 8840df2c4..e04e7455f 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -74,18 +74,6 @@ jobs: runs-on: [ self-hosted, linux, x64, e2e-test ] needs: [ build-charm, run-id ] steps: - - name: Install GitHub Cli - run: which gh || sudo apt install gh -y - - - name: Watch github-runner - env: - GH_TOKEN: ${{ secrets.E2E_TESTING_TOKEN }} - run: | - gh api \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - /repos/${{ secrets.E2E_TESTING_REPO }}/actions/runs/$GITHUB_RUN_ID/attempts/$GITHUB_RUN_ATTEMPT/jobs - - name: Setup Lxd Juju Controller uses: charmed-kubernetes/actions-operator@main with: @@ -126,15 +114,27 @@ jobs: run: which gh || sudo apt install gh -y - name: Watch github-runner + env: + GH_TOKEN: ${{ secrets.E2E_TESTING_TOKEN }} run: | - gh api \ + juju debug-log --replay --tail & + + while :; do + JOBS=$(gh api \ -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ - /repos/${{ secrets.E2E_TESTING_REPO }}/actions/runs/$GITHUB_RUN_ID/attempts/$GITHUB_RUN_ATTEMPT/jobs - - juju debug-log --replay --tail - - + /repos/${{ secrets.E2E_TESTING_REPO }}/actions/runs/$GITHUB_RUN_ID/attempts/$GITHUB_RUN_ATTEMPT/jobs) + CONCLUSION=$(echo $JOBS | jq -r '.jobs[] | select(.name == "End-to-End Test") | .conclusion') + STATUS=$(echo $JOBS | jq -r '.jobs[] | select(.name == "End-to-End Test") | .status') + if [[ $status != "queued" && $status != "in_progress" ]]; then + break + fi + done + if [[ $STATUS != "completed" || $CONCLUSION != "success" ]]; then + echo "test workflow failed with status: $STATUS, conclusion: $CONCLUSION" + exit 1 + fi + e2e-test: name: End-to-End Test needs: [ build-charm, run-id ] From a0aca04f812a2417227efd0c1ba43763d4b2489f Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 14:15:48 +0800 Subject: [PATCH 097/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index e04e7455f..36409c3a0 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -126,7 +126,7 @@ jobs: /repos/${{ secrets.E2E_TESTING_REPO }}/actions/runs/$GITHUB_RUN_ID/attempts/$GITHUB_RUN_ATTEMPT/jobs) CONCLUSION=$(echo $JOBS | jq -r '.jobs[] | select(.name == "End-to-End Test") | .conclusion') STATUS=$(echo $JOBS | jq -r '.jobs[] | select(.name == "End-to-End Test") | .status') - if [[ $status != "queued" && $status != "in_progress" ]]; then + if [[ $STATUS != "queued" && $STATUS != "in_progress" ]]; then break fi done @@ -134,7 +134,7 @@ jobs: echo "test workflow failed with status: $STATUS, conclusion: $CONCLUSION" exit 1 fi - + e2e-test: name: End-to-End Test needs: [ build-charm, run-id ] From f15347d14e5c733b952edc7c442d5e743adde19d Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 14:41:21 +0800 Subject: [PATCH 098/113] test --- .github/workflows/start_e2e_test.yaml | 3 ++- src/runner_manager.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 36409c3a0..304ae7f88 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -131,7 +131,8 @@ jobs: fi done if [[ $STATUS != "completed" || $CONCLUSION != "success" ]]; then - echo "test workflow failed with status: $STATUS, conclusion: $CONCLUSION" + echo "test workflow failed with status: $STATUS, conclusion: $CONCLUSION" + kill $(jobs -p) exit 1 fi diff --git a/src/runner_manager.py b/src/runner_manager.py index 01b2f37ce..158f82861 100644 --- a/src/runner_manager.py +++ b/src/runner_manager.py @@ -123,6 +123,7 @@ def __init__( local_session = requests.Session() local_session.mount("http://", adapter) local_session.mount("https://", adapter) + local_session.trust_env = False self._clients = RunnerClients( GhApi(token=self.config.token), From 0d9c930d2a0b0e4b72622c77ed3db6cb771d2d70 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 15:59:44 +0800 Subject: [PATCH 099/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 304ae7f88..24d6029e9 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -74,6 +74,12 @@ jobs: runs-on: [ self-hosted, linux, x64, e2e-test ] needs: [ build-charm, run-id ] steps: + - name: Enable Kernel Modules + run: | + for m in ip_tables ip6_tables nf_nat overlay br_netfilter; do + sudo modprobe $m; + done + - name: Setup Lxd Juju Controller uses: charmed-kubernetes/actions-operator@main with: From ae6a058a995d0fabff214c86f00c7bd362794daa Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 16:31:17 +0800 Subject: [PATCH 100/113] test --- .github/workflows/start_e2e_test.yaml | 2 +- src/charm.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 24d6029e9..c80a315af 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -155,7 +155,7 @@ jobs: run: touch /usr/local/bin/test_file # "Install microk8s" step will test if the proxies settings are correct. - name: Proxy set in /etc/environment - run: cat /etc/environment | grep HTTP_PROXY + run: cat /etc/environment # "Update apt in python docker container" step will test docker default proxy settings due to # pulling the python image. - name: Proxy set in docker daemon diff --git a/src/charm.py b/src/charm.py index 8e40a8155..b91774b9c 100755 --- a/src/charm.py +++ b/src/charm.py @@ -136,7 +136,8 @@ def __init__(self, *args, **kargs) -> None: if https_proxy := get_env_var("JUJU_CHARM_HTTPS_PROXY"): self.proxies["https"] = https_proxy # there's no need for no_proxy if there's no http_proxy or https_proxy - if no_proxy := get_env_var("JUJU_CHARM_NO_PROXY") and (https_proxy or http_proxy): + no_proxy = get_env_var("JUJU_CHARM_NO_PROXY") + if (https_proxy or http_proxy) and no_proxy: self.proxies["no_proxy"] = no_proxy self.service_token = None From 56fa74086f1964ef07d11faae2324372d3168f28 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 16:43:02 +0800 Subject: [PATCH 101/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index c80a315af..1c12901d3 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -121,7 +121,7 @@ jobs: - name: Watch github-runner env: - GH_TOKEN: ${{ secrets.E2E_TESTING_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | juju debug-log --replay --tail & @@ -135,6 +135,7 @@ jobs: if [[ $STATUS != "queued" && $STATUS != "in_progress" ]]; then break fi + sleep 10 done if [[ $STATUS != "completed" || $CONCLUSION != "success" ]]; then echo "test workflow failed with status: $STATUS, conclusion: $CONCLUSION" From 5cb89f6447768558c546287f6eb96c8b236dd75b Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 17:38:17 +0800 Subject: [PATCH 102/113] Update runner.py --- src/runner.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/runner.py b/src/runner.py index a1693a3e0..a6e88a45e 100644 --- a/src/runner.py +++ b/src/runner.py @@ -242,7 +242,10 @@ def _ensure_runner_profile(self) -> None: profile_devices = {} if _LXD_PROFILE_YAML.exists(): additional_lxc_profile = yaml.safe_load(_LXD_PROFILE_YAML.read_text()) - profile_config = {k: json.dumps(v) for k, v in additional_lxc_profile["config"].items()} + profile_config = { + k: json.dumps(v) if isinstance(v, bool) else v + for k, v in additional_lxc_profile["config"].items() + } profile_devices = additional_lxc_profile["devices"] self._clients.lxd.profiles.create("runner", profile_config, profile_devices) From 6f6bcd34331190e011ea3108397faa10674bbd2c Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 18:04:47 +0800 Subject: [PATCH 103/113] Update start_e2e_test.yaml --- .github/workflows/start_e2e_test.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/start_e2e_test.yaml index 1c12901d3..0e74948e2 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/start_e2e_test.yaml @@ -71,7 +71,7 @@ jobs: deploy-e2e-test-runner: name: Deploy End-to-End Test Runner - runs-on: [ self-hosted, linux, x64, e2e-test ] + runs-on: ubuntu-latest needs: [ build-charm, run-id ] steps: - name: Enable Kernel Modules @@ -112,8 +112,6 @@ jobs: --config path=${{ secrets.E2E_TESTING_REPO }} \ --config token=${{ secrets.E2E_TESTING_TOKEN }} \ --config virtual-machines=1 \ - --config vm-cpu=4 \ - --config vm-memory=16GiB \ --force - name: Install GitHub Cli From 5bfec9c5d54a6303c07f5225406eaf495e55ee1f Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 18:40:06 +0800 Subject: [PATCH 104/113] test --- .github/workflows/build_charm.yaml | 32 --------- .../{start_e2e_test.yaml => e2e_test.yaml} | 18 ++--- .github/workflows/end_to_end_test.yaml | 67 ------------------- .github/workflows/test.yaml | 4 +- src/lxd.py | 6 +- src/runner.py | 30 +++++---- src/runner_manager.py | 18 ++--- 7 files changed, 37 insertions(+), 138 deletions(-) delete mode 100644 .github/workflows/build_charm.yaml rename .github/workflows/{start_e2e_test.yaml => e2e_test.yaml} (95%) delete mode 100644 .github/workflows/end_to_end_test.yaml diff --git a/.github/workflows/build_charm.yaml b/.github/workflows/build_charm.yaml deleted file mode 100644 index 13584e64c..000000000 --- a/.github/workflows/build_charm.yaml +++ /dev/null @@ -1,32 +0,0 @@ -name: Build charm - -on: -# pull_request: - workflow_call: - workflow_dispatch: - -jobs: - get-runner-image: - name: Get runner image - uses: canonical/operator-workflows/.github/workflows/get_runner_image.yaml@main - build-charm: - name: Build the charm - needs: get-runner-image - runs-on: ${{ needs.get-runner-image.outputs.runs-on }} - steps: - - uses: actions/checkout@v3 - - name: Enable network in LXD - run: sudo iptables -I DOCKER-USER -j ACCEPT - - name: Add user to lxd group - run: sudo adduser runner lxd - - name: Initialize LXD - run: sudo -u runner lxd init --auto - - name: Install charmcraft - run: sudo snap install charmcraft --classic - - name: Pack charm - run: sudo -u runner charmcraft pack - - uses: actions/upload-artifact@v3 - with: - name: github-runner-charm - path: github-runner_*.charm - retention-days: 5 diff --git a/.github/workflows/start_e2e_test.yaml b/.github/workflows/e2e_test.yaml similarity index 95% rename from .github/workflows/start_e2e_test.yaml rename to .github/workflows/e2e_test.yaml index 0e74948e2..0da22bcbc 100644 --- a/.github/workflows/start_e2e_test.yaml +++ b/.github/workflows/e2e_test.yaml @@ -55,7 +55,7 @@ jobs: - name: Upload github-runner Charm uses: actions/upload-artifact@v3 with: - name: github-runner_ubuntu-22.04-amd64.charm + name: danger-test-only-github-runner_ubuntu-22.04-amd64.charm path: github-runner_ubuntu-22.04-amd64.charm run-id: @@ -74,18 +74,15 @@ jobs: runs-on: ubuntu-latest needs: [ build-charm, run-id ] steps: - - name: Enable Kernel Modules - run: | - for m in ip_tables ip6_tables nf_nat overlay br_netfilter; do - sudo modprobe $m; - done - - name: Setup Lxd Juju Controller uses: charmed-kubernetes/actions-operator@main with: juju-channel: 3.1/stable provider: lxd + - name: Install GitHub Cli + run: which gh || sudo apt install gh -y + - name: Create Testing Juju Model run: juju add-model testing @@ -101,7 +98,7 @@ jobs: - name: Download github-runner Charm uses: actions/download-artifact@v3 with: - name: github-runner_ubuntu-22.04-amd64.charm + name: danger-test-only-github-runner_ubuntu-22.04-amd64.charm - name: Deploy github-runner Charm run: | @@ -112,14 +109,11 @@ jobs: --config path=${{ secrets.E2E_TESTING_REPO }} \ --config token=${{ secrets.E2E_TESTING_TOKEN }} \ --config virtual-machines=1 \ - --force - - - name: Install GitHub Cli - run: which gh || sudo apt install gh -y - name: Watch github-runner env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + timeout-minutes: 30 run: | juju debug-log --replay --tail & diff --git a/.github/workflows/end_to_end_test.yaml b/.github/workflows/end_to_end_test.yaml deleted file mode 100644 index b97db036d..000000000 --- a/.github/workflows/end_to_end_test.yaml +++ /dev/null @@ -1,67 +0,0 @@ -name: End to end tests - - -on: - workflow_call: - inputs: - test-runner: - required: true - workflow_dispatch: - inputs: - test-runner: - required: true - -jobs: - e2e-test: - name: end to end test - runs-on: [self-hosted, linux, x64, ${{ test-runner }}] - steps: - - name: Echo hello world - run: echo "hello world" - - name: File permission for /usr/local/bin - run: ls -ld /usr/local/bin | grep drwxrwxrwx - - name: Test file permission for /usr/local/bin - run: touch /usr/local/bin/test_file - # "Install microk8s" step will test if the proxies settings are correct. - - name: Proxy set in /etc/environment - run: cat /etc/environment | grep HTTP_PROXY - # "Update apt in python docker container" step will test docker default proxy settings due to - # pulling the python image. - - name: Proxy set in docker daemon - run: sudo cat /etc/systemd/system/docker.service.d/http-proxy.conf | grep HTTP_PROXY - # "Update apt in python docker container" step will test docker client default proxy settings. - - name: Proxy set in docker client - run: cat /home/ubuntu/.docker/config.json | grep httpProxy - - name: Install microk8s - run: sudo snap install microk8s --classic - - name: Wait for microk8s - run: sudo microk8s status --wait-ready - - name: Deploy nginx for testing - run: sudo microk8s kubectl create deployment nginx --image=nginx - - name: Wait for nginx to be ready - run: sudo microk8s kubectl rollout status deployment/nginx --timeout=30m - - name: Update apt in python docker container - run: docker run python:3.10-slim apt update - dep-test: - # Test the dependencies in one job to avoid using too many runners at once. - name: dependency test - needs: e2e-test - runs-on: [self-hosted, linux, x64, e2e-runner] - steps: - - name: Docker version - run: docker version - - name: pip version - run: python3 -m pip --version - - name: npm version - run: npm --version - - name: shellcheck version - run: shellcheck --version - - name: jq version - run: jq --version - - name: yq version - run: yq --version - - name: install check-jsonschema - run: python3 -m pip install check-jsonschema - # Test program installed by pip. The directory `~/.local/bin` need to be added to PATH. - - name: test check-jsonschema - run: check-jsonschema --version diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 672005ade..fcffaca11 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,7 +1,7 @@ name: Tests -on: {} -# pull_request: +on: + pull_request: { } jobs: unit-tests: diff --git a/src/lxd.py b/src/lxd.py index 0896bda56..9b15008ae 100644 --- a/src/lxd.py +++ b/src/lxd.py @@ -54,13 +54,15 @@ def mk_dir(self, dir_name: str) -> None: "--", "/usr/bin/mkdir", "-p", - dir_name + dir_name, ] try: execute_command(lxc_command) except SubprocessError as err: logger.exception("Failed to create directory") - raise LxdError(f"Unable to create directory in LXD instance {self.instance.name}") from err + raise LxdError( + f"Unable to create directory in LXD instance {self.instance.name}" + ) from err def push_file(self, source: str, destination: str, mode: Optional[str] = None) -> None: """Push a file to the LXD instance. diff --git a/src/runner.py b/src/runner.py index a6e88a45e..5abc1c6e8 100644 --- a/src/runner.py +++ b/src/runner.py @@ -60,11 +60,11 @@ class Runner: pre_job_script = runner_application / "pre-job.sh" def __init__( - self, - clients: RunnerClients, - runner_config: RunnerConfig, - runner_status: RunnerStatus, - instance: Optional[LxdInstance] = None, + self, + clients: RunnerClients, + runner_config: RunnerConfig, + runner_status: RunnerStatus, + instance: Optional[LxdInstance] = None, ): """Construct the runner instance. @@ -80,11 +80,11 @@ def __init__( self.instance = instance def create( - self, - image: str, - resources: VirtualMachineResources, - binary_path: Path, - registration_token: str, + self, + image: str, + resources: VirtualMachineResources, + binary_path: Path, + registration_token: str, ): """Create the runner instance on LXD and register it on GitHub. @@ -193,7 +193,7 @@ def remove(self, remove_token: str) -> None: @retry(tries=5, delay=1, local_logger=logger) def _create_instance( - self, image: str, resources: VirtualMachineResources, ephemeral: bool = True + self, image: str, resources: VirtualMachineResources, ephemeral: bool = True ) -> LxdInstance: """Create an instance of runner. @@ -318,14 +318,16 @@ def _start_instance(self) -> None: # Setting `wait=True` only ensure the instance has begin to boot up. self.instance.start(wait=True) - @retry(tries=120, delay=30, local_logger=logger) + @retry(tries=20, delay=30, local_logger=logger) def _wait_boot_up(self) -> None: if self.instance is None: raise RunnerError("Runner operation called prior to runner creation.") # Wait for the instance to finish to boot up and network to be up. - assert self.instance.execute(["/usr/bin/who"])[0] == 0 - assert self.instance.execute(["/usr/bin/nslookup", "github.com"])[0] == 0 + if self.instance.execute(["/usr/bin/who"])[0] != 0: + raise RunnerError("Runner system is not ready") + if self.instance.execute(["/usr/bin/nslookup", "github.com"])[0] != 0: + raise RunnerError("Runner network is not ready") logger.info("Finished booting up LXD instance for runner: %s", self.config.name) diff --git a/src/runner_manager.py b/src/runner_manager.py index 158f82861..c22abc3d5 100644 --- a/src/runner_manager.py +++ b/src/runner_manager.py @@ -74,11 +74,11 @@ class RunnerManager: runner_bin_path = Path("/opt/github-runner-app") def __init__( - self, - app_name: str, - unit: int, - runner_manager_config: RunnerManagerConfig, - proxies: ProxySetting = ProxySetting(), + self, + app_name: str, + unit: int, + runner_manager_config: RunnerManagerConfig, + proxies: ProxySetting = ProxySetting(), ) -> None: """Construct RunnerManager object for creating and managing runners. @@ -136,7 +136,7 @@ def __init__( @retry(tries=5, delay=30, local_logger=logger) def get_latest_runner_bin_url( - self, os_name: str = "linux", arch_name: str = "x64" + self, os_name: str = "linux", arch_name: str = "x64" ) -> RunnerApplication: """Get the URL for the latest runner binary. @@ -407,9 +407,9 @@ def _get_runners(self) -> list[Runner]: """ def create_runner_info( - name: str, - local_runner: Optional[LxdInstance], - remote_runner: Optional[SelfHostedRunner], + name: str, + local_runner: Optional[LxdInstance], + remote_runner: Optional[SelfHostedRunner], ) -> Runner: """Create runner from information from GitHub and LXD.""" logger.debug( From 10c8ba9df5508868ebc32ed6e88d14db06b87f90 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 18:57:27 +0800 Subject: [PATCH 105/113] Add footgun prevention --- .github/workflows/e2e_test.yaml | 1 + config.yaml | 5 +++++ src/charm.py | 7 ++++++- src/runner.py | 12 ++++++------ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/.github/workflows/e2e_test.yaml b/.github/workflows/e2e_test.yaml index 0da22bcbc..ccc0e1873 100644 --- a/.github/workflows/e2e_test.yaml +++ b/.github/workflows/e2e_test.yaml @@ -109,6 +109,7 @@ jobs: --config path=${{ secrets.E2E_TESTING_REPO }} \ --config token=${{ secrets.E2E_TESTING_TOKEN }} \ --config virtual-machines=1 \ + --config test-mode=insecure - name: Watch github-runner env: diff --git a/config.yaml b/config.yaml index e238e5381..c19d0a57f 100644 --- a/config.yaml +++ b/config.yaml @@ -52,3 +52,8 @@ options: default: 60 description: > Minutes between each check for new versions of the runner binary. + test-mode: + type: string + description: > + When set to 'insecure', the charm test mode is activated, which may deactivate some security + hardening measures. diff --git a/src/charm.py b/src/charm.py index b91774b9c..6a54f29b5 100755 --- a/src/charm.py +++ b/src/charm.py @@ -32,6 +32,7 @@ from github_type import GitHubRunnerStatus from runner_manager import RunnerManager, RunnerManagerConfig from runner_type import GitHubOrg, GitHubRepo, ProxySetting, VirtualMachineResources +from src.runner import LXD_PROFILE_YAML from utilities import execute_command, get_env_var, retry if TYPE_CHECKING: @@ -122,7 +123,11 @@ def __init__(self, *args, **kargs) -> None: class. """ super().__init__(*args, **kargs) - + if LXD_PROFILE_YAML.exists(): + if self.config.get("test-mode") != "insecure": + raise RuntimeError("lxd-profile.yaml detected outside test mode") + else: + logger.critical("test mode is enabled") self._event_timer = EventTimer(self.unit.name) self._stored.set_default( diff --git a/src/runner.py b/src/runner.py index 5abc1c6e8..abf52a7fa 100644 --- a/src/runner.py +++ b/src/runner.py @@ -35,9 +35,9 @@ from utilities import retry logger = logging.getLogger(__name__) -_LXD_PROFILE_YAML = pathlib.Path(__file__).parent.parent / "lxd-profile.yaml" -if _LXD_PROFILE_YAML.exists(): - logger.info("lxd-profile.yaml file exists, starting testing mode") +LXD_PROFILE_YAML = pathlib.Path(__file__).parent.parent / "lxd-profile.yaml" +if not LXD_PROFILE_YAML.exists(): + LXD_PROFILE_YAML = LXD_PROFILE_YAML.parent / "lxd-profile.yml" class Runner: @@ -213,7 +213,7 @@ def _create_instance( # Create runner instance. instance_config: LxdInstanceConfig = { "name": self.config.name, - "type": "container" if _LXD_PROFILE_YAML.exists() else "virtual-machine", + "type": "container" if LXD_PROFILE_YAML.exists() else "virtual-machine", "source": { "type": "image", "mode": "pull", @@ -240,8 +240,8 @@ def _ensure_runner_profile(self) -> None: logger.info("Creating runner LXD profile") profile_config = {} profile_devices = {} - if _LXD_PROFILE_YAML.exists(): - additional_lxc_profile = yaml.safe_load(_LXD_PROFILE_YAML.read_text()) + if LXD_PROFILE_YAML.exists(): + additional_lxc_profile = yaml.safe_load(LXD_PROFILE_YAML.read_text()) profile_config = { k: json.dumps(v) if isinstance(v, bool) else v for k, v in additional_lxc_profile["config"].items() From 6dabd31ca6eb9fa41b53f02ef2939007d889098f Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 18:58:04 +0800 Subject: [PATCH 106/113] Update charm.py --- src/charm.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/charm.py b/src/charm.py index 6a54f29b5..a36e91224 100755 --- a/src/charm.py +++ b/src/charm.py @@ -126,8 +126,7 @@ def __init__(self, *args, **kargs) -> None: if LXD_PROFILE_YAML.exists(): if self.config.get("test-mode") != "insecure": raise RuntimeError("lxd-profile.yaml detected outside test mode") - else: - logger.critical("test mode is enabled") + logger.critical("test mode is enabled") self._event_timer = EventTimer(self.unit.name) self._stored.set_default( From 7a7234918a66ea7ec6a16397c0610a30b3a52de1 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 19:04:29 +0800 Subject: [PATCH 107/113] Update e2e_test.yaml --- .github/workflows/e2e_test.yaml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/e2e_test.yaml b/.github/workflows/e2e_test.yaml index ccc0e1873..39b2b1375 100644 --- a/.github/workflows/e2e_test.yaml +++ b/.github/workflows/e2e_test.yaml @@ -1,4 +1,4 @@ -name: Start E2E Test +name: End-to-End Test on: pull_request: @@ -164,12 +164,8 @@ jobs: - name: Install microk8s run: sudo snap install microk8s --classic - name: Wait for microk8s - run: | - while :; do - sudo timeout 60 microk8s status --wait-ready \ - && break \ - || sudo microk8s kubectl get pods --all-namespaces || : - done + timeout-minutes: 10 + run: sudo microk8s status --wait-ready - name: Deploy nginx for testing run: sudo microk8s kubectl create deployment nginx --image=nginx - name: Wait for nginx to be ready From 8504fd2a02a2b4b1fda2e7a1e6cad3b06b585cbe Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 19:19:05 +0800 Subject: [PATCH 108/113] restore pre-job --- .github/workflows/e2e_test.yaml | 4 ++-- templates/pre-job.j2 | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e_test.yaml b/.github/workflows/e2e_test.yaml index 39b2b1375..9a3616034 100644 --- a/.github/workflows/e2e_test.yaml +++ b/.github/workflows/e2e_test.yaml @@ -55,7 +55,7 @@ jobs: - name: Upload github-runner Charm uses: actions/upload-artifact@v3 with: - name: danger-test-only-github-runner_ubuntu-22.04-amd64.charm + name: dangerous-test-only-github-runner_ubuntu-22.04-amd64.charm path: github-runner_ubuntu-22.04-amd64.charm run-id: @@ -98,7 +98,7 @@ jobs: - name: Download github-runner Charm uses: actions/download-artifact@v3 with: - name: danger-test-only-github-runner_ubuntu-22.04-amd64.charm + name: dangerous-test-only-github-runner_ubuntu-22.04-amd64.charm - name: Deploy github-runner Charm run: | diff --git a/templates/pre-job.j2 b/templates/pre-job.j2 index f1f641af1..12b0bf73f 100644 --- a/templates/pre-job.j2 +++ b/templates/pre-job.j2 @@ -1 +1,11 @@ #!/usr/bin/env bash + +GITHUB_SOURCE_REPOSITORY=$(cat "${GITHUB_EVENT_PATH}" | jq -r '.pull_request.head.repo.full_name') + +# Request repo-policy-compliance service check. +curl --noproxy '*' \ + --fail-with-body \ + -H 'Authorization: Bearer {{one_time_token}}' \ + -H 'Content-Type: application/json' \ + -d "{\"repository_name\": \"${GITHUB_REPOSITORY}\", \"source_repository_name\": \"${GITHUB_SOURCE_REPOSITORY}\", \"target_branch_name\": \"${GITHUB_BASE_REF}\", \"source_branch_name\": \"${GITHUB_HEAD_REF}\", \"commit_sha\": \"${GITHUB_SHA}\"}" \ + http://{{host_ip}}:8080/check-run \ No newline at end of file From a44f6f1b7df516928a050bb5b880e22155d2aafa Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 19:19:56 +0800 Subject: [PATCH 109/113] Update pre-job.j2 --- templates/pre-job.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/pre-job.j2 b/templates/pre-job.j2 index 12b0bf73f..968a77dbb 100644 --- a/templates/pre-job.j2 +++ b/templates/pre-job.j2 @@ -8,4 +8,4 @@ curl --noproxy '*' \ -H 'Authorization: Bearer {{one_time_token}}' \ -H 'Content-Type: application/json' \ -d "{\"repository_name\": \"${GITHUB_REPOSITORY}\", \"source_repository_name\": \"${GITHUB_SOURCE_REPOSITORY}\", \"target_branch_name\": \"${GITHUB_BASE_REF}\", \"source_branch_name\": \"${GITHUB_HEAD_REF}\", \"commit_sha\": \"${GITHUB_SHA}\"}" \ - http://{{host_ip}}:8080/check-run \ No newline at end of file + http://{{host_ip}}:8080/check-run From adc27db61487adec36a1ffccae902b934edf10b2 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 19:23:43 +0800 Subject: [PATCH 110/113] Update charm.py --- src/charm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/charm.py b/src/charm.py index a36e91224..0e872c615 100755 --- a/src/charm.py +++ b/src/charm.py @@ -30,9 +30,9 @@ from errors import RunnerError, SubprocessError from event_timer import EventTimer, TimerDisableError, TimerEnableError from github_type import GitHubRunnerStatus +from runner import LXD_PROFILE_YAML from runner_manager import RunnerManager, RunnerManagerConfig from runner_type import GitHubOrg, GitHubRepo, ProxySetting, VirtualMachineResources -from src.runner import LXD_PROFILE_YAML from utilities import execute_command, get_env_var, retry if TYPE_CHECKING: From 5c058abc2c9fa3b437c2e549c51a50794f9c9fa5 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Mon, 19 Jun 2023 22:59:04 +0800 Subject: [PATCH 111/113] Remove som debug code --- .gitignore | 2 +- src/lxd.py | 17 +---------------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 4352f1f53..c65caac0e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ placeholders/ *.charm build/ .coverage -lxd-profile.yaml \ No newline at end of file +lxd-profile.* diff --git a/src/lxd.py b/src/lxd.py index 9b15008ae..4d2aaaa49 100644 --- a/src/lxd.py +++ b/src/lxd.py @@ -47,22 +47,7 @@ def mk_dir(self, dir_name: str) -> None: Args: dir: Name of the directory to create. """ - lxc_command = [ - "/snap/bin/lxc", - "exec", - self.instance.name, - "--", - "/usr/bin/mkdir", - "-p", - dir_name, - ] - try: - execute_command(lxc_command) - except SubprocessError as err: - logger.exception("Failed to create directory") - raise LxdError( - f"Unable to create directory in LXD instance {self.instance.name}" - ) from err + self.instance.execute(["/usr/bin/mkdir", "-p", dir_name]) def push_file(self, source: str, destination: str, mode: Optional[str] = None) -> None: """Push a file to the LXD instance. From 39a56299d01cabb5157e7e4e2d8b28f8addd6af4 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Tue, 20 Jun 2023 15:12:07 +0800 Subject: [PATCH 112/113] Fix a typo --- .github/workflows/e2e_test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e_test.yaml b/.github/workflows/e2e_test.yaml index 9a3616034..d38455aa3 100644 --- a/.github/workflows/e2e_test.yaml +++ b/.github/workflows/e2e_test.yaml @@ -50,7 +50,7 @@ jobs: - name: Pack github-runner Charm if: steps.cache-charm.outputs.cache-hit != 'true' - run: charmcraft pack || ( cat ~/.local/state/charmcraft/log/* 1 && exit 1 ) + run: charmcraft pack || ( cat ~/.local/state/charmcraft/log/* && exit 1 ) - name: Upload github-runner Charm uses: actions/upload-artifact@v3 From ccd3affcbb02cbe6e5340cbbef4eca9f85db3c37 Mon Sep 17 00:00:00 2001 From: Weii Wang Date: Wed, 21 Jun 2023 13:47:18 +0800 Subject: [PATCH 113/113] Update e2e_test.yaml --- .github/workflows/e2e_test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/e2e_test.yaml b/.github/workflows/e2e_test.yaml index d38455aa3..e16a625e7 100644 --- a/.github/workflows/e2e_test.yaml +++ b/.github/workflows/e2e_test.yaml @@ -141,6 +141,7 @@ jobs: needs: [ build-charm, run-id ] runs-on: [ self-hosted, linux, x64, "${{ needs.run-id.outputs.run-id }}" ] steps: + # below is a series of simple tests to assess the functionality of the newly spawned runner. - name: Echo hello world run: echo "hello world" - name: File permission for /usr/local/bin