diff --git a/.circle/add-itest-user.sh b/.circle/add-itest-user.sh new file mode 100755 index 0000000000..2b6f087efc --- /dev/null +++ b/.circle/add-itest-user.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -e + +# Create an SSH system user (default `stanley` user may be already created) +if (! id stanley 2>/dev/null); then + useradd stanley +fi + +mkdir -p /home/stanley/.ssh + +# Generate ssh keys on StackStorm box and copy over public key into remote box. +ssh-keygen -f /home/stanley/.ssh/stanley_rsa -P "" + +# Authorize key-base acces +sh -c 'cat /home/stanley/.ssh/stanley_rsa.pub >> /home/stanley/.ssh/authorized_keys' +chmod 0600 /home/stanley/.ssh/authorized_keys +chmod 0700 /home/stanley/.ssh +chown -R stanley:stanley /home/stanley + +# Enable passwordless sudo +sh -c 'echo "stanley ALL=(ALL) NOPASSWD: SETENV: ALL" >> /etc/sudoers.d/st2' +chmod 0440 /etc/sudoers.d/st2 diff --git a/.circle/buildenv_common.sh b/.circle/buildenv_common.sh new file mode 100755 index 0000000000..66df1b75be --- /dev/null +++ b/.circle/buildenv_common.sh @@ -0,0 +1,8 @@ +# Write export lines into ~/.buildenv and also source it in ~/.circlerc +write_env() { + for e in $*; do + eval "value=\$$e" + [ -z "$value" ] || echo "export $e=$value" >> ~/.buildenv + done + echo ". ~/.buildenv" >> ~/.circlerc +} diff --git a/.circle/buildenv_st2.sh b/.circle/buildenv_st2.sh new file mode 100755 index 0000000000..da259724fd --- /dev/null +++ b/.circle/buildenv_st2.sh @@ -0,0 +1,57 @@ +#!/bin/bash +set -e + +my_dir="$(dirname "$0")" +source "$my_dir/buildenv_common.sh" + +distros=($DISTROS) +DISTRO=${distros[$CIRCLE_NODE_INDEX]} + +fetch_version() { + if [ -f ../st2common/st2common/__init__.py ]; then + # Get st2 version based on hardcoded string in st2common + # build takes place in `st2` repo + python -c 'execfile("../st2common/st2common/__init__.py"); print __version__' + else + # build takes place in `st2-packages` repo + curl -sSL -o /tmp/st2_version.py ${ST2_GITURL}/raw/${ST2_GITREV}/st2common/st2common/__init__.py + python -c 'execfile("/tmp/st2_version.py"); print __version__' + fi +} + +# Needs explantion??? +st2_giturl() { + # Handle pull requests properly + if [ -z "$CIRCLE_PR_REPONAME" ]; then + echo "https://github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" + else + echo "https://github.com/${CIRCLE_PR_USERNAME}/${CIRCLE_PR_REPONAME}" + fi +} + +# --- +# ST2_GITURL - st2 GitHub repository (ex: https://github.com/StackStorm/st2) +# ST2_GITREV - st2 branch name (ex: master, v1.2.1). This will be used to determine correct Docker Tag: `latest`, `1.2.1` +# ST2PKG_VERSION - st2 version, will be reused in Docker image metadata (ex: 1.2dev) +# ST2PKG_RELEASE - Release number aka revision number for `st2` package, will be reused in Docker metadata (ex: 4) +# ST2_WAITFORSTART - Delay between st2 start and service checks + +ST2_GITURL=${ST2_GITURL:-$(st2_giturl)} +ST2_GITREV=${ST2_GITREV:-$CIRCLE_BRANCH} +ST2PKG_VERSION=$(fetch_version) +# for Bintray +#ST2PKG_RELEASE=$(.circle/bintray.sh next-revision ${DISTRO}_staging ${ST2PKG_VERSION} st2) +# for PackageCloud +if [ -z "$CIRCLE_PR_REPONAME" ]; then + ST2PKG_RELEASE=$(.circle/packagecloud.sh next-revision ${DISTRO} ${ST2PKG_VERSION} st2) +else + # is fork + ST2PKG_RELEASE=1 +fi + +re="\\b$DISTRO\\b" +[[ "$NOTESTS" =~ $re ]] && TESTING=0 + +write_env ST2_GITURL ST2_GITREV ST2PKG_VERSION ST2PKG_RELEASE ST2_WAITFORSTART DISTRO TESTING + +cat ~/.buildenv diff --git a/.circle/configure-postgres.sh b/.circle/configure-postgres.sh new file mode 100755 index 0000000000..ce76a517fc --- /dev/null +++ b/.circle/configure-postgres.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +CONFIG=$(cat < /etc/rabbitmq/rabbitmq.config +service rabbitmq-server start diff --git a/.circle/configure-services.sh b/.circle/configure-services.sh new file mode 100755 index 0000000000..b257d3693a --- /dev/null +++ b/.circle/configure-services.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e + +# change into script directory +cd $(dirname `readlink -f $0`) + +set -x +sudo ./configure-rabbitmq.sh +sudo ./configure-postgres.sh diff --git a/circle.yml b/circle.yml index 5d39f62d13..fb879972fe 100644 --- a/circle.yml +++ b/circle.yml @@ -6,15 +6,14 @@ # DOCKER_USER # DOCKER_EMAIL # DOCKER_PASSWORD + general: - # Don't run CI for PR, only for major branches + # Don't run CI for PR, only for major branches. + # Remove travis and enable per PR at the same time. branches: only: - master - /v[0-9]+\.[0-9]+/ - build_dir: st2-packages - artifacts: - - ~/packages notify: webhooks: @@ -22,76 +21,27 @@ notify: machine: environment: - DISTROS: "wheezy jessie trusty el6 el7" - NOTESTS: "el7" - ST2_PACKAGES_REPO: https://github.com/StackStorm/st2-packages - ST2_DOCKERFILES_REPO: https://github.com/StackStorm/st2-dockerfiles - ST2_PACKAGES: "st2" + ST2_REPO_ROOT_DIR: ${HOME}/${CIRCLE_PROJECT_REPONAME} BUILD_DOCKER: 0 - DEPLOY_DOCKER: 0 - DEPLOY_PACKAGES: 1 - pre: - - mkdir -p ~/packages - # Need latest Docker version for some features to work (CircleCI by default works with outdated version) - - | - sudo curl -L -o /usr/bin/docker 'http://s3-external-1.amazonaws.com/circle-downloads/docker-1.9.0-circleci' - sudo chmod 0755 /usr/bin/docker services: - docker - mongodb - postgresql - rabbitmq-server -checkout: - post: - - | - git clone --depth 1 ${ST2_PACKAGES_REPO} /home/ubuntu/st2/st2-packages - cd /home/ubuntu/st2/st2-packages - git checkout ${CIRCLE_BRANCH} || true - - .circle/buildenv_st2.sh - dependencies: cache_directories: - ~/.cache/pip pre: - sudo .circle/configure-services.sh - - sudo .circle/fix-cache-permissions.sh + - sudo .circle/add-itest-user.sh - sudo apt-get -y install parallel jq - - gem install package_cloud - - sudo pip install docker-compose - - docker-compose version - - docker version - override: - - .circle/docker-compose.sh pull ${DISTRO} post: - - .circle/docker-compose.sh build ${DISTRO} - + - cd ${ST2_REPO_ROOT_DIR} && hostname && make compile requirements test: override: - - .circle/docker-compose.sh test ${DISTRO}: + - case $CIRCLE_NODE_INDEX in 0) cd ${ST2_REPO_ROOT_DIR} && make .flake8 .pylint ;; 1) cd ${ST2_REPO_ROOT_DIR} && make .unit-tests-coverage-html clean ;; 2) cd ${ST2_REPO_ROOT_DIR} && make .itests-coverage-html clean ;; esac: parallel: true - # Copy all Packages to node0 - - rsync -rv /tmp/st2-packages/ node0:~/packages/${DISTRO}: - parallel: true - post: - - .circle/docker.sh build st2 - - .circle/docker.sh build st2actionrunner st2api st2auth st2exporter st2notifier st2resultstracker st2rulesengine st2sensorcontainer - - .circle/docker.sh run st2api - - .circle/docker.sh test st2api 'st2 --version' - -deployment: - publish: - owner: StackStorm - branch: - - master - - /v[0-9]+\.[0-9]+/ - commands: - # Deploy to PackageCloud all artifacts for respective distros in parallel - - | - DISTROS=($DISTROS) - parallel -v -j0 --line-buffer .circle/packagecloud.sh deploy {} ~/packages/{} ::: ${DISTROS[@]::$CIRCLE_NODE_TOTAL} - - .circle/docker.sh deploy st2actionrunner st2api st2auth st2exporter st2notifier st2resultstracker st2rulesengine st2sensorcontainer - - .circle/save_payload.py ~/packages experimental: notify: