diff options
Diffstat (limited to 'tests/platform-ci')
-rwxr-xr-x | tests/platform-ci/ci-build.sh | 77 |
1 files changed, 51 insertions, 26 deletions
diff --git a/tests/platform-ci/ci-build.sh b/tests/platform-ci/ci-build.sh index a156f314..21ea015f 100755 --- a/tests/platform-ci/ci-build.sh +++ b/tests/platform-ci/ci-build.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # This script will run create a virtual provider # and run tests on it. @@ -10,6 +10,12 @@ # * test provider: in provider/ # * leap-platform-test: installed in path # +# Todo: +# - Running locally works fine, now use it in gitlab CI ( which ssh-key ? create cloud.json from env vars ) +# - Speed up vm boot if possible ( right now 3-4mins ) + +# exit if any commands returns non-zero status +set -e # leap_platform/tests/platform-ci export ROOTDIR @@ -24,35 +30,54 @@ PROVIDERDIR="${ROOTDIR}/provider" export PLATFORMDIR PLATFORMDIR=$(readlink -f "${ROOTDIR}/../..") -# leap_platform/builds -export BUILDSDIR="${PLATFORMDIR}/builds" -export LOCKDIR="${PLATFORMDIR}/builds/lock" -export LOGDIR="${PLATFORMDIR}/builds/log" +LEAP_CMD="/usr/local/bin/bundle exec leap -v2 --yes" -export CONTACTS="sysdev@leap.se" -export MAIL_TO=$CONTACTS -export OPTS='--yes' -export FILTER_COMMON="" -export LEAP_CMD="bundle exec leap" - -echo "CI directory: ${ROOTDIR}" -echo "Provider directory: ${PROVIDERDIR}" -echo "Platform directory: ${PLATFORMDIR}" +# create node(s) with unique id so we can run tests in parallel +NAME="citest${CI_BUILD_ID}" +TAG='single' +SERVICES='couchdb,soledad,mx,webapp,tor,monitor' +SEEDS='sources.platform.apt.basic:http://deb.leap.se/experimental-0.9 sources.webapp.revision:develop sources.nickserver.revision:master' -# exit if any commands returns non-zero status -set -e -# create node(s) with unique id so we can run tests in parallel -export TAG="build${CI_BUILD_ID}" -[ -d "${PROVIDERDIR}/tags" ] || mkdir "${PROVIDERDIR}/tags" -echo '{}' > "${PROVIDERDIR}/tags/${TAG}.json" +# +# Main +# -export IP_SUFFIX_START='100' -export NODES="single${TAG}:couchdb,soledad,mx,webapp,openvpn,tor,monitor,obfsproxy" -leap-platform-test add_nodes "$NODES" -leap-platform-test -v init_deploy -leap-platform-test -v test +/bin/echo "CI directory: ${ROOTDIR}" +/bin/echo "Provider directory: ${PROVIDERDIR}" +/bin/echo "Platform directory: ${PLATFORMDIR}" cd "$PROVIDERDIR" + +# Ensure we don't output secret stuff to console even when running in verbose mode with -x +set +x + +# Create cloud.json needed for `leap vm` commands using AWS credentials +which jq || ( apt-get update -y && apt-get install jq -y ) +/usr/bin/jq ".platform_ci.auth |= .+ {\"aws_access_key_id\":\"$AWS_ACCESS_KEY\", \"aws_secret_access_key\":\"$AWS_SECRET_KEY\"}" < cloud.json.template > cloud.json + +# Configure ssh keypair +[ -d ~/.ssh ] || /bin/mkdir ~/.ssh +/bin/echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa +/bin/chmod 600 ~/.ssh/id_rsa +/bin/cp users/gitlab-runner/gitlab-runner_ssh.pub ~/.ssh/id_rsa.pub + +[ -d "./tags" ] || mkdir "./tags" +/bin/echo "{\"environment\": \"$TAG\"}" | /usr/bin/json_pp > "${PROVIDERDIR}/tags/${TAG}.json" + +$LEAP_CMD vm status "$TAG" +# shellcheck disable=SC2086 +$LEAP_CMD vm add "$NAME" services:"$SERVICES" tags:"$TAG" $SEEDS +$LEAP_CMD compile "$TAG" +$LEAP_CMD vm status "$TAG" + +$LEAP_CMD node init "$TAG" $LEAP_CMD info "${TAG}" -$LEAP_CMD local destroy "${TAG}" + +# Deploy and test +$LEAP_CMD deploy "$TAG" +$LEAP_CMD test "$TAG" + +# if everything succeeds, destroy the vm +$LEAP_CMD vm rm "${TAG}" +[ -f "nodes/${NAME}.json" ] && /bin/rm "nodes/${NAME}.json" |