|
| 1 | +#!/bin/bash |
| 2 | +# Copyright 2023-Present Couchbase, Inc. |
| 3 | +# |
| 4 | +# Use of this software is governed by the Business Source License included |
| 5 | +# in the file licenses/BSL-Couchbase.txt. As of the Change Date specified |
| 6 | +# in that file, in accordance with the Business Source License, use of this |
| 7 | +# software will be governed by the Apache License, Version 2.0, included in |
| 8 | +# the file licenses/APL2.txt. |
| 9 | + |
| 10 | +set -eux -o pipefail |
| 11 | + |
| 12 | +function usage() { |
| 13 | + echo "Usage: $0 [-m] [-h] containername" |
| 14 | +} |
| 15 | + |
| 16 | +if [ $# -gt 2 ]; then |
| 17 | + echo "Expected maximally two arguments" |
| 18 | + exit 1 |
| 19 | +fi |
| 20 | + |
| 21 | +while [[ $# -gt 0 ]]; do |
| 22 | + key="$1" |
| 23 | + case $key in |
| 24 | + -m | --multi-node) |
| 25 | + MULTI_NODE=true |
| 26 | + shift |
| 27 | + ;; |
| 28 | + -h | --help) |
| 29 | + echo "Usage: $0 [-m] [-h] containername" |
| 30 | + exit 1 |
| 31 | + ;; |
| 32 | + --non-dockerhub) |
| 33 | + DOCKERHUB=false |
| 34 | + shift |
| 35 | + ;; |
| 36 | + *) |
| 37 | + COUCHBASE_DOCKER_IMAGE_NAME="$1" |
| 38 | + shift |
| 39 | + ;; |
| 40 | + esac |
| 41 | +done |
| 42 | + |
| 43 | +WORKSPACE_ROOT="$(pwd)" |
| 44 | +DOCKER_CBS_ROOT_DIR="$(pwd)" |
| 45 | +if [ "${CBS_ROOT_DIR:-}" != "" ]; then |
| 46 | + DOCKER_CBS_ROOT_DIR="${CBS_ROOT_DIR}" |
| 47 | +fi |
| 48 | + |
| 49 | +set +e |
| 50 | +AMAZON_LINUX_2=$(grep 'Amazon Linux 2"' /etc/os-release) |
| 51 | +set -e |
| 52 | +if [[ -n "${AMAZON_LINUX_2}" ]]; then |
| 53 | + DOCKER_COMPOSE="docker-compose" # use docker-compose v1 for Jenkins AWS Linux 2 |
| 54 | +else |
| 55 | + DOCKER_COMPOSE="docker compose" |
| 56 | +fi |
| 57 | +cd -- "${BASH_SOURCE%/*}/" |
| 58 | +${DOCKER_COMPOSE} down || true |
| 59 | +export SG_TEST_COUCHBASE_SERVER_DOCKER_NAME=couchbase |
| 60 | +# Start CBS |
| 61 | +docker stop ${SG_TEST_COUCHBASE_SERVER_DOCKER_NAME} || true |
| 62 | +docker rm ${SG_TEST_COUCHBASE_SERVER_DOCKER_NAME} || true |
| 63 | +# --volume: Makes and mounts a CBS folder for storing a CBCollect if needed |
| 64 | + |
| 65 | +# use dockerhub if no registry is specified, allows for pre-release images from alternative registries |
| 66 | +if [[ ! "${COUCHBASE_DOCKER_IMAGE_NAME}" =~ ghcr.io/* && "${DOCKERHUB:-}" != "false" ]]; then |
| 67 | + COUCHBASE_DOCKER_IMAGE_NAME="couchbase/server:${COUCHBASE_DOCKER_IMAGE_NAME}" |
| 68 | +fi |
| 69 | + |
| 70 | +if [ "${MULTI_NODE:-}" == "true" ]; then |
| 71 | + ${DOCKER_COMPOSE} up -d --force-recreate --renew-anon-volumes --remove-orphans |
| 72 | +else |
| 73 | + # single node |
| 74 | + docker run --rm -d --name ${SG_TEST_COUCHBASE_SERVER_DOCKER_NAME} --volume "${WORKSPACE_ROOT}:/workspace" -p 8091-8097:8091-8097 -p 9102:9102 -p 9123:9123 -p 11207:11207 -p 11210:11210 -p 11211:11211 -p 18091-18097:18091-18097 -p 19102:19102 "${COUCHBASE_DOCKER_IMAGE_NAME}" |
| 75 | +fi |
| 76 | + |
| 77 | +# Test to see if Couchbase Server is up |
| 78 | +# Each retry min wait 5s, max 10s. Retry 20 times with exponential backoff (delay 0), fail at 120s |
| 79 | +curl --retry-all-errors --connect-timeout 5 --max-time 10 --retry 20 --retry-delay 0 --retry-max-time 120 'http://127.0.0.1:8091' |
| 80 | + |
| 81 | +# Set up CBS |
| 82 | + |
| 83 | +docker exec couchbase couchbase-cli cluster-init --cluster-username Administrator --cluster-password password --cluster-ramsize 3072 --cluster-index-ramsize 3072 --cluster-fts-ramsize 256 --services data,index,query |
| 84 | +docker exec couchbase couchbase-cli setting-index --cluster couchbase://localhost --username Administrator --password password --index-threads 4 --index-log-level verbose --index-max-rollback-points 10 --index-storage-setting default --index-memory-snapshot-interval 150 --index-stable-snapshot-interval 40000 |
| 85 | + |
| 86 | +curl -u Administrator:password -v -X POST http://127.0.0.1:8091/node/controller/rename -d 'hostname=127.0.0.1' |
| 87 | + |
| 88 | +if [ "${MULTI_NODE:-}" == "true" ]; then |
| 89 | + REPLICA1_NAME=couchbase-replica1 |
| 90 | + REPLICA2_NAME=couchbase-replica2 |
| 91 | + CLI_ARGS=(-c couchbase://couchbase -u Administrator -p password) |
| 92 | + docker exec ${REPLICA1_NAME} couchbase-cli node-init "${CLI_ARGS[@]}" |
| 93 | + docker exec ${REPLICA2_NAME} couchbase-cli node-init "${CLI_ARGS[@]}" |
| 94 | + REPLICA1_IP=$(docker inspect --format '{{json .NetworkSettings.Networks}}' ${REPLICA1_NAME} | jq -r 'first(.[]) | .IPAddress') |
| 95 | + REPLICA2_IP=$(docker inspect --format '{{json .NetworkSettings.Networks}}' ${REPLICA2_NAME} | jq -r 'first(.[]) | .IPAddress') |
| 96 | + docker exec ${SG_TEST_COUCHBASE_SERVER_DOCKER_NAME} couchbase-cli server-add "${CLI_ARGS[@]}" --server-add "$REPLICA2_IP" --server-add-username Administrator --server-add-password password --services data,index,query |
| 97 | + docker exec ${SG_TEST_COUCHBASE_SERVER_DOCKER_NAME} couchbase-cli server-add "${CLI_ARGS[@]}" --server-add "$REPLICA1_IP" --server-add-username Administrator --server-add-password password --services data,index,query |
| 98 | + docker exec ${SG_TEST_COUCHBASE_SERVER_DOCKER_NAME} couchbase-cli rebalance "${CLI_ARGS[@]}" |
| 99 | +fi |
0 commit comments