Skip to content

Commit

Permalink
Enabling CouchDB unit-tests for all ARCH CI Environment
Browse files Browse the repository at this point in the history
Spinning up a CouchDB container in unit-test setup, and making necessary
config changes so that existing CouchDB unit-tests run as a part of
Continuous Integration (CI).

Change-Id: I4aabc587d9cba220b6385e410786b35230118a9a
Signed-off-by: Adnan Choudhury <adnan.choudhury@itpeoplecorp.com>
  • Loading branch information
adnan-c authored and krishvoor committed Feb 17, 2017
1 parent a5714ce commit be5e932
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 5 deletions.
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ JAVASHIM_DEPS = $(shell git ls-files core/chaincode/shim/java)
PROTOS = $(shell git ls-files *.proto | grep -v vendor)
MSP_SAMPLECONFIG = $(shell git ls-files msp/sampleconfig/*.pem)
PROJECT_FILES = $(shell git ls-files)
IMAGES = peer orderer ccenv javaenv buildenv testenv zookeeper kafka
IMAGES = peer orderer ccenv javaenv buildenv testenv zookeeper kafka couchdb

pkgmap.peer := $(PKGNAME)/peer
pkgmap.orderer := $(PKGNAME)/orderer
Expand Down Expand Up @@ -101,7 +101,9 @@ buildenv: build/image/buildenv/$(DUMMY)
build/image/testenv/$(DUMMY): build/image/buildenv/$(DUMMY)
testenv: build/image/testenv/$(DUMMY)

unit-test: peer-docker testenv
couchdb: build/image/couchdb/$(DUMMY)

unit-test: peer-docker testenv couchdb
cd unit-test && docker-compose up --abort-on-container-exit --force-recreate && docker-compose down

unit-tests: unit-test
Expand Down Expand Up @@ -195,6 +197,9 @@ build/image/testenv/payload: build/docker/bin/orderer \
build/image/zookeeper/payload: images/zookeeper/docker-entrypoint.sh
build/image/kafka/payload: images/kafka/docker-entrypoint.sh \
images/kafka/kafka-run-class.sh
build/image/couchdb/payload: images/couchdb/docker-entrypoint.sh \
images/couchdb/local.ini \
images/couchdb/vm.args

build/image/%/payload:
mkdir -p $@
Expand Down
10 changes: 7 additions & 3 deletions core/ledger/util/couchdb/couchdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ import (
"github.com/hyperledger/fabric/common/ledger/testutil"
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
ledgertestutil "github.com/hyperledger/fabric/core/ledger/testutil"
"github.com/spf13/viper"
)

//Basic setup to test couch
var connectURL = "localhost:5984"
var badConnectURL = "localhost:5990"
var connectURL = "couchdb:5984"
var badConnectURL = "couchdb:5990"
var database = "couch_util_testdb"
var username = ""
var password = ""
Expand All @@ -56,7 +57,10 @@ var assetJSON = []byte(`{"asset_name":"marble1","color":"blue","size":"35","owne

func TestMain(m *testing.M) {
ledgertestutil.SetupCoreYAMLConfig("./../../../../peer")
os.Exit(m.Run())
viper.Set("ledger.state.stateDatabase", "CouchDB")
result := m.Run()
viper.Set("ledger.state.stateDatabase", "goleveldb")
os.Exit(result)
}

func TestDBConnectionDef(t *testing.T) {
Expand Down
75 changes: 75 additions & 0 deletions images/couchdb/Dockerfile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
FROM hyperledger/fabric-baseimage:_BASE_TAG_

# Based on https://github.com/klaemo/docker-couchdb/blob/master/2.0.0/Dockerfile

# Add CouchDB user account
RUN groupadd -r couchdb && useradd -d /opt/couchdb -g couchdb couchdb

RUN apt-get update -y && apt-get install -y --no-install-recommends \
ca-certificates \
curl \
erlang-nox \
erlang-reltool \
haproxy \
libicu5. \
libmozjs185-1.0 \
openssl \
cmake \
apt-transport-https \
gcc \
g++ \
erlang-dev \
libcurl4-openssl-dev \
libicu-dev \
libmozjs185-dev \
make \
&& rm -rf /var/lib/apt/lists/*

# Grab su-exec and tini
RUN set -x \
&& git clone https://github.com/ncopa/su-exec /tmp/su-exec/ \
&& cd /tmp/su-exec \
&& make all \
&& cp su-exec /usr/bin/ \
&& git clone https://github.com/krallin/tini/ /tmp/tini/ \
&& cd /tmp/tini/ \
&& git checkout v0.14.0 \
&& cmake . && make \
&& cp tini tini-static /usr/local/bin/ \
# Clean up su-exec and tini
&& rm -rf /tmp/tini \
&& rm -rf /tmp/su-exec

ARG COUCHDB_VERSION=2.0.0

# Download dev dependencies
RUN set -x \
&& npm install -g grunt-cli \
# Acquire CouchDB source code
&& cd /usr/src && mkdir couchdb \
&& curl -fSL https://dist.apache.org/repos/dist/release/couchdb/source/$COUCHDB_VERSION/apache-couchdb-$COUCHDB_VERSION.tar.gz -o couchdb.tar.gz \
&& tar -xzf couchdb.tar.gz -C couchdb --strip-components=1 \
&& cd couchdb \
# Build the release and install into /opt
&& ./configure --disable-docs \
&& make release \
&& mv /usr/src/couchdb/rel/couchdb /opt/ \
# Cleanup build detritus
&& rm -rf /var/lib/apt/lists/* /usr/lib/node_modules /usr/src/couchdb*

# Add configuration
COPY payload/local.ini /opt/couchdb/etc/local.d/
COPY payload/vm.args /opt/couchdb/etc/
COPY payload/docker-entrypoint.sh /

# Setup directories and permissions
RUN chmod +x /docker-entrypoint.sh \
&& mkdir /opt/couchdb/data /opt/couchdb/etc/default.d \
&& chown -R couchdb:couchdb /opt/couchdb/

WORKDIR /opt/couchdb
EXPOSE 5984 4369 9100
VOLUME ["/opt/couchdb/data"]

ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"]
CMD ["/opt/couchdb/bin/couchdb"]
57 changes: 57 additions & 0 deletions images/couchdb/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash
# 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 -e

if [ "$1" = '/opt/couchdb/bin/couchdb' ]; then
# we need to set the permissions here because docker mounts volumes as root
chown -R couchdb:couchdb /opt/couchdb

chmod -R 0770 /opt/couchdb/data

chmod 664 /opt/couchdb/etc/*.ini
chmod 664 /opt/couchdb/etc/local.d/*.ini
chmod 775 /opt/couchdb/etc/*.d

if [ ! -z "$NODENAME" ] && ! grep "couchdb@" /opt/couchdb/etc/vm.args; then
echo "-name couchdb@$NODENAME" >> /opt/couchdb/etc/vm.args
fi

if [ "$COUCHDB_USER" ] && [ "$COUCHDB_PASSWORD" ]; then
# Create admin
printf "[admins]\n%s = %s\n" "$COUCHDB_USER" "$COUCHDB_PASSWORD" > /opt/couchdb/etc/local.d/docker.ini
chown couchdb:couchdb /opt/couchdb/etc/local.d/docker.ini
fi

# if we don't find an [admins] section followed by a non-comment, display a warning
if ! grep -Pzoqr '\[admins\]\n[^;]\w+' /opt/couchdb/etc/local.d/*.ini; then
# The - option suppresses leading tabs but *not* spaces. :)
cat >&2 <<-'EOWARN'
****************************************************
WARNING: CouchDB is running in Admin Party mode.
This will allow anyone with access to the
CouchDB port to access your database. In
Docker's default configuration, this is
effectively any other container on the same
system.
Use "-e COUCHDB_USER=admin -e COUCHDB_PASSWORD=password"
to set it in "docker run".
****************************************************
EOWARN
fi


exec su-exec couchdb "$@"
fi

exec "$@"
8 changes: 8 additions & 0 deletions images/couchdb/local.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
; CouchDB Configuration Settings

; Custom settings should be made in this file. They will override settings
; in default.ini, but unlike changes made to default.ini, this file won't be
; overwritten on server upgrade.

[chttpd]
bind_address = any
28 changes: 28 additions & 0 deletions images/couchdb/vm.args
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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.

# Ensure that the Erlang VM listens on a known port
-kernel inet_dist_listen_min 9100
-kernel inet_dist_listen_max 9100

# Tell kernel and SASL not to log anything
-kernel error_logger silent
-sasl sasl_error_logger false

# Use kernel poll functionality if supported by emulator
+K true

# Start a pool of asynchronous IO threads
+A 16

# Comment this line out to enable the interactive Erlang shell on startup
+Bd -noinput
9 changes: 9 additions & 0 deletions unit-test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ unit-tests:
image: hyperledger/fabric-testenv
links:
- vp
- couchdb
environment:
- UNIT_TEST_PEER_IP=vp
- GO_LDFLAGS
Expand All @@ -23,3 +24,11 @@ unit-tests:
- /var/run/docker.sock:/var/run/docker.sock
- ${GOPATH}/src/github.com/hyperledger/fabric:/opt/gopath/src/github.com/hyperledger/fabric
command: ./unit-test/run.sh

couchdb:
container_name: couchdb
image: hyperledger/fabric-couchdb
log_driver: none
ports:
- "5984:5984"

0 comments on commit be5e932

Please sign in to comment.