Skip to content

Commit 67cf650

Browse files
committed
Add workflow to run e2e tests using GitHub CI
Signed-off-by: Andrei Kvapil <[email protected]>
1 parent a9c8133 commit 67cf650

13 files changed

Lines changed: 67 additions & 171 deletions

File tree

‎.github/workflows/e2e-test.yml‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Build and run e2e tests
2+
3+
on:
4+
pull_request:
5+
types: [labeled, opened, synchronize, reopened]
6+
7+
jobs:
8+
e2e:
9+
name: Build and run e2e tests
10+
runs-on: [self-hosted]
11+
permissions:
12+
contents: read
13+
packages: write
14+
15+
if: contains(github.event.pull_request.labels.*.name, 'ok-to-test')
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 1
22+
23+
- name: Login to GitHub Container Registry
24+
uses: docker/login-action@v3
25+
with:
26+
username: ${{ github.repository_owner }}
27+
password: ${{ secrets.GITHUB_TOKEN }}
28+
registry: ghcr.io
29+
30+
- name: make build
31+
run: |
32+
make build
33+
34+
- name: make test
35+
run: |
36+
make test

‎Makefile‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
.PHONY: manifests repos assets
22

3-
build:
3+
build-deps:
4+
@command -V find docker skopeo jq gh > /dev/null
5+
@yq --version | grep -q "mikefarah" || (echo "mikefarah/yq is required" && exit 1)
6+
@tar --version | grep -q GNU || (echo "GNU tar is required" && exit 1)
7+
@sed --version | grep -q GNU || (echo "GNU sed is required" && exit 1)
8+
@awk --version | grep -q GNU || (echo "GNU awk is required" && exit 1)
9+
10+
build: build-deps
411
make -C packages/apps/http-cache image
512
make -C packages/apps/postgres image
613
make -C packages/apps/mysql image
@@ -38,10 +45,9 @@ assets:
3845
make -C packages/core/installer/ assets
3946

4047
test:
41-
test -f _out/assets/nocloud-amd64.raw.xz || make -C packages/core/installer talos-nocloud
4248
make -C packages/core/testing apply
4349
make -C packages/core/testing test
44-
make -C packages/core/testing test-applications
50+
#make -C packages/core/testing test-applications
4551

4652
generate:
4753
hack/update-codegen.sh

‎hack/e2e.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ done
8484

8585
# Start VMs
8686
for i in 1 2 3; do
87-
qemu-system-x86_64 -machine type=pc,accel=kvm -cpu host -smp 4 -m 8192 \
87+
qemu-system-x86_64 -machine type=pc,accel=kvm -cpu host -smp 8 -m 16384 \
8888
-device virtio-net,netdev=net0,mac=52:54:00:12:34:5$i -netdev tap,id=net0,ifname=cozy-srv$i,script=no,downscript=no \
8989
-drive file=srv$i/system.img,if=virtio,format=raw \
9090
-drive file=srv$i/seed.img,if=virtio,format=raw \

‎packages/core/builder/Chart.yaml‎

Lines changed: 0 additions & 3 deletions
This file was deleted.

‎packages/core/builder/Makefile‎

Lines changed: 0 additions & 35 deletions
This file was deleted.

‎packages/core/builder/config.toml‎

Lines changed: 0 additions & 11 deletions
This file was deleted.

‎packages/core/builder/templates/sandbox.yaml‎

Lines changed: 0 additions & 43 deletions
This file was deleted.

‎packages/core/builder/values.yaml‎

Lines changed: 0 additions & 3 deletions
This file was deleted.

‎packages/core/installer/Makefile‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ diff:
1919

2020
update:
2121
hack/gen-profiles.sh
22-
IMAGE=$$(yq '.input.baseInstaller.imageRef | sub("/installer:", "/imager:")' images/talos/profiles/installer.yaml) \
23-
yq -i '.talos.imager.image = strenv(IMAGE)' ../builder/values.yaml
2422

2523
image: pre-checks image-matchbox image-cozystack image-talos
2624

27-
image-cozystack: run-builder
25+
image-cozystack:
2826
make -C ../../.. repos
2927
docker buildx build -f images/cozystack/Dockerfile ../../.. \
3028
--provenance false \
@@ -40,11 +38,11 @@ image-cozystack: run-builder
4038
yq -i '.cozystack.image = strenv(IMAGE)' values.yaml
4139
rm -f images/installer.json
4240

43-
image-talos: run-builder
41+
image-talos:
4442
test -f ../../../_out/assets/installer-amd64.tar || make talos-installer
4543
skopeo copy docker-archive:../../../_out/assets/installer-amd64.tar docker://$(REGISTRY)/talos:$(call settag,$(TALOS_VERSION))
4644

47-
image-matchbox: run-builder
45+
image-matchbox:
4846
test -f ../../../_out/assets/kernel-amd64 || make talos-kernel
4947
test -f ../../../_out/assets/initramfs-metal-amd64.xz || make talos-initramfs
5048
docker buildx build -f images/matchbox/Dockerfile ../../.. \
@@ -66,10 +64,5 @@ assets: talos-iso talos-nocloud talos-metal
6664
talos-initramfs talos-kernel talos-installer talos-iso talos-nocloud talos-metal:
6765
mkdir -p ../../../_out/assets
6866
cat images/talos/profiles/$(subst talos-,,$@).yaml | \
69-
kubectl exec -i -n cozy-builder deploy/builder-talos-imager -- imager -
70-
kubectl exec -n cozy-builder deploy/builder-talos-imager -- tar -C /out -czf- . | \
71-
tar -C ../../../_out/assets -xzf-
72-
kubectl exec -n cozy-builder deploy/builder-talos-imager -- rm -rf /out
73-
74-
run-builder:
75-
make -C ../builder/ apply wait-for-builder
67+
docker run --rm -i -v /dev:/dev --privileged "ghcr.io/siderolabs/imager:$(TALOS_VERSION)" --tar-to-stdout - | \
68+
tar -C ../../../_out/assets -xzf-

‎packages/core/testing/Makefile‎

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ NAMESPACE=cozy-e2e-tests
22
NAME := sandbox
33
CLEAN := 1
44
TESTING_APPS := $(shell find ../../apps -maxdepth 1 -mindepth 1 -type d | awk -F/ '{print $$NF}')
5+
SANDBOX_NAME := cozy-e2e-sandbox
6+
7+
ROOT_DIR = $(dir $(abspath $(firstword $(MAKEFILE_LIST))/../../..))
58

69
include ../../../scripts/common-envs.mk
710

@@ -34,27 +37,20 @@ image-e2e-sandbox:
3437
yq -i '.e2e.image = strenv(IMAGE)' values.yaml
3538
rm -f images/e2e-sandbox.json
3639

37-
copy-hack-dir:
38-
tar -C ../../../ -cf- hack | kubectl exec -i -n $(NAMESPACE) deploy/cozystack-e2e-$(NAME) -- tar -xf-
39-
40-
copy-image:
41-
cat ../../../_out/assets/nocloud-amd64.raw.xz | kubectl exec -i -n $(NAMESPACE) deploy/cozystack-e2e-$(NAME) -- sh -xec 'xz --decompress > /nocloud-amd64.raw'
42-
43-
test: wait-for-sandbox copy-hack-dir copy-image ## Run the end-to-end tests in existing sandbox.
44-
helm template -n cozy-system installer ../installer | kubectl exec -i -n $(NAMESPACE) deploy/cozystack-e2e-$(NAME) -- sh -c 'cat > /cozystack-installer.yaml'
45-
kubectl exec -ti -n $(NAMESPACE) deploy/cozystack-e2e-$(NAME) -- sh -c 'export COZYSTACK_INSTALLER_YAML=$$(cat /cozystack-installer.yaml) && /hack/e2e.sh'
40+
test: ## Run the end-to-end tests in existing sandbox.
41+
docker exec "${SANDBOX_NAME}" sh -c 'cd /workspace && export COZYSTACK_INSTALLER_YAML=$$(helm template -n cozy-system installer ./packages/core/installer) && hack/e2e.sh'
4642

47-
test-applications: wait-for-sandbox copy-hack-dir ## Run the end-to-end tests in existing sandbox for applications.
43+
test-applications: ## Run the end-to-end tests in existing sandbox for applications.
4844
for app in $(TESTING_APPS); do \
49-
kubectl exec -ti -n cozy-e2e-tests deploy/cozystack-e2e-sandbox -- bash -c "/hack/e2e.application.sh $${app}"; \
45+
docker exec ${SANDBOX_NAME} bash -c "/hack/e2e.application.sh $${app}"; \
5046
done
51-
kubectl exec -ti -n cozy-e2e-tests deploy/cozystack-e2e-sandbox -- bash -c "kubectl get hr -A | grep -v 'True'"
47+
docker exec ${SANDBOX_NAME} bash -c "kubectl get hr -A | grep -v 'True'"
5248

5349
delete: ## Remove sandbox from existing Kubernetes cluster.
54-
kubectl delete deploy -n $(NAMESPACE) cozystack-e2e-$(NAME)
50+
docker rm -f "${SANDBOX_NAME}" || true
5551

5652
exec: ## Opens an interactive shell in the sandbox container.
57-
kubectl exec -ti -n $(NAMESPACE) deploy/cozystack-e2e-$(NAME) -- bash
53+
docker exec -ti "${SANDBOX_NAME}" -- bash
5854

5955
proxy: sync-hosts ## Enable a SOCKS5 proxy server; mirrord and gost must be installed.
6056
mirrord exec --target deploy/cozystack-e2e-sandbox --target-namespace cozy-e2e-tests -- gost -L=127.0.0.1:10080
@@ -65,6 +61,6 @@ login: ## Downloads the kubeconfig into a temporary directory and runs a shell w
6561
sync-hosts:
6662
kubectl exec -n $(NAMESPACE) deploy/cozystack-e2e-$(NAME) -- sh -c 'kubectl get ing -A -o go-template='\''{{ "127.0.0.1 localhost\n"}}{{ range .items }}{{ range .status.loadBalancer.ingress }}{{ .ip }}{{ end }} {{ range .spec.rules }}{{ .host }}{{ end }}{{ "\n" }}{{ end }}'\'' > /etc/hosts'
6763

68-
wait-for-sandbox:
69-
kubectl wait deploy --for=condition=Progressing -n $(NAMESPACE) cozystack-e2e-$(NAME)
70-
kubectl wait pod --for=condition=Ready -n $(NAMESPACE) -l app=cozystack-e2e-$(NAME)
64+
apply: delete
65+
docker run -d --rm --name "${SANDBOX_NAME}" --privileged ghcr.io/cozystack/cozystack/e2e-sandbox:latest@sha256:f41b1e0f76e7820ce87cd3dfa1b680490d0c898105690c79537943f26ab28040 sleep infinity
66+
docker cp "${ROOT_DIR}" "${SANDBOX_NAME}":/workspace

0 commit comments

Comments
 (0)