From 8d18c33f5aa5a3b47634bd8dc7c1ce5df1b97d82 Mon Sep 17 00:00:00 2001 From: Ying Li Date: Thu, 17 Mar 2016 11:07:54 -0700 Subject: [PATCH] Use a container to run the client integration tests Signed-off-by: Ying Li --- .build/integrationtest.sh | 44 +++++++++++++-------------------------- .build/testclient.sh | 23 ++++++++------------ Makefile | 3 +++ circle.yml | 7 ++++++- development.yml | 34 ++++++++++++++++++++++++++++++ 5 files changed, 66 insertions(+), 45 deletions(-) create mode 100644 development.yml diff --git a/.build/integrationtest.sh b/.build/integrationtest.sh index 9f73eec2b4..0c949eb53a 100755 --- a/.build/integrationtest.sh +++ b/.build/integrationtest.sh @@ -1,39 +1,23 @@ #!/usr/bin/env bash +function cleanup { + docker-compose -f development.yml stop + # if we're in CircleCI, we cannot remove any containers + if [[ -z "${CIRCLECI}" ]]; then + docker-compose -f development.yml rm -f + fi +} +if [[ -z "${CIRCLECI}" ]]; then + BUILDOPTS="--force-rm" +fi set -e set -x -function finish { - docker-compose stop - if [[ -n "${COMPOSE_PID}" ]]; then - kill "${COMPOSE_PID}" || true - fi - if [[ -n "${TEST_PID}" ]]; then - kill "${TEST_PID}" || true - fi -} +cleanup -docker-compose stop +docker-compose -f development.yml build ${BUILDOPTS} +docker-compose -f development.yml up --abort-on-container-exit -# if we're in CircleCI, we cannot remove any containers -if [[ -z "${CIRCLECI}" ]]; then - docker-compose rm -f -fi - -docker-compose build -docker-compose up --abort-on-container-exit >> /dev/null & -COMPOSE_PID=$! - - -.build/testclient.sh & -TEST_PID=$! - -set +x - -wait ${TEST_PID} - -(docker-compose logs &) - -trap finish SIGINT SIGTERM EXIT +trap cleanup SIGINT SIGTERM EXIT diff --git a/.build/testclient.sh b/.build/testclient.sh index d60c396670..cc244ed0f1 100755 --- a/.build/testclient.sh +++ b/.build/testclient.sh @@ -2,21 +2,17 @@ set -e -RANDOMSTRING="$(cat /dev/urandom | env LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1)" -HOST="${REMOTE_SERVER_URL:-https://localhost:4443}" +make client -OPTS="-c cmd/notary/config.json -d /tmp/${RANDOMSTRING}" -if [[ -n "${DOCKER_HOST}" ]]; then - if [[ "$(resolveip -s notary-server)" == *"${DOCKER_HOST}"* ]]; then - echo "This test is going to fail since the client doesn't have a trusted CA root for ${HOST}" - exit 1 - fi - HOST="${REMOTE_SERVER_URL:-https://notary-server:4443}" - OPTS="$OPTS -s ${HOST}" -fi +set +e + +RANDOMSTRING="$(cat /dev/urandom | env LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1)" +HOST="${REMOTE_SERVER_URL:-https://notary-server:4443}" REPONAME="docker.com/notary/${RANDOMSTRING}" +OPTS="-c cmd/notary/config.json -d /tmp/${RANDOMSTRING}" + export NOTARY_ROOT_PASSPHRASE=ponies export NOTARY_TARGETS_PASSPHRASE=ponies export NOTARY_SNAPSHOT_PASSPHRASE=ponies @@ -29,7 +25,7 @@ echo rm -rf "/tmp/${RANDOMSTRING}" iter=0 -until curl -k "${HOST}" +until (curl -s -S -k "${HOST}") do ((iter++)) if (( iter > 30 )); then @@ -40,10 +36,9 @@ do sleep 1 done +set -e set -x -make client - bin/notary ${OPTS} init ${REPONAME} bin/notary ${OPTS} delegation add ${REPONAME} targets/releases fixtures/secure.example.com.crt --all-paths bin/notary ${OPTS} add ${REPONAME} readmetarget README.md diff --git a/Makefile b/Makefile index 2b500bbc5a..5b10712ed7 100644 --- a/Makefile +++ b/Makefile @@ -170,6 +170,9 @@ covmerge: clean-protos: @rm proto/*.pb.go +client: ${PREFIX}/bin/notary + @echo "+ $@" + binaries: ${PREFIX}/bin/notary-server ${PREFIX}/bin/notary ${PREFIX}/bin/notary-signer @echo "+ $@" diff --git a/circle.yml b/circle.yml index 58dc98aa96..4d47c6f697 100644 --- a/circle.yml +++ b/circle.yml @@ -3,10 +3,15 @@ machine: pre: # Install gvm - bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/1.0.22/binscripts/gvm-installer) + # Upgrade docker + - sudo curl -L -o /usr/bin/docker 'https://s3-external-1.amazonaws.com/circle-downloads/docker-1.9.1-circleci' + - sudo chmod 0755 /usr/bin/docker post: # Install many go versions - gvm install go1.6 -B --name=stable + # upgrade compose + - sudo pip install --upgrade docker-compose services: - docker @@ -80,6 +85,6 @@ test: post: # Report to codecov.io - - bash <(curl -s https://codecov.io/bash): + - case $CIRCLE_NODE_INDEX in 0) bash <(curl -s https://codecov.io/bash) ;; 1) bash <(curl -s https://codecov.io/bash) ;; esac: parallel: true pwd: $BASE_STABLE diff --git a/development.yml b/development.yml new file mode 100644 index 0000000000..328715a9ee --- /dev/null +++ b/development.yml @@ -0,0 +1,34 @@ +server: + build: . + dockerfile: server.Dockerfile + links: + - mysql + - signer + - signer:notarysigner + environment: + - SERVICE_NAME=notary_server + entrypoint: /bin/bash + command: -c "./migrations/migrate.sh && notary-server -config=fixtures/server-config.json" +signer: + build: . + dockerfile: signer.Dockerfile + links: + - mysql + environment: + - SERVICE_NAME=notary_signer + entrypoint: /bin/bash + command: -c "./migrations/migrate.sh && notary-signer -config=fixtures/signer-config.json" +mysql: + volumes: + - ./notarymysql/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d + image: mariadb:10.1.10 + environment: + - TERM=dumb + - MYSQL_ALLOW_EMPTY_PASSWORD="true" + command: mysqld --innodb_file_per_table +client: + build: . + dockerfile: Dockerfile + links: + - server:notary-server + command: .build/testclient.sh