Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement fully automated end-to-end CI testing workflow #70

Merged
merged 113 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
c73cb0e
WIP
weiiwang01 Jun 15, 2023
237954b
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
7f460f2
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
b1a27f5
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
029b5d9
WIP
weiiwang01 Jun 15, 2023
df4567c
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
958ae5c
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
8027159
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
7bf4dd7
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
048ea96
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
34d7350
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
3f1b929
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
5acbbc8
Enable
weiiwang01 Jun 15, 2023
408476c
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
4afe479
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
5a55888
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
c54a48e
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
31f4f8a
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
3c92c84
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
a493293
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
404fc82
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
8842e0c
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
511e97e
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
868e733
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
36cb5ab
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
869c893
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
6d0c11d
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
a0b00b9
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
5575da9
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
e6ceb3c
Update start_e2e_test.yaml
weiiwang01 Jun 15, 2023
845136d
Update start_e2e_test.yaml
weiiwang01 Jun 16, 2023
9eedbc1
Update start_e2e_test.yaml
weiiwang01 Jun 16, 2023
550a994
Update start_e2e_test.yaml
weiiwang01 Jun 16, 2023
32745f8
Update lxd.py
weiiwang01 Jun 16, 2023
16d30d7
Update start_e2e_test.yaml
weiiwang01 Jun 16, 2023
91e26c1
Test
weiiwang01 Jun 16, 2023
61c45a5
test
weiiwang01 Jun 16, 2023
3a9c3d7
Update start_e2e_test.yaml
weiiwang01 Jun 16, 2023
ed56ab3
Update lxd.py
weiiwang01 Jun 16, 2023
1748cd8
Revert "test"
weiiwang01 Jun 16, 2023
ca815f1
Update runner.py
weiiwang01 Jun 16, 2023
1c0a7e9
test
weiiwang01 Jun 16, 2023
05c55fa
Update start_e2e_test.yaml
weiiwang01 Jun 16, 2023
0d479f5
Update runner.py
weiiwang01 Jun 16, 2023
05ac636
using nested LXD
weiiwang01 Jun 18, 2023
3636f41
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
e62d410
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
2ffbb18
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
8a3f585
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
77dd709
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
b79ba12
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
2aedd54
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
2916739
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
97a0c1c
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
4074c2e
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
3fd472b
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
2806fde
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
375b448
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
73fae16
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
202577d
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
b0ed3e8
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
a9d5da8
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
36469a9
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
9cd29c9
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
5c67e9a
Update pre-job.j2
weiiwang01 Jun 18, 2023
24e3b9f
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
1ea8a06
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
effcdb5
test
weiiwang01 Jun 18, 2023
db551e8
Update pre-job.j2
weiiwang01 Jun 18, 2023
03ee22a
Update pre-job.j2
weiiwang01 Jun 18, 2023
0a298e8
Update runner.py
weiiwang01 Jun 18, 2023
e37d182
Update pre-job.j2
weiiwang01 Jun 18, 2023
3deb003
Update pre-job.j2
weiiwang01 Jun 18, 2023
a97c8a8
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
89b9274
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
23a8201
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
c492177
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
80d6d07
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
b056cc8
Update start_e2e_test.yaml
weiiwang01 Jun 18, 2023
08e1f54
Update end_to_end_test.yaml
weiiwang01 Jun 18, 2023
83b7a80
Update start_e2e_test.yaml
weiiwang01 Jun 19, 2023
0797e72
Update start_e2e_test.yaml
weiiwang01 Jun 19, 2023
2403822
Update start_e2e_test.yaml
weiiwang01 Jun 19, 2023
759fd31
Update start_e2e_test.yaml
weiiwang01 Jun 19, 2023
ce51b49
Update start_e2e_test.yaml
weiiwang01 Jun 19, 2023
1bc7da6
Update start_e2e_test.yaml
weiiwang01 Jun 19, 2023
0cf96fd
Update start_e2e_test.yaml
weiiwang01 Jun 19, 2023
8651647
Update start_e2e_test.yaml
weiiwang01 Jun 19, 2023
bcfc2eb
Update start_e2e_test.yaml
weiiwang01 Jun 19, 2023
1f69f96
Update start_e2e_test.yaml
weiiwang01 Jun 19, 2023
618590b
Update pre-job.j2
weiiwang01 Jun 19, 2023
81fc6b2
Use the main repo for testing
weiiwang01 Jun 19, 2023
1a85465
Update start_e2e_test.yaml
weiiwang01 Jun 19, 2023
49ce263
Update start_e2e_test.yaml
weiiwang01 Jun 19, 2023
6329932
Update start_e2e_test.yaml
weiiwang01 Jun 19, 2023
85257a3
Update start_e2e_test.yaml
weiiwang01 Jun 19, 2023
a0aca04
Update start_e2e_test.yaml
weiiwang01 Jun 19, 2023
f15347d
test
weiiwang01 Jun 19, 2023
0d9c930
Update start_e2e_test.yaml
weiiwang01 Jun 19, 2023
ae6a058
test
weiiwang01 Jun 19, 2023
56fa740
Update start_e2e_test.yaml
weiiwang01 Jun 19, 2023
5cb89f6
Update runner.py
weiiwang01 Jun 19, 2023
6f6bcd3
Update start_e2e_test.yaml
weiiwang01 Jun 19, 2023
5bfec9c
test
weiiwang01 Jun 19, 2023
10c8ba9
Add footgun prevention
weiiwang01 Jun 19, 2023
6dabd31
Update charm.py
weiiwang01 Jun 19, 2023
7a72349
Update e2e_test.yaml
weiiwang01 Jun 19, 2023
8504fd2
restore pre-job
weiiwang01 Jun 19, 2023
a44f6f1
Update pre-job.j2
weiiwang01 Jun 19, 2023
adc27db
Update charm.py
weiiwang01 Jun 19, 2023
5c058ab
Remove som debug code
weiiwang01 Jun 19, 2023
39a5629
Fix a typo
weiiwang01 Jun 20, 2023
ccd3aff
Update e2e_test.yaml
weiiwang01 Jun 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions .github/workflows/build_charm.yaml

This file was deleted.

192 changes: 192 additions & 0 deletions .github/workflows/e2e_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
name: End-to-End Test

on:
pull_request:

jobs:
build-charm:
name: Build Charm
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Remove Unnecessary Components
run: |
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
lxc.mount.auto=proc:rw sys:rw cgroup:rw
lxc.cgroup.devices.allow=a
lxc.cap.drop=
devices:
kmsg:
path: /dev/kmsg
source: /dev/kmsg
type: unix-char
EOF

- 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: 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

- name: Pack github-runner Charm
if: steps.cache-charm.outputs.cache-hit != 'true'
run: charmcraft pack || ( cat ~/.local/state/charmcraft/log/* && exit 1 )

- name: Upload github-runner Charm
uses: actions/upload-artifact@v3
with:
name: dangerous-test-only-github-runner_ubuntu-22.04-amd64.charm
path: github-runner_ubuntu-22.04-amd64.charm

run-id:
name: Generate Run ID
runs-on: ubuntu-latest
outputs:
run-id: ${{ steps.run-id.outputs.run-id }}
steps:
- 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: ubuntu-latest
needs: [ build-charm, run-id ]
steps:
- 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

- 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: Change Testing Model Logging Level
run: juju model-config logging-config="<root>=INFO;unit=DEBUG"

- name: Download github-runner Charm
uses: actions/download-artifact@v3
with:
name: dangerous-test-only-github-runner_ubuntu-22.04-amd64.charm

- 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 \
${{ needs.run-id.outputs.run-id }} \
--base [email protected] \
--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:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
timeout-minutes: 30
run: |
juju debug-log --replay --tail &
gregory-schiano marked this conversation as resolved.
Show resolved Hide resolved

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)
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
sleep 10
done
if [[ $STATUS != "completed" || $CONCLUSION != "success" ]]; then
echo "test workflow failed with status: $STATUS, conclusion: $CONCLUSION"
kill $(jobs -p)
exit 1
fi

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:
# below is a series of simple tests to assess the functionality of the newly spawned runner.
- name: Echo hello world
jdkandersson marked this conversation as resolved.
Show resolved Hide resolved
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
# "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
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
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
61 changes: 0 additions & 61 deletions .github/workflows/end_to_end_test.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Tests

on:
pull_request:
pull_request: { }

jobs:
unit-tests:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ placeholders/
*.charm
build/
.coverage
lxd-profile.*
5 changes: 5 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
10 changes: 8 additions & 2 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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 utilities import execute_command, get_env_var, retry
Expand Down Expand Up @@ -122,7 +123,10 @@ def __init__(self, *args, **kargs) -> None:
class.
"""
super().__init__(*args, **kargs)

if LXD_PROFILE_YAML.exists():
amandahla marked this conversation as resolved.
Show resolved Hide resolved
if self.config.get("test-mode") != "insecure":
raise RuntimeError("lxd-profile.yaml detected outside test mode")
logger.critical("test mode is enabled")
self._event_timer = EventTimer(self.unit.name)

self._stored.set_default(
Expand All @@ -135,7 +139,9 @@ 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
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
Expand Down
Loading