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

feat: setup e2e env #116

Merged
merged 4 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ dtm
.glide/

# YAML for testings
*.yaml
config*.yaml
daniel-hutao marked this conversation as resolved.
Show resolved Hide resolved
app*.yaml

# IDE
.idea/

# .devstream
.devstream/
devstream.state

# e2e
testbin/
4 changes: 4 additions & 0 deletions docs/project_layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ Web application specific components: static web assets, server side templates an

## Common Application Directories

### `/hack`

The [`/hack`](hack/README.md) directory contains many scripts that ensure continuous development of DevStream.

### `/configs`

Configuration file templates or default configs.
Expand Down
23 changes: 23 additions & 0 deletions hack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# DevStream hack GuideLines
daniel-hutao marked this conversation as resolved.
Show resolved Hide resolved

This document describes how you can use the scripts from [`hack`](.) directory
and gives a brief introduction and explanation of these scripts.

## Overview

The [`hack`](.) directory contains many scripts that ensure continuous development of DevStream.

## Key scripts

- [e2e](./e2e): This directory holds the scripts used for e2e testing.
- [e2e-up.sh](./e2e/e2e-up.sh): This script used for setup e2e testing environment.
- [e2e-down.sh](./e2e/e2e-down.sh): This script used for clear e2e testing kind cluster.

## Examples

- Setup e2e testing environment

```shell
cd hack/e2e
sh e2e-up.sh
```
11 changes: 11 additions & 0 deletions hack/e2e/e2e-down.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

ROOT_DIR=$(dirname "${BASH_SOURCE[0]}")/../..
WORK_DIR=${ROOT_DIR}/testbin

cd ${WORK_DIR}
./kind delete cluster --name=devstream-e2e
93 changes: 93 additions & 0 deletions hack/e2e/e2e-up.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/usr/bin/env bash

# This script is mainly used to start a k8s 1-node cluster environment for e2e testing.
# Docker is the only dependency that needs to be prepared in advance.
# `kubectl` and `kind` will be obtained through `curl`, maybe this way has the best compatibility.

# All materials required for testing are downloaded to the testbin directory,
# which is initialized only when it is executed for the first time, and then cached locally.
# The reason for not judging whether there are related tools like kubectl locally
# is because these tools may not match the versions required and are not easy to manage.

set -o errexit
set -o nounset
set -o pipefail

ROOT_DIR=$(dirname "${BASH_SOURCE[0]}")/../..
WORK_DIR=${ROOT_DIR}/testbin
K8S_VERSION=${TESTENV_K8S_VERSION:-1.22.0}
KIND_VERSION=${TESTENV_KIND_VERSION:-0.11.1}

function init() {
if [ "$(uname)" == "Darwin" ];then
HOST_OS="darwin"
elif [ "$(uname)" == "Linux" ];then
HOST_OS="linux"
else
echo "Support Darwin/Linux OS only"
exit 1
fi

if [ "$(arch)" == "amd64" ];then
HOST_ARCH="arm64"
elif [ "$(arch)" == "arm64" ];then
HOST_ARCH="amd64"
else
echo "Support amd64/arm64 CPU arch only"
exit 1
fi

echo "Got OS type: ${HOST_OS} and CPU arch: ${HOST_ARCH}"
}

# docker
function check_deps() {
echo "Requires having Docker installed"
docker ps > /dev/null
if [ $? -ne 0 ]; then
exit 1
fi
}

# kubectl & kind
function fetch_tools() {
echo "All tools save in ${WORK_DIR} directory"
if [ ! -f ${WORK_DIR} ]; then
mkdir -p ${WORK_DIR}
fi
cd ${WORK_DIR}

if [ ! -f kind ]; then
echo "kind doesn't exist, download it now"
kind_uri="https://kind.sigs.k8s.io/dl/v${KIND_VERSION}/kind-${HOST_OS}-${HOST_ARCH}"
echo "kind uri: ${kind_uri}"
curl -Lo ./kind "${kind_uri}"
fi
echo "kind already downloaded"
chmod +x ./kind

if [ ! -f kubectl ]; then
echo "kubectl doesn't exist, download it now"
kubectl_uri="https://dl.k8s.io/release/v${K8S_VERSION}/bin/${HOST_OS}/${HOST_ARCH}/kubectl"
echo "kubectl uri: ${kubectl_uri}"
curl -Lo ./kubectl "${kubectl_uri}"
fi
echo "kubectl already downloaded"
chmod +x ./kubectl

KUBECTL="${WORK_DIR}/kubectl"
KIND="${WORK_DIR}/kind"

cd -
}

# start up a kind cluster
function setup_env() {
docker pull "kindest/node:v${K8S_VERSION}"
${KIND} create cluster --image="kindest/node:v${K8S_VERSION}" --config="${ROOT_DIR}/hack/e2e/kind.yaml" --name=devstream-e2e
}

init
check_deps
fetch_tools
setup_env
9 changes: 9 additions & 0 deletions hack/e2e/kind.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 8080
hostPort: 8080
listenAddress: "0.0.0.0"
protocol: tcp
1 change: 1 addition & 0 deletions test/e2e/suites.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package e2e
1 change: 1 addition & 0 deletions test/smoke/smoke.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding: utf-8 -*-