Skip to content

Commit

Permalink
DRIVERS-2909 Add Env File Handling (#444)
Browse files Browse the repository at this point in the history
Co-authored-by: Jib <[email protected]>
  • Loading branch information
blink1073 and Jibola authored Jun 5, 2024
1 parent 2ae87ee commit 19d18c5
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 121 deletions.
215 changes: 98 additions & 117 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,18 @@ functions:
MONGODB_BINARIES: "$MONGODB_BINARIES"
UPLOAD_BUCKET: "$UPLOAD_BUCKET"
PROJECT_DIRECTORY: "$PROJECT_DIRECTORY"
PREPARE_SHELL: |
set -o errexit
export DRIVERS_TOOLS="$DRIVERS_TOOLS"
export MONGO_ORCHESTRATION_HOME="$MONGO_ORCHESTRATION_HOME"
export PROJECT_ORCHESTRATION_HOME="$PROJECT_ORCHESTRATION_HOME"
export MONGODB_BINARIES="$MONGODB_BINARIES"
export UPLOAD_BUCKET="$UPLOAD_BUCKET"
export PROJECT_DIRECTORY="$PROJECT_DIRECTORY"
export TMPDIR="$MONGO_ORCHESTRATION_HOME/db"
export PATH="$MONGODB_BINARIES:$PATH"
export PROJECT="${project}"
EOT
cat <<EOT > .env
CURRENT_VERSION="$CURRENT_VERSION"
DRIVERS_TOOLS="$DRIVERS_TOOLS"
MONGO_ORCHESTRATION_HOME="$MONGO_ORCHESTRATION_HOME"
PROJECT_ORCHESTRATION_HOME="$PROJECT_ORCHESTRATION_HOME"
MONGODB_BINARIES="$MONGODB_BINARIES"
UPLOAD_BUCKET="$UPLOAD_BUCKET"
PROJECT_DIRECTORY="$PROJECT_DIRECTORY"
EOT
# See what we've done
cat expansion.yml
Expand All @@ -100,15 +99,14 @@ functions:
- command: shell.exec
params:
script: |
${PREPARE_SHELL}
rm -rf $DRIVERS_TOOLS
rm -rf ${DRIVERS_TOOLS}
if [ "${project}" = "drivers-tools" ]; then
# If this was a patch build, doing a fresh clone would not actually test the patch
cp -R ${PROJECT_DIRECTORY}/ $DRIVERS_TOOLS
cp -R ${PROJECT_DIRECTORY}/ ${DRIVERS_TOOLS}
else
git clone https://github.com/mongodb-labs/drivers-evergreen-tools.git $DRIVERS_TOOLS
git clone https://github.com/mongodb-labs/drivers-evergreen-tools.git ${DRIVERS_TOOLS}
fi
$DRIVERS_TOOLS/.evergreen/setup.sh
${DRIVERS_TOOLS}/.evergreen/setup.sh
"upload release":
- command: s3.put
Expand Down Expand Up @@ -163,7 +161,6 @@ functions:
params:
working_dir: "src"
script: |
${PREPARE_SHELL}
[ -f ${PROJECT_DIRECTORY}/${file} ] && BUILDTOOL="${buildtool}" bash ${PROJECT_DIRECTORY}/${file} || echo "${PROJECT_DIRECTORY}/${file} not available, skipping"
"exec script" :
Expand All @@ -172,7 +169,6 @@ functions:
params:
working_dir: "src"
script: |
${PREPARE_SHELL}
[ -f ${PROJECT_DIRECTORY}/${file} ] && bash ${PROJECT_DIRECTORY}/${file} || echo "${PROJECT_DIRECTORY}/${file} not available, skipping"
"upload docs" :
Expand Down Expand Up @@ -312,73 +308,67 @@ functions:
file_location: "${DRIVERS_TOOLS}/results.json"

"bootstrap mongo-orchestration":
- command: shell.exec
- command: subprocess.exec
params:
script: |
${PREPARE_SHELL}
# Purposely use sh here to ensure backwards compatibility.
MONGODB_VERSION=${VERSION} TOPOLOGY=${TOPOLOGY} AUTH=${AUTH} SSL=${SSL} STORAGE_ENGINE=${STORAGE_ENGINE} LOAD_BALANCER=${LOAD_BALANCER} REQUIRE_API_VERSION=${REQUIRE_API_VERSION} sh ${DRIVERS_TOOLS}/.evergreen/run-orchestration.sh
# Purposely use sh here to ensure backwards compatibility.
binary: sh
env:
MONGODB_VERSION: ${VERSION}
TOPOLOGY: ${TOPOLOGY}
SSL: ${SSL}
STORAGE_ENGINE: ${STORAGE_ENGINE}
LOAD_BALANCER: ${LOAD_BALANCER}
REQUIRE_API_VERSION: ${REQUIRE_API_VERSION}
args:
- ${DRIVERS_TOOLS}/.evergreen/run-orchestration.sh
# run-orchestration generates expansion file with the MONGODB_URI for the cluster
- command: expansions.update
params:
file: mo-expansion.yml

"start load balancer":
- command: shell.exec
- command: subprocess.exec
params:
script: |
MONGODB_URI=${MONGODB_URI} bash ${DRIVERS_TOOLS}/.evergreen/run-load-balancer.sh start
binary: bash
env:
MONGODB_URI: ${MONGODB_URI}
args:
- ${DRIVERS_TOOLS}/.evergreen/run-load-balancer.sh
- start
- command: expansions.update
params:
file: lb-expansion.yml

"run tests":
- command: shell.exec
- command: subprocess.exec
type: test
params:
binary: bash
working_dir: "src"
script: |
${PREPARE_SHELL}
AUTH=${AUTH} SSL=${SSL} MONGODB_URI="${MONGODB_URI}" sh ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
env:
AUTH: ${AUTH}
SSL: ${SSL}
MONGODB_URI: ${MONGODB_URI}
CRYPT_SHARED_LIB_PATH: ${CRYPT_SHARED_LIB_PATH}
args:
- ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh

"run serverless tests":
- command: shell.exec
type: test
params:
include_expansions_in_env: ["SERVERLESS_ATLAS_PASSWORD"]
working_dir: "src"
script: |
${PREPARE_SHELL}
set +o xtrace
MONGODB_URI="${MONGODB_URI}" \
SERVERLESS_ATLAS_USER="${SERVERLESS_ATLAS_USER}" \
CRYPT_SHARED_LIB_PATH="${CRYPT_SHARED_LIB_PATH}" \
bash ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
"run atlas tests":
- command: shell.exec
"run docker test":
- command: subprocess.exec
type: test
params:
working_dir: "src"
script: |
${PREPARE_SHELL}
set +o xtrace
MONGODB_URI="${MONGODB_URI}" \
bash ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
"run docker test":
- command: shell.exec
binary: bash
env:
ENTRYPOINT: /root/test-entrypoint.sh
args:
- ${DRIVERS_TOOLS}/.evergreen/docker/run-server.sh
- command: subprocess.exec
type: test
params:
working_dir: "src"
script: |
${PREPARE_SHELL}
set -ex
cd $DRIVERS_TOOLS/.evergreen/docker
ARCH=${ARCH} TARGET_IMAGE=${TARGET_IMAGE} MONGODB_VERSION=${MONGODB_VERSION} ENTRYPOINT=/root/test-entrypoint.sh bash run-server.sh
# Generate a test results file
cd ${PROJECT_DIRECTORY}
make test
binary: make
working_dir: "${DRIVERS_TOOLS}"
args:
- test

"run oidc local test":
- command: ec2.assume_role
Expand All @@ -390,9 +380,8 @@ functions:
include_expansions_in_env: ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"]
working_dir: "src"
script: |
${PREPARE_SHELL}
set -ex
bash $DRIVERS_TOOLS/.evergreen/auth_oidc/setup.sh
bash ${DRIVERS_TOOLS}/.evergreen/auth_oidc/setup.sh
test -f /tmp/tokens/test_user1
test -f /tmp/tokens/test_user2
test -f /tmp/tokens/test_machine
Expand All @@ -410,9 +399,8 @@ functions:
include_expansions_in_env: ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"]
working_dir: "src"
script: |
${PREPARE_SHELL}
set -ex
cd $DRIVERS_TOOLS/.evergreen/auth_oidc
cd ${DRIVERS_TOOLS}/.evergreen/auth_oidc
ENTRYPOINT=/root/docker_entry_base.sh bash start_local_server.sh
test -f /tmp/tokens/test_user1
test -f /tmp/tokens/test_user2
Expand All @@ -427,40 +415,36 @@ functions:
shell: bash
script: |-
set -o errexit
${PREPARE_SHELL}
cd $DRIVERS_TOOLS
cd ${DRIVERS_TOOLS}
export AZUREOIDC_DRIVERS_TAR_FILE=/tmp/drivers-tools.tgz
git archive -o $AZUREOIDC_DRIVERS_TAR_FILE HEAD
export AZUREOIDC_TEST_CMD="source ./env.sh && echo 'hello'"
bash $DRIVERS_TOOLS/.evergreen/auth_oidc/azure/run-driver-test.sh
bash ${DRIVERS_TOOLS}/.evergreen/auth_oidc/azure/run-driver-test.sh
"run oidc gcp test":
- command: shell.exec
params:
shell: bash
script: |-
set -o errexit
${PREPARE_SHELL}
cd $DRIVERS_TOOLS
cd ${DRIVERS_TOOLS}
export GCPOIDC_DRIVERS_TAR_FILE=/tmp/drivers-tools.tgz
git archive -o $GCPOIDC_DRIVERS_TAR_FILE HEAD
export GCPOIDC_TEST_CMD="source ./secrets-export.sh && echo 'hello'"
bash $DRIVERS_TOOLS/.evergreen/auth_oidc/gcp/run-driver-test.sh
bash ${DRIVERS_TOOLS}/.evergreen/auth_oidc/gcp/run-driver-test.sh
"teardown assets":
- command: shell.exec
shell: bash
- command: subprocess.exec
params:
script: |
${PREPARE_SHELL}
bash ${DRIVERS_TOOLS}/.evergreen/teardown.sh
binary: bash
args:
- ${DRIVERS_TOOLS}/.evergreen/teardown.sh

"cleanup":
- command: shell.exec
params:
script: |
${PREPARE_SHELL}
rm -rf $DRIVERS_TOOLS || true
rm -rf ${DRIVERS_TOOLS} || true
pre:
- func: "fetch source"
Expand Down Expand Up @@ -812,22 +796,26 @@ tasks:
- name: "test-serverless"
tags: ["serverless", "pr"]
commands:
- func: "run serverless tests"
- func: "run tests"

- name: "test-atlas"
tags: ["atlas", "pr"]
commands:
- func: "run atlas tests"
- func: "run tests"

- name: "test-docker"
tags: ["latest", "docker", "pr"]
commands:
- func: "run docker test"
- func: "run docker test"
vars:
TARGET_IMAGE: ubuntu18.04
MONGODB_VERSION: 3.6
ARCH: amd64

- name: "test-docker-3.6"
tags: ["latest", "docker", "pr"]
commands:
- func: "run docker test"
vars:
TARGET_IMAGE: ubuntu18.04
MONGODB_VERSION: 3.6
ARCH: amd64

- name: "test-oidc-local"
tags: ["latest", "oidc", "pr"]
Expand Down Expand Up @@ -861,19 +849,18 @@ task_groups:
setup_group:
- func: "fetch source"
- func: "prepare resources"
- command: shell.exec
- command: subprocess.exec
params:
shell: "bash"
script: |
${PREPARE_SHELL}
set +o xtrace
bash ${DRIVERS_TOOLS}/.evergreen/serverless/setup.sh
binary: "bash"
include_expansions_in_env: ["SERVERLESS_ATLAS_PASSWORD", "SERVERLESS_ATLAS_USER"]
args:
- ${DRIVERS_TOOLS}/.evergreen/serverless/setup.sh
teardown_group:
- command: shell.exec
- command: subprocess.exec
params:
script: |
${PREPARE_SHELL}
bash ${DRIVERS_TOOLS}/.evergreen/serverless/teardown.sh
binary: "bash"
args:
- ${DRIVERS_TOOLS}/.evergreen/serverless/teardown.sh
- func: "teardown assets"
- func: "upload logs"
- func: "upload test results"
Expand Down Expand Up @@ -928,21 +915,18 @@ task_groups:
script: |
set -o errexit
set -x
${PREPARE_SHELL}
# ensure HEAD points to current commit
cd $DRIVERS_TOOLS
cd ${DRIVERS_TOOLS}
git add .
git commit -m "add files"
export AZUREOIDC_VMNAME_PREFIX="DRIVERS_TOOLS"
$DRIVERS_TOOLS/.evergreen/auth_oidc/azure/setup.sh
${DRIVERS_TOOLS}/.evergreen/auth_oidc/azure/setup.sh
teardown_group:
- command: shell.exec
- command: subprocess.exec
params:
shell: bash
script: |
${PREPARE_SHELL}
set -x
$DRIVERS_TOOLS/.evergreen/auth_oidc/azure/teardown.sh
binary: bash
args:
- ${DRIVERS_TOOLS}/.evergreen/auth_oidc/azure/teardown.sh
- func: "teardown assets"
- func: "upload logs"
- func: "upload test results"
Expand All @@ -964,21 +948,18 @@ task_groups:
script: |
set -o errexit
set -x
${PREPARE_SHELL}
# ensure HEAD points to current commit
cd $DRIVERS_TOOLS
cd ${DRIVERS_TOOLS}
git add .
git commit -m "add files"
export GCPOIDC_VMNAME_PREFIX="DRIVERS_TOOLS"
$DRIVERS_TOOLS/.evergreen/auth_oidc/gcp/setup.sh
${DRIVERS_TOOLS}/.evergreen/auth_oidc/gcp/setup.sh
teardown_group:
- command: shell.exec
- command: subprocess.exec
params:
shell: bash
script: |
${PREPARE_SHELL}
set -x
$DRIVERS_TOOLS/.evergreen/auth_oidc/gcp/teardown.sh
binary: bash
args:
- $DRIVERS_TOOLS/.evergreen/auth_oidc/gcp/teardown.sh
- func: "teardown assets"
- func: "upload logs"
- func: "upload test results"
Expand Down
3 changes: 3 additions & 0 deletions .evergreen/docker/run-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set -eu

SCRIPT_DIR=$(dirname ${BASH_SOURCE[0]})
. $SCRIPT_DIR/../handle-paths.sh

NAME=drivers-evergreen-tools
ENTRYPOINT=${ENTRYPOINT:-/root/local-entrypoint.sh}
IMAGE=${TARGET_IMAGE:-ubuntu20.04}
Expand All @@ -17,8 +18,10 @@ if [[ -z $PLATFORM && -n $ARCH ]]; then
PLATFORM="--platform linux/$ARCH"
fi

pushd $SCRIPT_DIR
USER="--build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g)"
docker build $PLATFORM -t $NAME $USER $IMAGE
popd
pushd $DRIVERS_TOOLS

# Remove existing mongodb and orchestration files
Expand Down
Loading

0 comments on commit 19d18c5

Please sign in to comment.