From 38f3e71ae1892dc691b56fc8b7dcffb3c1dc1e0a Mon Sep 17 00:00:00 2001 From: Steven Normore Date: Mon, 22 Jul 2019 08:46:48 -0400 Subject: [PATCH] DRY up the e2e/docker-{run,test}.sh scripts into just e2e/docker.sh --- e2e/README.md | 4 +-- e2e/docker-clean.sh | 45 -------------------------------- e2e/{docker-run.sh => docker.sh} | 13 ++++++++- 3 files changed, 14 insertions(+), 48 deletions(-) delete mode 100755 e2e/docker-clean.sh rename e2e/{docker-run.sh => docker.sh} (83%) diff --git a/e2e/README.md b/e2e/README.md index c4d7667a0..c8cc508e8 100644 --- a/e2e/README.md +++ b/e2e/README.md @@ -6,7 +6,7 @@ It may be run either locally or on the CI. ## usage -The easiest way to run the end-to-end test is to execute `e2e.sh`. It requires the following environment variables to be set: +The easiest way to run the end-to-end test is to execute `docker.sh test`. It requires the following environment variables to be set or available in a `.env` file: - `DIGITALOCEAN_ACCESS_TOKEN`: the DigitalOcean access token - `KOPS_REGION`: the DigitalOcean region (e.g., _sfo2_) @@ -25,6 +25,6 @@ The following environment parameters are optional: ## resource cleanup -The end-to-end tests clean up resources used on the DigitalOcean cloud after themselves on completion (either successful or erroneous). In the case that teardown does not complete for whatever reason (say, because of a crash of the tests or resources being in an irreparable state), the `cleanup-resources.sh` script can be used to remove the resources explicitly. +The end-to-end tests clean up resources used on the DigitalOcean cloud after themselves on completion (either successful or erroneous). In the case that teardown does not complete for whatever reason (say, because of a crash of the tests or resources being in an irreparable state), the `docker.sh clean` script can be used to remove the resources explicitly. See the script's header for details. diff --git a/e2e/docker-clean.sh b/e2e/docker-clean.sh deleted file mode 100755 index fc287d2cf..000000000 --- a/e2e/docker-clean.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2017 DigitalOcean -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -o errexit -set -o pipefail -set -o nounset - -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -( - cd ${SCRIPT_DIR} - - DOCKER_RUN_ARGS="" - if [ -f .env ]; then - DOCKER_RUN_ARGS="--env-file .env" - fi - - docker build -t do-ccm-e2e . - docker run \ - --rm -it \ - -v ${SCRIPT_DIR}:/app \ - -w /app \ - -e DIGITALOCEAN_ACCESS_TOKEN \ - -e KOPS_REGION \ - -e S3_ENDPOINT \ - -e S3_ACCESS_KEY_ID \ - -e S3_SECRET_ACCESS_KEY \ - -e KOPS_CLUSTER_NAME \ - ${DOCKER_RUN_ARGS} \ - do-ccm-e2e \ - ./scripts/cleanup-resources.sh -) \ No newline at end of file diff --git a/e2e/docker-run.sh b/e2e/docker.sh similarity index 83% rename from e2e/docker-run.sh rename to e2e/docker.sh index c11f86b95..19b90b0ee 100755 --- a/e2e/docker-run.sh +++ b/e2e/docker.sh @@ -18,6 +18,17 @@ set -o errexit set -o pipefail set -o nounset +COMMAND=${1:-} +TARGET_SCRIPT=$(case "${COMMAND}" in + (test) echo "e2e.sh";; + (clean) echo "scripts/cleanup-resources.sh";; +esac) + +if [ -z "${TARGET_SCRIPT}" ]; then + echo "usage: docker.sh test|clean" + exit 1 +fi + SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" PROJECT_DIR="${SCRIPT_DIR}/.." @@ -42,5 +53,5 @@ PROJECT_DIR="${SCRIPT_DIR}/.." -e KOPS_CLUSTER_NAME \ ${DOCKER_RUN_ARGS} \ do-ccm-e2e \ - ./e2e/e2e.sh + e2e/${TARGET_SCRIPT} ) \ No newline at end of file