JAVA-71 | added custom dockerfile to run preconfigured couchbase instance (#14663)
This commit is contained in:
parent
5b29d1d999
commit
e9d8fd0f55
|
@ -0,0 +1,4 @@
|
|||
FROM couchbase/server:community-5.0.1
|
||||
|
||||
COPY configure.sh /configure.sh
|
||||
CMD ["/configure.sh"]
|
|
@ -0,0 +1,106 @@
|
|||
#!/bin/bash
|
||||
|
||||
function retry() {
|
||||
for i in $(seq 1 10); do
|
||||
$1 "$2"
|
||||
if [[ $? == 0 ]]; then
|
||||
return 0
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
function bucketCreate(){
|
||||
couchbase-cli bucket-create -c localhost -u Administrator -p password \
|
||||
--bucket="$1" \
|
||||
--bucket-type=couchbase \
|
||||
--bucket-ramsize=512 \
|
||||
--bucket-replica=1 \
|
||||
--wait
|
||||
if [[ $? != 0 ]]; then
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function userCreate(){
|
||||
createOutput=$(couchbase-cli user-manage -c localhost -u Administrator -p password \
|
||||
--set --rbac-username "$1" --rbac-password "$1" \
|
||||
--roles admin --auth-domain local)
|
||||
if [[ $? != 0 ]]; then
|
||||
echo $createOutput >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function clusterUp(){
|
||||
# wait for service to come up
|
||||
until $(curl --output /dev/null --silent --head --fail http://localhost:8091); do
|
||||
printf '.'
|
||||
sleep 1
|
||||
done
|
||||
|
||||
# initialize cluster
|
||||
initOutput=$(couchbase-cli cluster-init -c localhost \
|
||||
--cluster-username=Administrator \
|
||||
--cluster-password=password \
|
||||
--cluster-port=8091 \
|
||||
--services=data,index,query,fts \
|
||||
--cluster-ramsize=1024 \
|
||||
--cluster-index-ramsize=256 \
|
||||
--cluster-fts-ramsize=256 \
|
||||
--index-storage-setting=default)
|
||||
if [[ $? != 0 ]]; then
|
||||
echo $initOutput >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function main(){
|
||||
set -ex
|
||||
echo "Couchbase UI :8091"
|
||||
echo "Couchbase logs /opt/couchbase/var/lib/couchbase/logs"
|
||||
./entrypoint.sh couchbase-server &
|
||||
if [[ $? != 0 ]]; then
|
||||
echo "Couchbase startup failed. Exiting." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
clusterUp
|
||||
if [[ $? != 0 ]]; then
|
||||
echo "Cluster init failed. Exiting." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
retry userCreate baeldung
|
||||
if [[ $? != 0 ]]; then
|
||||
echo "User create failed. Exiting." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
retry userCreate baeldung2
|
||||
if [[ $? != 0 ]]; then
|
||||
echo "User create failed. Exiting." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
retry bucketCreate baeldung
|
||||
if [[ $? != 0 ]]; then
|
||||
echo "Bucket create failed. Exiting." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
retry bucketCreate baeldung2
|
||||
if [[ $? != 0 ]]; then
|
||||
echo "Bucket create failed. Exiting." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
set +ex
|
||||
|
||||
# entrypoint.sh launches the server but since config.sh is pid 1 we keep it
|
||||
# running so that the docker container does not exit.
|
||||
wait
|
||||
}
|
||||
|
||||
main
|
|
@ -0,0 +1,14 @@
|
|||
#!/bin/bash
|
||||
|
||||
# setup
|
||||
set -ex
|
||||
docker rm couchbase_container -f
|
||||
|
||||
# main
|
||||
docker build -t couchbase_image .
|
||||
|
||||
# cleanup
|
||||
set +ex
|
||||
|
||||
# run
|
||||
docker run -d --name couchbase_container -p 8091-8096:8091-8096 -p 11210-11211:11210-11211 couchbase_image
|
|
@ -12,16 +12,10 @@ import org.springframework.test.context.support.DependencyInjectionTestExecution
|
|||
/**
|
||||
* This LiveTest requires:
|
||||
*
|
||||
* 1- Couchbase instance running (e.g. with `docker run -d --name db -p 8091-8096:8091-8096 -p 11210-11211:11210-11211 couchbase`)
|
||||
*
|
||||
*
|
||||
* 2- Couchbase configured with (we can use the console in localhost:8091):
|
||||
*
|
||||
* 2.1- Buckets: named 'baeldung' and 'baeldung2'
|
||||
*
|
||||
* 2.2- Security: users 'baeldung' and 'baeldung2'. Note: in newer versions an empty password is not allowed, then we have to change the passwords in the project)
|
||||
*
|
||||
* 2.3- Spacial View: Add new spacial view (in Index tab) in document 'campus_spatial', view 'byLocation' with the following function:
|
||||
* 1- Couchbase 5 instance Running and Configured.
|
||||
* It's enough to execute the "dockerbuild.sh" script in the test/docker folder.
|
||||
*
|
||||
* 2.1- Spacial View: Add new spacial view (in Index tab) in document 'campus_spatial', view 'byLocation' with the following function:
|
||||
* {@code
|
||||
* function (doc) {
|
||||
* if (doc.location &&
|
||||
|
@ -30,8 +24,9 @@ import org.springframework.test.context.support.DependencyInjectionTestExecution
|
|||
* }
|
||||
* }}
|
||||
*
|
||||
* 2.4- MapReduce Views: Add new views in document 'campus':
|
||||
* 2.4.1- view 'all' with function:
|
||||
* 2.2- MapReduce Views: Add new views in document 'campus':
|
||||
*
|
||||
* 2.2.1- view 'all' with function:
|
||||
* {@code
|
||||
* function (doc, meta) {
|
||||
* if(doc._class == "com.baeldung.spring.data.couchbase.model.Campus") {
|
||||
|
@ -39,7 +34,7 @@ import org.springframework.test.context.support.DependencyInjectionTestExecution
|
|||
* }
|
||||
* }}
|
||||
*
|
||||
* 2.4.2- view 'byName' with function:
|
||||
* 2.2.2- view 'byName' with function:
|
||||
* {@code
|
||||
* function (doc, meta) {
|
||||
* if(doc._class == "com.baeldung.spring.data.couchbase.model.Campus" &&
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
package com.baeldung.spring.data.couchbase;
|
||||
|
||||
import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter;
|
||||
|
||||
public class CustomTypeKeyCouchbaseConfig extends MyCouchbaseConfig {
|
||||
|
||||
@Override
|
||||
public String getConnectionString() {
|
||||
return NODE_LIST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUserName() {
|
||||
return BUCKET_USERNAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return BUCKET_PASSWORD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String typeKey() {
|
||||
return MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE;
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package com.baeldung.spring.data.couchbase;
|
||||
|
||||
import com.couchbase.client.java.query.QueryScanConsistency;
|
||||
|
||||
public class ReadYourOwnWritesCouchbaseConfig extends MyCouchbaseConfig {
|
||||
|
||||
@Override
|
||||
public QueryScanConsistency getDefaultConsistency() {
|
||||
return QueryScanConsistency.REQUEST_PLUS;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue