Skip to content

Commit d4abe10

Browse files
committed
fix back to main
1 parent e48e449 commit d4abe10

File tree

4 files changed

+253
-0
lines changed

4 files changed

+253
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2023-Present Couchbase, Inc.
2+
#
3+
# Use of this software is governed by the Business Source License included
4+
# in the file licenses/BSL-Couchbase.txt. As of the Change Date specified
5+
# in that file, in accordance with the Business Source License, use of this
6+
# software will be governed by the Apache License, Version 2.0, included in
7+
# the file licenses/APL2.txt.
8+
9+
services:
10+
couchbase:
11+
container_name: couchbase
12+
image: "couchbase/server:${COUCHBASE_DOCKER_IMAGE_NAME:-enterprise-7.6.5}"
13+
ports:
14+
- 8091:8091
15+
- 8092:8092
16+
- 8093:8093
17+
- 8094:8094
18+
- 8095:8095
19+
- 8096:8096
20+
- 8097:8097
21+
- 9102:9102
22+
- 9123:9123
23+
- 11207:11207
24+
- 11210:11210
25+
- 11211:11211
26+
- 18091:18091
27+
- 18092:18092
28+
- 18093:18093
29+
- 18094:18094
30+
- 18095:18095
31+
- 18096:18096
32+
- 18097:18097
33+
- 19102:19102
34+
volumes:
35+
- "${DOCKER_CBS_ROOT_DIR:-.}/cbs:/root"
36+
- "${WORKSPACE_ROOT:-.}:/workspace"
37+
couchbase-replica1:
38+
container_name: couchbase-replica1
39+
image: "couchbase/${COUCHBASE_DOCKER_IMAGE_NAME:-server:enterprise-7.6.5}"
40+
couchbase-replica2:
41+
container_name: couchbase-replica2
42+
image: "couchbase/server:${COUCHBASE_DOCKER_IMAGE_NAME:-enterprise-7.6.5}"
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
# Copyright 2024-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+
# This file is used by github CI or locally and runs a subset of test scripts to validate the service installation done by the package managers. This is intended to be run from Linux or Mac.
11+
12+
set -eux -o pipefail
13+
14+
IMAGES=(
15+
"almalinux:9"
16+
"amazonlinux:2"
17+
"amazonlinux:2023"
18+
"debian:10"
19+
"debian:11"
20+
"debian:12"
21+
"redhat/ubi8"
22+
"redhat/ubi9"
23+
"rockylinux:9"
24+
"ubuntu:20.04"
25+
"ubuntu:22.04"
26+
"ubuntu:24.04"
27+
28+
# not technically supported
29+
"oraclelinux:9"
30+
)
31+
32+
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
33+
SYNC_GATEWAY_DIR=$(realpath ${SCRIPT_DIR}/..)
34+
35+
if [ "$(uname)" == "Darwin" ]; then
36+
sudo ${SYNC_GATEWAY_DIR}/integration-test/service-test.sh
37+
fi
38+
39+
for IMAGE in "${IMAGES[@]}"; do
40+
echo "Running tests for ${IMAGE}"
41+
docker run --mount src=${SYNC_GATEWAY_DIR},target=/sync_gateway,type=bind ${IMAGE} /bin/bash -c "/sync_gateway/integration-test/service-test.sh"
42+
done

integration-test/service-test.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#/bin/sh
2+
3+
# Copyright 2024-Present Couchbase, Inc.
4+
#
5+
# Use of this software is governed by the Business Source License included
6+
# in the file licenses/BSL-Couchbase.txt. As of the Change Date specified
7+
# in that file, in accordance with the Business Source License, use of this
8+
# software will be governed by the Apache License, Version 2.0, included in
9+
# the file licenses/APL2.txt.
10+
11+
# This code is intneded to be run from within a docker container of a specific platform and runs a subset of the service scripts. The full service can not be validated since systemd does not work in docker contains. This is intended to run in /bin/sh to test dash environments on debian systems.
12+
13+
set -eux -o pipefail
14+
15+
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
16+
17+
cd ${SCRIPT_DIR}/../service
18+
19+
./sync_gateway_service_install.sh --servicecmd
20+
21+
# /etc/os-release doesn't exist on Darwin
22+
if [ -f /etc/os-release ]; then
23+
. /etc/os-release
24+
case ${ID} in
25+
amzn)
26+
yum install -y shadow-utils systemd
27+
;;
28+
esac
29+
30+
groupadd -r sync_gateway
31+
useradd -g sync_gateway sync_gateway
32+
33+
# bash would support export -f for a systemctl wrapper, but dash does not support exporting aliases or functions
34+
35+
mkdir -p /tmp/systemctl_wrapper
36+
37+
cat << 'EOF' > /tmp/systemctl_wrapper/systemctl
38+
#!/bin/bash
39+
40+
set -eu -o pipefail
41+
42+
case ${1:-} in
43+
start)
44+
echo "No-op systemctl start in docker, since we're not running systemd"
45+
;;
46+
stop)
47+
echo "No-op systemctl stop in docker, since we're not running systemd"
48+
;;
49+
*)
50+
echo "Running systemctl $@"
51+
command /usr/bin/systemctl "$@"
52+
;;
53+
esac
54+
EOF
55+
56+
chmod +x /tmp/systemctl_wrapper/systemctl
57+
58+
export PATH=/tmp/systemctl_wrapper:$PATH
59+
fi
60+
61+
./sync_gateway_service_install.sh
62+
./sync_gateway_service_upgrade.sh
63+
./sync_gateway_service_uninstall.sh
64+
65+
# test again with runas option
66+
./sync_gateway_service_install.sh --runas=root
67+
./sync_gateway_service_upgrade.sh
68+
./sync_gateway_service_uninstall.sh
69+
70+
echo "Successful service test"

integration-test/start_server.sh

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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

Comments
 (0)