Skip to content

Commit

Permalink
Remove docker baas from Jenkins CI (#7248)
Browse files Browse the repository at this point in the history
* remove docker baas from Jenkins CI

* fix baas version lookup on remote hosts

* fix up Jenkinsfile tests

* fix test scripts
  • Loading branch information
ironage authored Jan 15, 2024
1 parent 865cf5e commit 7805df5
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 62 deletions.
50 changes: 17 additions & 33 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,6 @@ def doCheckInDocker(Map options = [:]) {
REALM_ENABLE_ENCRYPTION: options.enableEncryption ? 'ON' : 'OFF',
REALM_ENABLE_SYNC: options.enableSync ? 'ON' : 'OFF',
]
if (options.enableSync) {
cmakeOptions << [
REALM_ENABLE_AUTH_TESTS: 'ON',
REALM_MONGODB_ENDPOINT: 'http://mongodb-realm:9090',
]
}
if (longRunningTests) {
cmakeOptions << [
CMAKE_CXX_FLAGS: '"-DTEST_DURATION=1"',
Expand Down Expand Up @@ -275,38 +269,28 @@ def doCheckInDocker(Map options = [:]) {
}
}

if (options.enableSync) {
// stitch images are auto-published every day to our CI
// see https://github.com/realm/ci/tree/master/realm/docker/mongodb-realm
// we refrain from using "latest" here to optimise docker pull cost due to a new image being built every day
// if there's really a new feature you need from the latest stitch, upgrade this manually
withRealmCloud(version: dependencies.MDBREALM_TEST_SERVER_TAG) { networkName ->
buildSteps("--network=${networkName}")
}
buildSteps()

if (options.dumpChangesetTransform) {
buildEnv.inside {
dir('build-dir/test') {
withEnv([
'UNITTEST_PROGRESS=1',
'UNITTEST_FILTER=Array_Example Transform_* EmbeddedObjects_*',
'UNITTEST_DUMP_TRANSFORM=changeset_dump',
]) {
sh '''
./realm-sync-tests
tar -zcvf changeset_dump.tgz changeset_dump
'''
}
withAWS(credentials: 'stitch-sync-s3', region: 'us-east-1') {
retry(20) {
s3Upload file: 'changeset_dump.tgz', bucket: 'realm-test-artifacts', acl: 'PublicRead', path: "sync-transform-corpuses/${gitSha}/"
}
if (options.dumpChangesetTransform) {
buildEnv.inside {
dir('build-dir/test') {
withEnv([
'UNITTEST_PROGRESS=1',
'UNITTEST_FILTER=Array_Example Transform_* EmbeddedObjects_*',
'UNITTEST_DUMP_TRANSFORM=changeset_dump',
]) {
sh '''
./realm-sync-tests
tar -zcvf changeset_dump.tgz changeset_dump
'''
}
withAWS(credentials: 'stitch-sync-s3', region: 'us-east-1') {
retry(20) {
s3Upload file: 'changeset_dump.tgz', bucket: 'realm-test-artifacts', acl: 'PublicRead', path: "sync-transform-corpuses/${gitSha}/"
}
}
}
}
} else {
buildSteps()
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion dependencies.list
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ PACKAGE_NAME=realm-core
VERSION=13.25.1
OPENSSL_VERSION=3.0.8
ZLIB_VERSION=1.2.13
MDBREALM_TEST_SERVER_TAG=2023-12-15
# https://github.com/10gen/baas/commits
# 300ef is 2023 Dec 15
BAAS_VERSION=300efb0604a88f1f36899bee0f42b34826b9b65f
17 changes: 14 additions & 3 deletions evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -975,8 +975,6 @@ tasks:
exec_timeout_secs: 3600
commands:
- func: "launch remote baas"
vars:
baas_branch: 300efb0604a88f1f36899bee0f42b34826b9b65f
- func: "compile"
vars:
target_to_build: ObjectStoreTests
Expand All @@ -1000,7 +998,6 @@ tasks:
commands:
- func: "launch remote baas"
vars:
baas_branch: 300efb0604a88f1f36899bee0f42b34826b9b65f
baas_proxy: On
- func: "compile"
vars:
Expand Down Expand Up @@ -1568,6 +1565,20 @@ buildvariants:
- name: compile_test_and_package
- name: benchmarks

# use a small runner to exercise timing sensitive bugs
- name: ubuntu2204-arm64-small
display_name: "Ubuntu 22.04 ARM64 Small"
run_on: ubuntu2204-arm64-small
expansions:
cmake_url: "https://s3.amazonaws.com/static.realm.io/evergreen-assets/cmake-3.20.3-linux-aarch64.tar.gz"
cmake_bindir: "./cmake_binaries/bin"
python3: "/opt/mongodbtoolchain/v3/bin/python3"
use_system_openssl: On
fetch_missing_dependencies: On
cmake_build_type: RelWithDebInfo
tasks:
- name: compile_test_and_package

- name: ubuntu2204-arm64-asan
display_name: "Ubuntu 22.04 ARM64 (ASAN)"
run_on: ubuntu2204-arm64-large
Expand Down
50 changes: 48 additions & 2 deletions evergreen/install_baas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,31 @@ if [[ -z "${WORK_PATH}" ]]; then
usage 1
fi

function get_var_from_file()
{
# Usage: get_var_from_file VAR FILE
upper=$(echo "${1}" | tr 'a-z' 'A-Z')
lower=$(echo "${1}" | tr 'A-Z' 'a-z')
regex="^(${upper}|${lower})[ ]*=[ ]*(.*)[ ]*"
while read p; do
if [[ $p =~ $regex ]]
then
value="${BASH_REMATCH[2]}" # results are in this variable, use the second regex group
export ${1}=${value}
break
fi
done < "${2}"
}

if [[ -z "${AWS_ACCESS_KEY_ID}" || -z "${AWS_SECRET_ACCESS_KEY}" ]]; then
# try to read them from the usual place on disk
creds_file=~/.aws/credentials
if test -f ${creds_file}; then
get_var_from_file AWS_ACCESS_KEY_ID ${creds_file}
get_var_from_file AWS_SECRET_ACCESS_KEY ${creds_file}
fi
fi

if [[ -z "${AWS_ACCESS_KEY_ID}" || -z "${AWS_SECRET_ACCESS_KEY}" ]]; then
echo "Error: AWS_ACCESS_KEY_ID and/or AWS_SECRET_ACCESS_KEY are not set"
exit 1
Expand Down Expand Up @@ -338,9 +363,30 @@ echo "jq version: $(jq --version)"
git config --global url."git@github.com:".insteadOf "https://github.com/"
#export GOPRIVATE="github.com/10gen/*"

# If a baas branch or commit version was not provided, retrieve the latest release version
# If a baas branch or commit version was not provided use the one locked in our dependencies
if [[ -z "${BAAS_VERSION}" ]]; then
BAAS_VERSION=$(${CURL} -LsS "https://realm.mongodb.com/api/private/v1.0/version" | jq -r '.backend.git_hash')
dep_file="dependencies.list"
test_path1="${BASE_PATH}/../${dep_file}"
test_path2="${BASE_PATH}/${dep_file}"
if [[ -f "${test_path1}" ]]; then
# if this was run locally then check up a directory
get_var_from_file BAAS_VERSION "${test_path1}"
elif [[ -f "${test_path2}" ]]; then
# if this is run from an evergreen remote host
# then the dependencies.list file has been copied over
get_var_from_file BAAS_VERSION "${test_path2}"
else
echo "could not find '${test_path1}' or '${test_path2}'"
ls "${BASE_PATH}/.."
echo ""
ls "${BASE_PATH}"
fi
fi

# if we couldn't find it and it wasn't manually provided fail
if [[ -z "${BAAS_VERSION}" ]]; then
echo "BAAS_VERSION was not provided and couldn't be discovered"
exit 1
fi

# Clone the baas repo and check out the specified version
Expand Down
2 changes: 2 additions & 0 deletions evergreen/setup_baas_host_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ echo "Transferring setup scripts to ${SSH_USER}:${FILE_DEST_DIR}"
scp "${SSH_OPTIONS[@]}" -o ConnectTimeout=60 "${BAAS_HOST_VARS}" "${SSH_USER}:${FILE_DEST_DIR}/"
# Copy the entire evergreen/ directory from the working copy of realm-core to the remote host
# This ensures the remote host the latest copy, esp when running evergreen patches
# dependencies.list contains the BAAS_VERSION to use
echo "Transferring evergreen scripts to ${SSH_USER}:${FILE_DEST_DIR}"
cp "${EVERGREEN_PATH}/../dependencies.list" "${EVERGREEN_PATH}/"
scp -r "${SSH_OPTIONS[@]}" -o ConnectTimeout=60 "${EVERGREEN_PATH}/" "${SSH_USER}:${FILE_DEST_DIR}/"

BAAS_TUNNELS=()
Expand Down
22 changes: 8 additions & 14 deletions how-to-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,16 @@ These are the available variables:
testing process as soon as a check fails or an unexpected exception is thrown
in a test.

## Running [app] tests against a local MongoDB Stitch
## Running [app] tests against a local MongoDB BAAS

Due to MongoDB security policies, running baas requires company issued AWS account credentials.
These are for MongoDB employees only, if you do not have these, reach out to #realm-core.
Once you have them, they need to be passed to the docker image below. If the credentials are not
passed in correctly, the docker image will block at the message "Starting Stitch..." forever.
Once you have them, they need to be set in the shell environment.

First, log in to aws using their command line tool. On mac this requries `brew install awscli`.
Then login using `aws configure` and input your access key and secret acess key. The other
configuration options can be left as none. This creates a correctly formatted file locally at
`~/.aws/credentials` which we will use later when starting docker.
`~/.aws/credentials` which we will use later.

If you do not want to install the aws command line tools, you can also create the aws file
manually in the correct location (`~/.aws/credentials`) with the following contents:
Expand All @@ -165,26 +164,21 @@ AWS_ACCESS_KEY_ID = <your-key-id>
AWS_SECRET_ACCESS_KEY = <your-secret-key>
```

Stitch images are published to our private Github CI. Follow the steps here to
set up authorization from docker to your Github account https://github.com/realm/ci/tree/master/realm/docker/mongodb-realm
Once authorized, run the following docker command from the top directory to start a local instance:
We use a script to fetch the dependencies for and run baas locally. Use the `-b sha` to use a particular version from https://github.com/10gen/baas/
The script uses the configuration from https://github.com/10gen/baas/blob/master/etc/configs/test_rcore_config.json

```
export MDBREALM_TEST_SERVER_TAG=$(grep MDBREALM_TEST_SERVER_TAG dependencies.list |cut -f 2 -d=)
docker run --rm -p 9090:9090 -v ~/.aws/credentials:/root/.aws/credentials -it ghcr.io/realm/ci/mongodb-realm-test-server:${MDBREALM_TEST_SERVER_TAG}
./evergreen/install_baas.sh -w baas
```

This will make the stitch UI available in your browser at `localhost:9090` where you can login with "unique_user@domain.com" and "password".
Once logged in, you can make changes to the integration-tests app and those changes will be persisted to your disk, because the docker image
has a mapped volume to the `tests/mongodb` directory.

To run the [app] tests against the local image, you need to configure a build with some cmake options to tell the tests where to point to.
To run the [app] tests against the local baas, you need to configure a build with some cmake options to tell the tests where to point to.
```
mkdir build.sync.ninja
cmake -B build.sync.ninja -G Ninja -DREALM_ENABLE_AUTH_TESTS=1 -DREALM_MONGODB_ENDPOINT=http://localhost:9090
cmake --build build.sync.ninja --target realm-object-store-tests
./build.sync.ninja/test/object-store/realm-object-store-tests -d=1
```

### Developing inside a container

The `.devcontainer` folders contains configuration for the [Visual Studio Code Remote - Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension, which allows you to develop inside the same Docker container that CI runs in, which is especially useful because it also sets up the MongoDB Realm Test Server container. Make sure you have the `Remote - Containers` extension installed (it's part of the recommended extensions list for this repository) and run the `Remote-Containers: Reopen in Container` (or `Rebuild and Reopen in Container`) command. VSCode will build the image described in `Dockerfile`, spin up a container group using Docker Compose, and reopen the workspace from inside the container.
Expand Down
14 changes: 10 additions & 4 deletions tools/cmake/GetVersion.cmake
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
file(STRINGS "${RealmCore_SOURCE_DIR}/dependencies.list" DEPENDENCIES)
message("Dependencies: ${DEPENDENCIES}")
set(VALID_DEPENDENCIES "")
foreach(LINE IN LISTS DEPENDENCIES)
string(REGEX MATCHALL "([^=]+)" KEY_VALUE ${LINE})
list(GET KEY_VALUE 0 KEY)
list(GET KEY_VALUE 1 VALUE)
set(DEP_${KEY} ${VALUE})
list(LENGTH KEY_VALUE MATCH_SIZE)
if (MATCH_SIZE GREATER_EQUAL 2)
list(GET KEY_VALUE 0 KEY)
list(GET KEY_VALUE 1 VALUE)
set(DEP_${KEY} ${VALUE})
set(VALID_DEPENDENCIES "${VALID_DEPENDENCIES} ${LINE}")
endif()
endforeach()

message("Dependencies: ${VALID_DEPENDENCIES}")

#check version format
string(REGEX MATCH "^[0-9]+\.[0-9]+\.[0-9]+$" CONFIG_VERSION ${DEP_VERSION})
if (NOT CONFIG_VERSION)
Expand Down
5 changes: 0 additions & 5 deletions tools/run_baas_docker_image.sh

This file was deleted.

0 comments on commit 7805df5

Please sign in to comment.