Skip to content

Commit

Permalink
Improved travis build script
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinvaneyk committed Mar 24, 2018
1 parent f5ed948 commit dfa3fc1
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 195 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ data/

*.tgz
/fission-workflows-bundle
/wfcli
/wfcli
__pycache__/
*.pyc
20 changes: 10 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ cache:
apt: true
directories:
- ${HOME}/.helm/
- ${HOME}/testbin/
- /tmp/fission-workflow-ci/bin
- ${GOPATH}/bin/
- ${GOPATH}/pkg/

env:
- KUBECONFIG=${HOME}/.kube/config PATH=$HOME/testbin:${PATH} BIN_DIR=${HOME}/testbin
- KUBECONFIG=${HOME}/.kube/config PATH=/tmp/fission-workflow-ci/bin:${PATH} BIN_DIR=/tmp/fission-workflow-ci/bin

services:
- docker
Expand All @@ -28,27 +28,27 @@ before_install:

install:
- sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
- sudo apt-get -y install google-cloud-sdk
- sudo apt-get -y install coreutils
- test/e2e/travis-setup.sh
- sudo apt-get -y install coreutils google-cloud-sdk
- test/e2e/install-clients.sh
# Needed for some integration tests
- glide -h > /dev/null || go get github.com/Masterminds/glide
- nats-streaming-server -h > /dev/null || go get github.com/nats-io/nats-streaming-server
- glide -h >/dev/null 2>&1 || go get github.com/Masterminds/glide
- nats-streaming-server -h >/dev/null 2>&1 || go get github.com/nats-io/nats-streaming-server # TODO remove the need for this

before_script:
- cd ${TRAVIS_BUILD_DIR}
# Static code analysis
- hack/verify-govet.sh
- hack/verify-gofmt.sh
- hack/verify-govet.sh
# Build
- glide install -v
- build/build-linux.sh
#- build/build-linux.sh
- test/e2e/travis-setup.sh

script:
# Unit and Integration tests
- test/runtests.sh
# End-to-end tests
- NOBUILD=true test/e2e/buildtest.sh
- test/e2e/buildtest.sh

after_script:
- test/e2e/cleanup.sh
Expand Down
8 changes: 6 additions & 2 deletions build/docker.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -euo pipefail
set -eo pipefail

#
# Builds all docker images. Usage docker.sh [<repo>] [<tag>]
Expand All @@ -25,20 +25,24 @@ if [ ! -z "$NOBUILD" ]; then
fi
echo "Building bundle..."
docker build --tag="${bundleImage}:${IMAGE_TAG}" -f ${BUILD_ROOT}/Dockerfile \
--no-cache --build-arg NOBUILD="${NOBUILD}" .
--no-cache \
--build-arg NOBUILD="${NOBUILD}" .
popd

# Build bundle-dependent images
echo "Building Fission runtime env..."
docker build --tag="${IMAGE_REPO}/workflow-env:${IMAGE_TAG}" ${BUILD_ROOT}/runtime-env/ \
--no-cache \
--build-arg BUNDLE_IMAGE=${bundleImage} \
--build-arg BUNDLE_TAG=${IMAGE_TAG}
echo "Building Fission build env..."
docker build --tag="${IMAGE_REPO}/workflow-build-env:${IMAGE_TAG}" ${BUILD_ROOT}/build-env/ \
--no-cache \
--build-arg BUNDLE_IMAGE=${bundleImage} \
--build-arg BUNDLE_TAG=${IMAGE_TAG}
echo "Building wfcli..."
docker build --tag="${IMAGE_REPO}/wfcli:${IMAGE_TAG}" ${BUILD_ROOT}/wfcli/ \
--no-cache \
--build-arg BUNDLE_IMAGE=${bundleImage} \
--build-arg BUNDLE_TAG=${IMAGE_TAG}

Expand Down
7 changes: 2 additions & 5 deletions cmd/fission-workflows-bundle/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ func Run(ctx context.Context, opts *Options) error {
es = natsEs
esPub = natsEs
}
if es == nil {
panic("no event store provided")
}

// Caches
wfiCache := getWorkflowInvocationCache(ctx, esPub)
Expand Down Expand Up @@ -290,14 +287,14 @@ func runHttpGateway(ctx context.Context, gwSrv *http.Server, adminApiAddr string
mux := grpcruntime.NewServeMux()
grpcOpts := []grpc.DialOption{grpc.WithInsecure()}
if adminApiAddr != "" {
err := apiserver.RegisterWorkflowAPIHandlerFromEndpoint(ctx, mux, adminApiAddr, grpcOpts)
err := apiserver.RegisterAdminAPIHandlerFromEndpoint(ctx, mux, adminApiAddr, grpcOpts)
if err != nil {
panic(err)
}
}

if wfApiAddr != "" {
err := apiserver.RegisterAdminAPIHandlerFromEndpoint(ctx, mux, wfApiAddr, grpcOpts)
err := apiserver.RegisterWorkflowAPIHandlerFromEndpoint(ctx, mux, wfApiAddr, grpcOpts)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/wfcli/invocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var cmdInvocation = cli.Command{
Usage: "get <workflow-invocation-id> <task-invocation-id>",
Flags: []cli.Flag{
cli.DurationFlag{
Name: "history, h",
Name: "history",
Usage: "Amount history (non-active invocations) to show.",
Value: time.Duration(1) * time.Hour,
},
Expand Down
1 change: 1 addition & 0 deletions cmd/wfcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func main() {
kubeConfig := getKubeConfigPath()
localPort := setupPortForward(kubeConfig, fissionNamespace, "application=fission-api")
value = "http://127.0.0.1:" + localPort
fmt.Printf("Forwarded Fission API to %s.\n", value)
} else {
value = fissionUrl
}
Expand Down
33 changes: 31 additions & 2 deletions test/e2e/buildtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,47 @@ DOCKER_REPO=gcr.io/fission-ci
WORKFLOWS_ENV_IMAGE=${DOCKER_REPO}/workflow-env
WORKFLOWS_BUILD_ENV_IMAGE=${DOCKER_REPO}/workflow-build-env
WORKFLOWS_BUNDLE_IMAGE=${DOCKER_REPO}/fission-workflows-bundle
TAG=test
NS=fission
NS_FUNCTION=fission-function
NS_BUILDER=fission-builder
fissionHelmId=fission
fissionWorkflowsHelmId=fission-workflows
FISSION_VERSION=0.6.0
TAG=test
TEST_STATUS=0
TEST_LOGFILE_PATH=tests.log
BIN_DIR="${BIN_DIR:-$HOME/testbin}"


print_report() {
emph "--- Test Report ---"
if ! cat ${TEST_LOGFILE_PATH} | grep '\(FAILURE\|SUCCESS\).*|' ; then
echo "No report found."
fi
emph "--- End Test Report ---"
}

on_exit() {
emph "[Buildtest exited]"
# Dump all the logs
dump_logs ${NS} ${NS_FUNCTION} ${NS_BUILDER} || true

# Print a short test report
print_report

# Ensure correct exist status
echo "TEST_STATUS: ${TEST_STATUS}"
if [ ${TEST_STATUS} -ne 0 ]; then
exit 1
fi
}

emph "Starting buildtest..."

trap on_exit EXIT

cleanup_fission_workflows ${fissionWorkflowsHelmId} || true

#
# Build
#
Expand All @@ -50,7 +79,7 @@ gcloud docker -- push ${WORKFLOWS_BUNDLE_IMAGE}:${TAG}
# Deploy Fission Workflows
# TODO use test specific namespace
emph "Deploying Fission Workflows '${fissionWorkflowsHelmId}' to ns '${NS}'..."
helm_install_fission_workflows ${fissionWorkflowsHelmId} ${NS} "pullPolicy=IfNotPresent,tag=${TAG},bundleImage=${WORKFLOWS_BUNDLE_IMAGE},envImage=${WORKFLOWS_ENV_IMAGE},buildEnvImage=${WORKFLOWS_BUILD_ENV_IMAGE}"
helm_install_fission_workflows ${fissionWorkflowsHelmId} ${NS} "pullPolicy=Always,tag=${TAG},bundleImage=${WORKFLOWS_BUNDLE_IMAGE},envImage=${WORKFLOWS_ENV_IMAGE},buildEnvImage=${WORKFLOWS_BUILD_ENV_IMAGE}"

# Wait for Fission Workflows to get ready
wfcli config
Expand Down
73 changes: 32 additions & 41 deletions test/e2e/cleanup.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash


set -euo pipefail
set -eu

. $(dirname $0)/utils.sh

Expand All @@ -14,58 +14,49 @@ TEST_STATUS=0
TEST_LOGFILE_PATH=tests.log
BIN_DIR="${BIN_DIR:-$HOME/testbin}"

cleanup() {
emph "Removing Fission and Fission Workflow deployments..."
helm_uninstall_release ${fissionWorkflowsHelmId} &
helm_uninstall_release ${fissionHelmId} &

emph "Removing custom resources..."
clean_tpr_crd_resources || true
cleanup_fission_workflows() {
emph "Removing Fission Workflows deployment..."
helm_uninstall_release ${fissionWorkflowsHelmId}
# TODO cleanup workflow functions too
}

cleanup_fission() {
# Trigger deletion of all namespaces before waiting - for concurrency of deletion
emph "Forcing deletion of namespaces..."
kubectl delete ns/${NS} > /dev/null 2>&1 & # Sometimes it is not deleted by helm delete
kubectl delete ns/${NS_BUILDER} > /dev/null 2>&1 & # Sometimes it is not deleted by helm delete
kubectl delete ns/${NS_FUNCTION} > /dev/null 2>&1 & # Sometimes it is not deleted by helm delete
kubectl delete ns/${NS} --now > /dev/null 2>&1 # Sometimes it is not deleted by helm delete
kubectl delete ns/${NS_BUILDER} --now > /dev/null 2>&1 # Sometimes it is not deleted by helm delete
kubectl delete ns/${NS_FUNCTION} --now > /dev/null 2>&1 # Sometimes it is not deleted by helm delete

cleanup_fission_workflows
emph "Removing Fission deployment..."
helm_uninstall_release ${fissionHelmId}

emph "Removing custom resources..."
clean_tpr_crd_resources || true

# Wait until all namespaces are actually deleted!
sleep 10
emph "Awaiting deletion of namespaces..."
retry kubectl delete ns/${NS} 2>&1 | grep -qv "Error from server (Conflict):"
retry kubectl delete ns/${NS_BUILDER} 2>&1 | grep -qv "Error from server (Conflict):"
retry kubectl delete ns/${NS_FUNCTION} 2>&1 | grep -qv "Error from server (Conflict):"
verify_ns_deleted() {
kubectl delete ns/${1} --now 2>&1 | grep -qv "Error from server (Conflict):"
}
# Namespaces sometimes take a long time to delete for some reason
RETRY_LIMIT=10 RETRY_DELAY=10 retry verify_ns_deleted ${NS_BUILDER}
RETRY_LIMIT=10 RETRY_DELAY=10 retry verify_ns_deleted ${NS}
RETRY_LIMIT=10 RETRY_DELAY=10 retry verify_ns_deleted ${NS_FUNCTION}

emph "Cleaning up local filesystem..."
rm -f ./fission-workflows-bundle ./wfcli
sleep 5
}

print_report() {
emph "--- Test Report ---"
if ! cat ${TEST_LOGFILE_PATH} | grep '\(FAILURE\|SUCCESS\).*|' ; then
echo "No report found."
fi
emph "--- End Test Report ---"
}

on_exit() {
emph "[Buildtest exited]"
# Dump all the logs
dump_logs ${NS} ${NS_FUNCTION} ${NS_BUILDER} || true

# Ensure teardown after tests finish
# TODO provide option to not cleanup the test setup after tests (e.g. for further tests)
emph "Cleaning up cluster..."
retry cleanup

# Print a short test report
print_report

# Ensure correct exist status
echo "TEST_STATUS: ${TEST_STATUS}"
if [ ${TEST_STATUS} -ne 0 ]; then
exit 1
fi
reset_fission_crd_resources() {
NS_CRDS=${1:-default}
echo "TODO reset fission"
exit 1
# TODO remove all functions, etc.
reset_crd_resources
}

# Ensure printing of report
on_exit
retry cleanup_fission
49 changes: 49 additions & 0 deletions test/e2e/install-clients.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash

set -euo pipefail

. $(dirname $0)/utils.sh

BIN_DIR=${BIN_DIR:-/tmp/fission-workflow-ci/bin}
HELM_VERSION=2.8.2
KUBECTL_VERSION=1.9.6
FISSION_VERSION=0.6.0

# Install kubectl
if ! kubectl version -c 2>/dev/null | grep ${KUBECTL_VERSION} >/dev/null; then
emph "Installing kubectl ${KUBECTL_VERSION} to ${BIN_DIR}/kubectl..."
curl -sLO https://storage.googleapis.com/kubernetes-release/release/v${KUBECTL_VERSION}/bin/linux/amd64/kubectl
chmod +x ./kubectl
mv -f kubectl ${BIN_DIR}/kubectl
else
emph "Kubectl ${KUBECTL_VERSION} already present."
fi
mkdir -p ${HOME}/.kube
which kubectl

# Install helm client
if ! helm version -c 2>/dev/null | grep ${HELM_VERSION} >/dev/null; then
emph "Installing Helm ${HELM_VERSION} to ${BIN_DIR}/helm..."
curl -sLO https://storage.googleapis.com/kubernetes-helm/helm-v${HELM_VERSION}-linux-amd64.tar.gz
tar xzvf helm-*.tar.gz
chmod +x linux-amd64/helm
mv -f linux-amd64/helm ${BIN_DIR}/helm
else
emph "Helm ${HELM_VERSION} already present."
fi
which helm

# Install Fission client
if ! fission --version 2>/dev/null | grep ${FISSION_VERSION} >/dev/null; then
emph "Installing Fission ${FISSION_VERSION} to ${BIN_DIR}/fission..."
curl -sLo fission https://github.com/fission/fission/releases/download/${FISSION_VERSION}/fission-cli-linux
chmod +x fission
mv -f fission ${BIN_DIR}/fission
else
emph "Fission ${FISSION_VERSION} already present."
fi
which fission

# TODO install gcloud

emph "Clients installed in ${BIN_DIR}"
Binary file modified test/e2e/tests/__pycache__/testutils.cpython-36.pyc
Binary file not shown.
Loading

0 comments on commit dfa3fc1

Please sign in to comment.