Skip to content

Commit be5e932

Browse files
adnan-cKrishna Harsha Voora
authored andcommitted
Enabling CouchDB unit-tests for all ARCH CI Environment
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>
1 parent a5714ce commit be5e932

File tree

7 files changed

+191
-5
lines changed

7 files changed

+191
-5
lines changed

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ JAVASHIM_DEPS = $(shell git ls-files core/chaincode/shim/java)
6464
PROTOS = $(shell git ls-files *.proto | grep -v vendor)
6565
MSP_SAMPLECONFIG = $(shell git ls-files msp/sampleconfig/*.pem)
6666
PROJECT_FILES = $(shell git ls-files)
67-
IMAGES = peer orderer ccenv javaenv buildenv testenv zookeeper kafka
67+
IMAGES = peer orderer ccenv javaenv buildenv testenv zookeeper kafka couchdb
6868

6969
pkgmap.peer := $(PKGNAME)/peer
7070
pkgmap.orderer := $(PKGNAME)/orderer
@@ -101,7 +101,9 @@ buildenv: build/image/buildenv/$(DUMMY)
101101
build/image/testenv/$(DUMMY): build/image/buildenv/$(DUMMY)
102102
testenv: build/image/testenv/$(DUMMY)
103103

104-
unit-test: peer-docker testenv
104+
couchdb: build/image/couchdb/$(DUMMY)
105+
106+
unit-test: peer-docker testenv couchdb
105107
cd unit-test && docker-compose up --abort-on-container-exit --force-recreate && docker-compose down
106108

107109
unit-tests: unit-test
@@ -195,6 +197,9 @@ build/image/testenv/payload: build/docker/bin/orderer \
195197
build/image/zookeeper/payload: images/zookeeper/docker-entrypoint.sh
196198
build/image/kafka/payload: images/kafka/docker-entrypoint.sh \
197199
images/kafka/kafka-run-class.sh
200+
build/image/couchdb/payload: images/couchdb/docker-entrypoint.sh \
201+
images/couchdb/local.ini \
202+
images/couchdb/vm.args
198203

199204
build/image/%/payload:
200205
mkdir -p $@

core/ledger/util/couchdb/couchdb_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ import (
2626
"github.com/hyperledger/fabric/common/ledger/testutil"
2727
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
2828
ledgertestutil "github.com/hyperledger/fabric/core/ledger/testutil"
29+
"github.com/spf13/viper"
2930
)
3031

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

5758
func TestMain(m *testing.M) {
5859
ledgertestutil.SetupCoreYAMLConfig("./../../../../peer")
59-
os.Exit(m.Run())
60+
viper.Set("ledger.state.stateDatabase", "CouchDB")
61+
result := m.Run()
62+
viper.Set("ledger.state.stateDatabase", "goleveldb")
63+
os.Exit(result)
6064
}
6165

6266
func TestDBConnectionDef(t *testing.T) {

images/couchdb/Dockerfile.in

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
FROM hyperledger/fabric-baseimage:_BASE_TAG_
2+
3+
# Based on https://github.com/klaemo/docker-couchdb/blob/master/2.0.0/Dockerfile
4+
5+
# Add CouchDB user account
6+
RUN groupadd -r couchdb && useradd -d /opt/couchdb -g couchdb couchdb
7+
8+
RUN apt-get update -y && apt-get install -y --no-install-recommends \
9+
ca-certificates \
10+
curl \
11+
erlang-nox \
12+
erlang-reltool \
13+
haproxy \
14+
libicu5. \
15+
libmozjs185-1.0 \
16+
openssl \
17+
cmake \
18+
apt-transport-https \
19+
gcc \
20+
g++ \
21+
erlang-dev \
22+
libcurl4-openssl-dev \
23+
libicu-dev \
24+
libmozjs185-dev \
25+
make \
26+
&& rm -rf /var/lib/apt/lists/*
27+
28+
# Grab su-exec and tini
29+
RUN set -x \
30+
&& git clone https://github.com/ncopa/su-exec /tmp/su-exec/ \
31+
&& cd /tmp/su-exec \
32+
&& make all \
33+
&& cp su-exec /usr/bin/ \
34+
&& git clone https://github.com/krallin/tini/ /tmp/tini/ \
35+
&& cd /tmp/tini/ \
36+
&& git checkout v0.14.0 \
37+
&& cmake . && make \
38+
&& cp tini tini-static /usr/local/bin/ \
39+
# Clean up su-exec and tini
40+
&& rm -rf /tmp/tini \
41+
&& rm -rf /tmp/su-exec
42+
43+
ARG COUCHDB_VERSION=2.0.0
44+
45+
# Download dev dependencies
46+
RUN set -x \
47+
&& npm install -g grunt-cli \
48+
# Acquire CouchDB source code
49+
&& cd /usr/src && mkdir couchdb \
50+
&& curl -fSL https://dist.apache.org/repos/dist/release/couchdb/source/$COUCHDB_VERSION/apache-couchdb-$COUCHDB_VERSION.tar.gz -o couchdb.tar.gz \
51+
&& tar -xzf couchdb.tar.gz -C couchdb --strip-components=1 \
52+
&& cd couchdb \
53+
# Build the release and install into /opt
54+
&& ./configure --disable-docs \
55+
&& make release \
56+
&& mv /usr/src/couchdb/rel/couchdb /opt/ \
57+
# Cleanup build detritus
58+
&& rm -rf /var/lib/apt/lists/* /usr/lib/node_modules /usr/src/couchdb*
59+
60+
# Add configuration
61+
COPY payload/local.ini /opt/couchdb/etc/local.d/
62+
COPY payload/vm.args /opt/couchdb/etc/
63+
COPY payload/docker-entrypoint.sh /
64+
65+
# Setup directories and permissions
66+
RUN chmod +x /docker-entrypoint.sh \
67+
&& mkdir /opt/couchdb/data /opt/couchdb/etc/default.d \
68+
&& chown -R couchdb:couchdb /opt/couchdb/
69+
70+
WORKDIR /opt/couchdb
71+
EXPOSE 5984 4369 9100
72+
VOLUME ["/opt/couchdb/data"]
73+
74+
ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"]
75+
CMD ["/opt/couchdb/bin/couchdb"]

images/couchdb/docker-entrypoint.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
3+
# use this file except in compliance with the License. You may obtain a copy of
4+
# the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
# License for the specific language governing permissions and limitations under
12+
# the License.
13+
14+
set -e
15+
16+
if [ "$1" = '/opt/couchdb/bin/couchdb' ]; then
17+
# we need to set the permissions here because docker mounts volumes as root
18+
chown -R couchdb:couchdb /opt/couchdb
19+
20+
chmod -R 0770 /opt/couchdb/data
21+
22+
chmod 664 /opt/couchdb/etc/*.ini
23+
chmod 664 /opt/couchdb/etc/local.d/*.ini
24+
chmod 775 /opt/couchdb/etc/*.d
25+
26+
if [ ! -z "$NODENAME" ] && ! grep "couchdb@" /opt/couchdb/etc/vm.args; then
27+
echo "-name couchdb@$NODENAME" >> /opt/couchdb/etc/vm.args
28+
fi
29+
30+
if [ "$COUCHDB_USER" ] && [ "$COUCHDB_PASSWORD" ]; then
31+
# Create admin
32+
printf "[admins]\n%s = %s\n" "$COUCHDB_USER" "$COUCHDB_PASSWORD" > /opt/couchdb/etc/local.d/docker.ini
33+
chown couchdb:couchdb /opt/couchdb/etc/local.d/docker.ini
34+
fi
35+
36+
# if we don't find an [admins] section followed by a non-comment, display a warning
37+
if ! grep -Pzoqr '\[admins\]\n[^;]\w+' /opt/couchdb/etc/local.d/*.ini; then
38+
# The - option suppresses leading tabs but *not* spaces. :)
39+
cat >&2 <<-'EOWARN'
40+
****************************************************
41+
WARNING: CouchDB is running in Admin Party mode.
42+
This will allow anyone with access to the
43+
CouchDB port to access your database. In
44+
Docker's default configuration, this is
45+
effectively any other container on the same
46+
system.
47+
Use "-e COUCHDB_USER=admin -e COUCHDB_PASSWORD=password"
48+
to set it in "docker run".
49+
****************************************************
50+
EOWARN
51+
fi
52+
53+
54+
exec su-exec couchdb "$@"
55+
fi
56+
57+
exec "$@"

images/couchdb/local.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
; CouchDB Configuration Settings
2+
3+
; Custom settings should be made in this file. They will override settings
4+
; in default.ini, but unlike changes made to default.ini, this file won't be
5+
; overwritten on server upgrade.
6+
7+
[chttpd]
8+
bind_address = any

images/couchdb/vm.args

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
2+
# use this file except in compliance with the License. You may obtain a copy of
3+
# the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations under
11+
# the License.
12+
13+
# Ensure that the Erlang VM listens on a known port
14+
-kernel inet_dist_listen_min 9100
15+
-kernel inet_dist_listen_max 9100
16+
17+
# Tell kernel and SASL not to log anything
18+
-kernel error_logger silent
19+
-sasl sasl_error_logger false
20+
21+
# Use kernel poll functionality if supported by emulator
22+
+K true
23+
24+
# Start a pool of asynchronous IO threads
25+
+A 16
26+
27+
# Comment this line out to enable the interactive Erlang shell on startup
28+
+Bd -noinput

unit-test/docker-compose.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ unit-tests:
1313
image: hyperledger/fabric-testenv
1414
links:
1515
- vp
16+
- couchdb
1617
environment:
1718
- UNIT_TEST_PEER_IP=vp
1819
- GO_LDFLAGS
@@ -23,3 +24,11 @@ unit-tests:
2324
- /var/run/docker.sock:/var/run/docker.sock
2425
- ${GOPATH}/src/github.com/hyperledger/fabric:/opt/gopath/src/github.com/hyperledger/fabric
2526
command: ./unit-test/run.sh
27+
28+
couchdb:
29+
container_name: couchdb
30+
image: hyperledger/fabric-couchdb
31+
log_driver: none
32+
ports:
33+
- "5984:5984"
34+

0 commit comments

Comments
 (0)