Skip to content

Commit

Permalink
Merge pull request #8 from misterbisson/4beta
Browse files Browse the repository at this point in the history
Couchbase 4 image
  • Loading branch information
misterbisson committed Oct 19, 2015
2 parents 06b0c75 + be3e9ba commit 7806af9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 53 deletions.
30 changes: 1 addition & 29 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,9 @@
#
# Triton-optimized Couchbase
#
FROM centos:centos6.6
FROM couchbase/server:enterprise-4.0.0
MAINTAINER Casey Bisson <[email protected]>

#
# Install yum dependencies
#
RUN yum install -y tar \
&& yum clean all

#
# Install gosu for startup script
#
RUN gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
&& curl -o /usr/local/bin/gosu -sSL "https://github.com/tianon/gosu/releases/download/1.4/gosu-amd64" \
&& curl -o /usr/local/bin/gosu.asc -sSL "https://github.com/tianon/gosu/releases/download/1.4/gosu-amd64.asc" \
&& gpg --verify /usr/local/bin/gosu.asc \
&& rm /usr/local/bin/gosu.asc \
&& chmod +x /usr/local/bin/gosu

#
# Set Couchbase install vars
#
ENV CB_VERSION=3.0.3 \
CB_RELEASE_URL=http://packages.couchbase.com/releases \
CB_PACKAGE=couchbase-server-enterprise-3.0.3-centos6.x86_64.rpm \
PATH=$PATH:/opt/couchbase/bin:/opt/couchbase/bin/tools:/opt/couchbase/bin/install

# Install Couchbase
RUN rpm --install $CB_RELEASE_URL/$CB_VERSION/$CB_PACKAGE


#
# Install Node.js
# similar to https://github.com/joyent/docker-node/blob/428d5e69763aad1f2d8f17c883112850535e8290/0.12/Dockerfile
Expand Down
58 changes: 35 additions & 23 deletions bin/triton-bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@
#

# This container's IP(s)
export MYIPPRIVATE=$(ip addr show eth0 | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}')
export MYIPPUBLIC=$(ip addr show eth1 | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}')
export IP_PRIVATE=$(ip addr show eth0 | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}')
IP_HAVEPUBLIC=$(ip link show | grep eth1)
if [[ $IP_HAVEPUBLIC ]]
then
export IP_PUBLIC=$(ip addr show eth1 | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}')
else
export IP_PUBLIC=$IP_PRIVATE
fi

# Discovery vars
export COUCHBASE_SERVICE_NAME=${COUCHBASE_SERVICE_NAME:-couchbase}
Expand All @@ -23,25 +29,25 @@ export COUCHBASE_PASS=${COUCHBASE_PASS:-password}
export COUCHBASE_BUCKET=$2

# Couchbase resource limits
export MYMEMORY=$(free -m | grep -o "Mem:\s*[0-9]*" | grep -o "[0-9]*")
export MYCPUS=$(nproc)
export MYCPUS=$(($MYCPUS>12?$(($MYMEMORY/3072)):$MYCPUS))
export MYCPUS=$(($MYCPUS>1?$MYCPUS:1))
export COUCHBASE_NS_SERVER_VM_EXTRA_ARGS=$(printf '["+S", "%s"]' $MYCPUS)
export ERL_AFLAGS="+S $MYCPUS"
export GOMAXPROCS=$MYCPUS
export MYMEMORY=$((($MYMEMORY/10)*8))
export AVAIL_MEMORY=$(free -m | grep -o "Mem:\s*[0-9]*" | grep -o "[0-9]*")
export AVAIL_CPUS=$(nproc)
export COUCHBASE_CPUS=$(($AVAIL_CPUS>8?8:$AVAIL_CPUS))
export COUCHBASE_CPUS=$(($COUCHBASE_CPUS>1?$COUCHBASE_CPUS:1))
export COUCHBASE_NS_SERVER_VM_EXTRA_ARGS=$(printf '["+S", "%s"]' $COUCHBASE_CPUS)
export ERL_AFLAGS="+S $COUCHBASE_CPUS"
export GOMAXPROCS=$COUCHBASE_CPUS
export COUCHBASE_MEMORY=$((($AVAIL_MEMORY/10)*7))

installed ()
{
echo
echo '#'
echo '# Couchbase is installed and configured'
echo '#'
echo "# Dashboard: http://$MYIPPUBLIC:8091"
echo "# Internal IP: $MYIPPRIVATE"
echo "# username: $COUCHBASE_USER"
echo "# password: $COUCHBASE_PASS"
echo "# Dashboard: http://$IP_PUBLIC:8091"
echo "# Internal IP: $IP_PRIVATE"
echo "# Username: $COUCHBASE_USER"
echo "# Password: $COUCHBASE_PASS"
echo '#'
}

Expand Down Expand Up @@ -108,7 +114,7 @@ fi
#
# Register this unconfigured Couchbase instance in Consul for discovery by the configuration/bootstrap agent
#
curl -f --retry 7 --retry-delay 3 $CONSUL_HOST/v1/agent/service/register -d "$(printf '{"ID":"%s-unconfigured-%s","Name":"%s-unconfigured","Address":"%s","checks": [{"ttl": "5900s"}]}' $COUCHBASE_SERVICE_NAME $HOSTNAME $COUCHBASE_SERVICE_NAME $MYIPPRIVATE)"
curl -f --retry 7 --retry-delay 3 $CONSUL_HOST/v1/agent/service/register -d "$(printf '{"ID":"%s-unconfigured-%s","Name":"%s-unconfigured","Address":"%s","checks": [{"ttl": "5900s"}]}' $COUCHBASE_SERVICE_NAME $HOSTNAME $COUCHBASE_SERVICE_NAME $IP_PRIVATE)"

# pass the healthcheck
curl -f --retry 7 --retry-delay 3 "$CONSUL_HOST/v1/agent/check/pass/service:$COUCHBASE_SERVICE_NAME-unconfigured-$HOSTNAME?note=initial+startup"
Expand Down Expand Up @@ -148,7 +154,7 @@ while [ $COUCHBASERESPONSIVE != 1 ]; do
/opt/couchbase/bin/couchbase-cli node-init -c 127.0.0.1:8091 -u access -p password \
--node-init-data-path=/opt/couchbase/var/lib/couchbase/data \
--node-init-index-path=/opt/couchbase/var/lib/couchbase/data \
--node-init-hostname=$MYIPPRIVATE
--node-init-hostname=$IP_PRIVATE

if [ $? -eq 0 ]
then
Expand Down Expand Up @@ -180,7 +186,8 @@ then
--cluster-init-username=$COUCHBASE_USER \
--cluster-init-password=$COUCHBASE_PASS \
--cluster-init-port=8091 \
--cluster-init-ramsize=$MYMEMORY
--cluster-init-ramsize=$COUCHBASE_MEMORY \
--services=data,index,query

if [ $? -eq 0 ]
then
Expand All @@ -198,7 +205,7 @@ then
/opt/couchbase/bin/couchbase-cli bucket-create -c 127.0.01:8091 -u $COUCHBASE_USER -p $COUCHBASE_PASS \
--bucket=$COUCHBASE_BUCKET \
--bucket-type=couchbase \
--bucket-ramsize=$MYMEMORY \
--bucket-ramsize=$COUCHBASE_MEMORY \
--bucket-replica=1

if [ $? -eq 0 ]
Expand All @@ -211,8 +218,8 @@ then

# limit the number of threads for various operations on this bucket
# See http://docs.couchbase.com/admin/admin/CLI/CBepctl/cbepctl-threadpool-tuning.html for more details
/opt/couchbase/bin/cbepctl 127.0.0.1:11210 -b $COUCHBASE_BUCKET set flush_param max_num_writers $(($MYCPUS>1?$MYCPUS/2:1))
/opt/couchbase/bin/cbepctl 127.0.0.1:11210 -b $COUCHBASE_BUCKET set flush_param max_num_readers $(($MYCPUS>1?$MYCPUS/2:1))
/opt/couchbase/bin/cbepctl 127.0.0.1:11210 -b $COUCHBASE_BUCKET set flush_param max_num_writers $(($COUCHBASE_CPUS>1?$COUCHBASE_CPUS/2:1))
/opt/couchbase/bin/cbepctl 127.0.0.1:11210 -b $COUCHBASE_BUCKET set flush_param max_num_readers $(($COUCHBASE_CPUS>1?$COUCHBASE_CPUS/2:1))
/opt/couchbase/bin/cbepctl 127.0.0.1:11210 -b $COUCHBASE_BUCKET set flush_param max_num_auxio 1
/opt/couchbase/bin/cbepctl 127.0.0.1:11210 -b $COUCHBASE_BUCKET set flush_param max_num_nonio 1

Expand Down Expand Up @@ -252,9 +259,14 @@ else
while [ $COUCHBASERESPONSIVE != 1 ]; do
echo -n '.'

# This is the moment that we're adding an unconfigured node to an already configured cluster.
# We have to speak to the configured cluster ($CLUSTERIP) using the user selected u/p,
# ...but tell it to add this new node using its factory default u/p.

curl -s -i -f -u $COUCHBASE_USER:$COUCHBASE_PASS \
"http://$CLUSTERIP:8091/controller/addNode" \
-d "hostname=$(ip addr show eth0 | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}')&user=admin&password=password"
-d "hostname=${IP_PRIVATE}&user=admin&password=password" \
"http://$CLUSTERIP:8091/controller/addNode"

if [ $? -eq 0 ]
then
let COUCHBASERESPONSIVE=1
Expand Down Expand Up @@ -311,6 +323,6 @@ echo '#'
echo '# Register the configured Couchbase instance'
echo '#'

curl -f --retry 7 --retry-delay 3 $CONSUL_HOST/v1/agent/service/register -d "$(printf '{"ID": "%s-%s","Name": "%s","tags": ["couchbase","demo"],"Address": "%s","checks": [{"http": "http://%s:8091/index.html","interval": "13s","timeout": "1s"}]}' $COUCHBASE_SERVICE_NAME $HOSTNAME $COUCHBASE_SERVICE_NAME $MYIPPRIVATE $MYIPPRIVATE)"
curl -f --retry 7 --retry-delay 3 $CONSUL_HOST/v1/agent/service/register -d "$(printf '{"ID": "%s-%s","Name": "%s","tags": ["couchbase","demo"],"Address": "%s","checks": [{"http": "http://%s:8091/index.html","interval": "13s","timeout": "1s"}]}' $COUCHBASE_SERVICE_NAME $HOSTNAME $COUCHBASE_SERVICE_NAME $IP_PRIVATE $IP_PRIVATE)"

installed
2 changes: 1 addition & 1 deletion bin/triton-start
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ then
/usr/local/bin/triton-bootstrap &

# Start Couchbase
/usr/local/bin/couchbase-start "$@"
/usr/sbin/runsvdir-start "$@"
fi

exec "$@"

0 comments on commit 7806af9

Please sign in to comment.