Skip to content

Commit

Permalink
chore: add compatibility test workflow (dragonflyoss#594)
Browse files Browse the repository at this point in the history
* chore: add compatibility test workflow

Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi authored Sep 2, 2021
1 parent ac65c1b commit d2e70b2
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 64 deletions.
98 changes: 98 additions & 0 deletions .github/workflows/compatibility-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Compatibility E2E Test

on:
push:
branches: [main, release-*]
pull_request:
branches: [main, release-*]

env:
GO_VERSION: 1.15
KIND_VERSION: v0.11.1
CONTAINERD_VERSION: v1.5.2
GOPROXY: https://goproxy.io,direct
KIND_CONFIG_PATH: test/testdata/kind/config.yaml
DRAGONFLY_E2E_TEST_MODE: compatibility
DRAGONFLY_DFDAEMON_IMAGE: dragonflyoss/dfdaemon:v0.4.0
DRAGONFLY_CHARTS_PATH: deploy/helm-charts/charts/dragonfly
DRAGONFLY_CHARTS_CONFIG_PATH: test/testdata/charts/compatibility-config.yaml
DRAGONFLY_FILE_SERVER_PATH: test/testdata/k8s/file-server.yaml

jobs:
skip_check:
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- name: Skip Check
id: skip_check
uses: fkirc/skip-duplicate-actions@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
paths_ignore: '["**.md", "**.png", "**.jpg", "**.svg"]'
do_not_skip: '["pull_request", "workflow_dispatch", "schedule"]'

e2e_tests:
runs-on: ubuntu-latest
needs: skip_check
if: needs.skip_check.outputs.noop != 'true'

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
submodules: recursive

- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

- name: Get dependencies
run: |
go mod vendor
go get github.com/onsi/ginkgo/ginkgo
mkdir -p /tmp/artifact
- name: Setup Kind
uses: engineerd/[email protected]
with:
version: ${{ env.KIND_VERSION }}
config: ${{ env.KIND_CONFIG_PATH }}

- name: Build images
run: |
make docker-build-manager
make docker-build-cdn
make docker-build-scheduler
docker pull ${{ env.DRAGONFLY_DFDAEMON_IMAGE }}
- name: Prepare kind environment
run: |
make kind-load-manager
make kind-load-cdn
make kind-load-scheduler
kind load docker-image ${{ env.DRAGONFLY_DFDAEMON_IMAGE }}
- name: Setup dragonfly
run: |
helm install --wait --timeout 10m --dependency-update --create-namespace --namespace dragonfly-system -f ${{ env.DRAGONFLY_CHARTS_CONFIG_PATH }} dragonfly ${{ env.DRAGONFLY_CHARTS_PATH }}
kubectl apply -f ${{ env.DRAGONFLY_FILE_SERVER_PATH }}
kubectl wait po file-server-0 --namespace dragonfly-e2e --for=condition=ready --timeout=10m
- name: Run compatibility E2E test
run: make actions-e2e-test-coverage

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.txt
flags: compatibility-e2etests

- name: Upload Logs
uses: actions/upload-artifact@v2
if: failure()
with:
name: dragonfly-logs
path: /tmp/artifact/
21 changes: 19 additions & 2 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ env:
KIND_VERSION: v0.11.1
CONTAINERD_VERSION: v1.5.2
GOPROXY: https://goproxy.io,direct
KIND_CONFIG_PATH: test/testdata/kind/config.yaml
DRAGONFLY_CHARTS_PATH: deploy/helm-charts/charts/dragonfly
DRAGONFLY_CHARTS_CONFIG_PATH: test/testdata/charts/config.yaml
DRAGONFLY_FILE_SERVER_PATH: test/testdata/k8s/file-server.yaml

jobs:
skip_check:
Expand Down Expand Up @@ -45,15 +49,28 @@ jobs:
- name: Get dependencies
run: |
go mod vendor
go get github.com/onsi/ginkgo/ginkgo
mkdir -p /tmp/artifact
- name: Setup Kind
uses: engineerd/[email protected]
with:
version: ${{ env.KIND_VERSION }}
config: ./test/testdata/kind/config.yaml
config: ${{ env.KIND_CONFIG_PATH }}

- name: Run E2E tests
- name: Build images
run: make docker-build

- name: Prepare kind environment
run: make kind-load

- name: Setup dragonfly
run: |
helm install --wait --timeout 10m --dependency-update --create-namespace --namespace dragonfly-system -f ${{ env.DRAGONFLY_CHARTS_CONFIG_PATH }} dragonfly ${{ env.DRAGONFLY_CHARTS_PATH }}
kubectl apply -f ${{ env.DRAGONFLY_FILE_SERVER_PATH }}
kubectl wait po file-server-0 --namespace dragonfly-e2e --for=condition=ready --timeout=10m
- name: Run E2E test
run: make actions-e2e-test-coverage

- name: Upload coverage to Codecov
Expand Down
22 changes: 5 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -190,35 +190,25 @@ test-coverage:
@cat cover.out >> coverage.txt
.PHONY: test-coverage

# Install github actions E2E tests environment
install-actions-e2e-test:
@./hack/install-e2e-test.sh actions
.PHONY: install-actions-e2e-test

# Run github actions E2E tests
actions-e2e-test: install-actions-e2e-test
@ginkgo -v -r --failFast test/e2e --trace --progress
.PHONY: actions-e2e-test

# Run github actions E2E tests with coverage
actions-e2e-test-coverage: install-actions-e2e-test
@ginkgo -v -r --failFast -cover test/e2e --trace --progress
actions-e2e-test-coverage:
@ginkgo -v -r --race --failFast -cover test/e2e --trace --progress
@cat test/e2e/*.coverprofile >> coverage.txt
.PHONY: actions-e2e-test-coverage

# Install E2E tests environment
install-e2e-test:
@./hack/install-e2e-test.sh local
@./hack/install-e2e-test.sh
.PHONY: install-e2e-test

# Run E2E tests
e2e-test: install-e2e-test
@ginkgo -v -r --failFast test/e2e --trace --progress
@ginkgo -v -r --race --failFast test/e2e --trace --progress
.PHONY: e2e-test

# Run E2E tests with coverage
e2e-test-coverage: install-e2e-test
@ginkgo -v -r --failFast -cover test/e2e --trace --progress
@ginkgo -v -r --race --failFast -cover test/e2e --trace --progress
@cat test/e2e/*.coverprofile >> coverage.txt
.PHONY: e2e-test-coverage

Expand Down Expand Up @@ -295,8 +285,6 @@ help:
@echo "make build-dfget-man-page generate dfget man page"
@echo "make test run unittests"
@echo "make test-coverage run tests with coverage"
@echo "make install-actions-e2e-test install github actions E2E tests environment"
@echo "make actions-e2e-test run github actons E2E tests"
@echo "make actions-e2e-test-coverage run github actons E2E tests with coverage"
@echo "make install-e2e-test install E2E tests environment"
@echo "make e2e-test run e2e tests"
Expand Down
44 changes: 7 additions & 37 deletions hack/install-e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ install-apache-bench() {
fi
}

install-local() {
print_step_info() {
echo "-----------------------------"
echo $1
echo "-----------------------------"
}

main() {
print_step_info "start kind create cluster"
install-kind

Expand All @@ -83,40 +89,4 @@ install-local() {
install-apache-bench
}

install-actions() {
print_step_info "start building docker images"
make docker-build

print_step_info "start loading image for kind"
make kind-load

print_step_info "start helm install dragonfly"
install-helm

print_step_info "start install file server"
install-file-server

print_step_info "start install ginkgo"
install-ginkgo

print_step_info "start install apache bench"
install-apache-bench
}

print_step_info() {
echo "-----------------------------"
echo $1
echo "-----------------------------"
}

main() {
case "${1-}" in
local)
install-local
;;
actions)
install-actions
esac
}

main "$@"
27 changes: 19 additions & 8 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package e2e

import (
"fmt"
"os"
"strings"
"testing"

Expand All @@ -34,23 +35,33 @@ const (
dragonflyNamespace = "dragonfly-system"
)

const (
compatibilityTestMode = "compatibility"
)

var _ = BeforeSuite(func() {
out, err := e2eutil.GitCommand("rev-parse", "--short", "HEAD").CombinedOutput()
rawGitCommit, err := e2eutil.GitCommand("rev-parse", "--short", "HEAD").CombinedOutput()
Expect(err).NotTo(HaveOccurred())
gitCommit := strings.Fields(string(out))[0]
gitCommit := strings.Fields(string(rawGitCommit))[0]
fmt.Printf("git merge commit: %s\n", gitCommit)

out, err = e2eutil.KubeCtlCommand("-n", dragonflyNamespace, "get", "pod", "-l", "component=dfdaemon",
rawPodName, err := e2eutil.KubeCtlCommand("-n", dragonflyNamespace, "get", "pod", "-l", "component=dfdaemon",
"-o", "jsonpath='{range .items[*]}{.metadata.name}{end}'").CombinedOutput()
podName := strings.Trim(string(out), "'")
podName := strings.Trim(string(rawPodName), "'")
Expect(err).NotTo(HaveOccurred())

Expect(strings.HasPrefix(podName, "dragonfly-dfdaemon-")).Should(BeTrue())

pod := e2eutil.NewPodExec(dragonflyNamespace, podName, "dfdaemon")
out, err = pod.Command("dfget", "version").CombinedOutput()
rawDfgetVersion, err := pod.Command("dfget", "version").CombinedOutput()
Expect(err).NotTo(HaveOccurred())
dfgetGitCommit := strings.Fields(string(out))[7]
fmt.Printf("dfget merge commit: %s\n", gitCommit)
dfgetGitCommit := strings.Fields(string(rawDfgetVersion))[7]
fmt.Printf("dfget merge commit: %s\n", dfgetGitCommit)

mode := os.Getenv("DRAGONFLY_E2E_TEST_MODE")
if mode == compatibilityTestMode {
Expect(gitCommit).NotTo(Equal(dfgetGitCommit))
return
}

Expect(gitCommit).To(Equal(dfgetGitCommit))
})
Expand Down
31 changes: 31 additions & 0 deletions test/testdata/charts/compatibility-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
scheduler:
image: d7yio/scheduler
tag: latest

cdn:
image: d7yio/cdn
tag: latest

dfdaemon:
image: dragonflyoss/dfdaemon
tag: v0.4.0
config:
proxy:
defaultFilter: "Expires&Signature"
security:
insecure: true
tcpListen:
namespace: /run/dragonfly/net
listen: 0.0.0.0
# if you want to change port, please update hostPort in $.Values.dfdaemon.hostPort
# port in configmap is generated from $.Values.dfdaemon.hostPort
# port: 65001
registryMirror:
url: https://index.docker.io
proxies:
- regx: blobs/sha256.*
- regx: file-server

manager:
image: d7yio/manager
tag: latest

0 comments on commit d2e70b2

Please sign in to comment.