Skip to content

Commit

Permalink
Scripts for managing integration tests environments (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
brantburnett authored Apr 12, 2018
1 parent 8621f90 commit efdbea0
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
node_modules/
/scripts
/example
/testbin
/env
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ Dockerfile
.editorconfig
.travis.yml
/scripts
/testbin
/env
13 changes: 13 additions & 0 deletions env/Down.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Param(
[string]
[Parameter(Position=0)]
$Version = "4.6.4"
)

if ($Version -match "^(\d+\.)*\d+$") {
$env:CBIMAGE = "couchbase:enterprise-$Version"
} else {
$env:CBIMAGE = $Version
}

docker-compose -p cbindexmgr -f $PSScriptRoot\docker-compose.yaml down
44 changes: 44 additions & 0 deletions env/Exec.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Executes couchbase-index-manager in a container with access to the test cluster
# with command line parameter passthrough
# Automatically includes authentication information for the test cluster
# and maps the example folder to /example in the container, set as the working dir

Param(
[switch]
$NoBuild,

[string[]]
[Parameter(ValueFromRemainingArguments=$true)]
$Params
)

$effectiveParams = @(
"-c", "couchbase://node1,node2,node3",
"-u", "Administrator",
"-p", "password"
)

$effectiveParams += $Params

if (-not $NoBuild) {
docker build -t cbindexmgr-testexec $PSScriptRoot\..
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
}

$image = & docker inspect cbindexmgr_node1_1 -f '{{ index .Config.Labels \"com.centeredgesoftware.cbindexmgr.image\"}}'
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}

$version = [regex]::match($image,'((\d+\.){2}\d+)').Groups[1].Value
if ($version) {
$versionNum = New-Object System.Version $version
if ($versionNum.Major -lt 5) {
$effectiveParams += @("--no-rbac")
}
}

docker run -it --network cbindexmgr -v "$PSScriptRoot\..\example:/example:ro" -w /example cbindexmgr-testexec $effectiveParams
exit $LASTEXITCODE
32 changes: 32 additions & 0 deletions env/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Testing Environments

This folder contains Docker Compose files that help to create
testing environments.

## Starting the Environment

```powershell
./env/Up.ps1 4.6.4
```

For an image other than Enterprise from the "couchbase" registry:

```powershell
./env/Up.ps1 couchbase/server:5.5.0-Mar
```

## Running couchbase-index-manager

If another shell window:

```powershell
./env/Exec.ps1 sync beer-sample ./beer-sample
```

## Stopping the Environment

First, press CTRL+C to stop the containers, then:

```powershell
./env/Down.ps1 4.6.4
```
13 changes: 13 additions & 0 deletions env/Up.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Param(
[string]
[Parameter(Position=0)]
$Version = "4.6.4"
)

if ($Version -match "^(\d+\.)*\d+$") {
$env:CBIMAGE = "couchbase:enterprise-$Version"
} else {
$env:CBIMAGE = $Version
}

docker-compose -p cbindexmgr -f $PSScriptRoot\docker-compose.yaml up
88 changes: 88 additions & 0 deletions env/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
version: '3.5'
services:
node1:
image: ${CBIMAGE:-couchbase:enterprise-4.6.4}
labels:
com.centeredgesoftware.cbindexmgr.image: ${CBIMAGE:-couchbase:enterprise-4.6.4}
ports:
- "8091:8091"
command: >
/bin/bash -c "
set -m;
/entrypoint.sh couchbase-server &
while true; do
sleep 3;
/opt/couchbase/bin/couchbase-cli node-init -c node1.cbindexmgr:8091 \
-u Administrator -p password \
--node-init-hostname=node1.cbindexmgr &&
sleep 1 &&
/opt/couchbase/bin/couchbase-cli cluster-init \
-u Administrator -p password \
--cluster-username Administrator --cluster-password password \
--cluster-ramsize 512 --cluster-index-ramsize 256 \
--services data,index,query && break
done;
fg 1"
node2:
image: ${CBIMAGE:-couchbase:enterprise-4.6.4}
command: >
/bin/bash -c "
set -m;
/entrypoint.sh couchbase-server &
while true; do
sleep 3;
/opt/couchbase/bin/couchbase-cli node-init -c node2.cbindexmgr:8091 \
-u Administrator -p password \
--node-init-hostname=node2.cbindexmgr && break
done;
fg 1"
node3:
image: ${CBIMAGE:-couchbase:enterprise-4.6.4}
command: >
/bin/bash -c "
set -m;
/entrypoint.sh couchbase-server &
while true; do
sleep 3;
/opt/couchbase/bin/couchbase-cli node-init -c node3.cbindexmgr:8091 \
-u Administrator -p password \
--node-init-hostname=node3.cbindexmgr && break
done;
fg 1"
startup:
image: ${CBIMAGE:-couchbase:enterprise-4.6.4}
depends_on:
- node1
- node2
- node3
working_dir: /opt/couchbase/bin
command: >
/bin/bash -c "
while true; do
sleep 3;
./couchbase-cli server-add -c node1.cbindexmgr -u Administrator -p password \
--server-add node2.cbindexmgr \
--server-add-username Administrator --server-add-password password \
--services data,index,query && break
done;
while true; do
sleep 3;
./couchbase-cli server-add -c node1.cbindexmgr -u Administrator -p password \
--server-add node3.cbindexmgr \
--server-add-username Administrator --server-add-password password \
--services data,index,query && break
done;
while true; do
sleep 3;
./couchbase-cli rebalance -c node1.cbindexmgr \
-u Administrator -p password && break
done;
while true; do
sleep 3;
./cbdocloader -n node1.cbindexmgr -u Administrator -p password \
-b beer-sample -s 100 /opt/couchbase/samples/beer-sample.zip && break
done
"
networks:
default:
name: cbindexmgr
5 changes: 3 additions & 2 deletions example/beer-sample/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ post_process: |
---
type: nodeMap
map:
node1: 172.21.0.2
node2: 172.21.0.3
node1: node1.cbindexmgr
node2: node2.cbindexmgr
node3: node3.cbindexmgr

0 comments on commit efdbea0

Please sign in to comment.