Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GODRIVER-2924 Add docker file support #352

Merged
merged 46 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
a5d25c4
GODRIVER-2924 Add docker file support
blink1073 Sep 22, 2023
a4041ba
add evg test
blink1073 Sep 22, 2023
f7d10d5
fix syntax
blink1073 Sep 22, 2023
aba0d92
add to build variant
blink1073 Sep 22, 2023
18a1b1f
cleanup
blink1073 Sep 22, 2023
4a247e2
fix orch file
blink1073 Sep 22, 2023
1b604c9
remove interactive flag
blink1073 Sep 22, 2023
4bc01ab
clean up and add oidc test
blink1073 Sep 23, 2023
d70f0f9
fix handling of tty
blink1073 Sep 23, 2023
61b03f4
update readme
blink1073 Sep 24, 2023
66a4d53
enforce bash
blink1073 Sep 25, 2023
e6d336e
fix handling of python3
blink1073 Sep 25, 2023
bfb9eca
try again
blink1073 Sep 25, 2023
d8eba1c
cleanup
blink1073 Sep 25, 2023
b6df968
Update .evergreen/run-orchestration.sh
blink1073 Sep 25, 2023
0b009e6
address review
blink1073 Sep 25, 2023
1e19b39
clean up file permissions and test results
blink1073 Sep 26, 2023
073c601
use explicit binary root
blink1073 Sep 26, 2023
d60a85c
move crypt_shared into container
blink1073 Sep 26, 2023
b16429b
fix echo
blink1073 Sep 26, 2023
0feea83
fix test file handling
blink1073 Sep 26, 2023
e0db6ab
try again
blink1073 Sep 26, 2023
62006d9
try again
blink1073 Sep 26, 2023
e21f839
more oidc debug
blink1073 Sep 26, 2023
673cdb4
fix syntax
blink1073 Sep 26, 2023
fd0a8f9
fix unbound
blink1073 Sep 26, 2023
2102924
fix script
blink1073 Sep 26, 2023
24de91d
more oidc fixes
blink1073 Sep 26, 2023
651c1f3
more oidc fixes
blink1073 Sep 26, 2023
1583ea4
update permissions handling
blink1073 Sep 26, 2023
92a8b0b
remove popd
blink1073 Sep 26, 2023
ca7bef9
fix entry point usage
blink1073 Sep 26, 2023
60d8a82
better test
blink1073 Sep 26, 2023
32d6f9a
add missing file
blink1073 Sep 26, 2023
f99efce
Update .evergreen/auth_oidc/start_local_server.sh
blink1073 Sep 26, 2023
8e096b2
Update .evergreen/start-orchestration.sh
blink1073 Sep 26, 2023
6337e16
Update .evergreen/run-orchestration.sh
blink1073 Sep 26, 2023
3d36032
Update .evergreen/docker/ubuntu20.04/base-entrypoint.sh
blink1073 Sep 26, 2023
c31bb8a
address review
blink1073 Sep 26, 2023
d834893
fix mo-expansion.sh
blink1073 Sep 26, 2023
6be304c
syntax
blink1073 Sep 26, 2023
2e783c2
fix test entry point
blink1073 Sep 26, 2023
b16351f
Update .evergreen/config.yml
blink1073 Sep 27, 2023
bb9d951
fix handling of python binary
blink1073 Sep 27, 2023
1df9cb3
Update .evergreen/run-orchestration.sh
blink1073 Sep 28, 2023
5c9047e
Update .evergreen/run-orchestration.sh
blink1073 Sep 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions .evergreen/auth_oidc/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
FROM ubuntu:20.04
FROM drivers-evergreen-tools

RUN apt-get -qq update && apt-get -qqy -o DPkg::Lock::Timeout=-1 install --no-install-recommends \
git \
ca-certificates \
curl \
wget \
sudo \
gnupg \
python \
python3 \
python3-virtualenv \
lsof \
libsnmp35 \
net-tools \
&& rm -rf /var/lib/apt/lists/*
COPY ./docker_entry.sh /root/docker_entry.sh
COPY ./docker_entry_base.sh /root/docker_entry_base.sh

COPY ./docker_entry.sh /home/root/docker_entry.sh

ENTRYPOINT ["/bin/bash", "/home/root/docker_entry.sh"]
ENV TOPOLOGY=replica_set
20 changes: 2 additions & 18 deletions .evergreen/auth_oidc/docker_entry.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,6 @@
# Entry point for Dockerfile for launching an oidc-enabled server.
#
set -eux
export MONGODB_VERSION=latest
export TOPOLOGY=replica_set
export ORCHESTRATION_FILE=auth-oidc.json
export DRIVERS_TOOLS=$HOME/drivers-evergreen-tools
export PROJECT_ORCHESTRATION_HOME=$DRIVERS_TOOLS/.evergreen/orchestration
export MONGO_ORCHESTRATION_HOME=$HOME
export NO_IPV6=${NO_IPV6:-""}

if [ ! -d $DRIVERS_TOOLS ]; then
git clone --branch DRIVERS-2415 https://github.com/blink1073/drivers-evergreen-tools.git $DRIVERS_TOOLS
fi

cd $DRIVERS_TOOLS/.evergreen/auth_oidc
. ./activate-authoidcvenv.sh
python oidc_write_orchestration.py

bash $DRIVERS_TOOLS/.evergreen/run-orchestration.sh
$DRIVERS_TOOLS/mongodb/bin/mongosh $DRIVERS_TOOLS/.evergreen/auth_oidc/setup_oidc.js
tail -f $MONGO_ORCHESTRATION_HOME/server.log
bash /root/docker_entry_base.sh
tail -f $MONGO_ORCHESTRATION_HOME/server.log
20 changes: 20 additions & 0 deletions .evergreen/auth_oidc/docker_entry_base.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
#
# Entry point for Dockerfile for launching an oidc-enabled server.
#
set -eu
export ORCHESTRATION_FILE=auth-oidc.json

trap "rm -rf authoidcvenv" EXIT HUP

rm -f $DRIVERS_TOOLS/results.json
cd $DRIVERS_TOOLS/.evergreen/auth_oidc
rm -rf authoidcvenv
. ./activate-authoidcvenv.sh
python oidc_write_orchestration.py

bash /root/base-entrypoint.sh

$MONGODB_BINARIES/mongosh $DRIVERS_TOOLS/.evergreen/auth_oidc/setup_oidc.js

echo "Server started!"
3 changes: 2 additions & 1 deletion .evergreen/auth_oidc/oidc_write_orchestration.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def azure():
orch_file = os.path.abspath(os.path.join(HERE, '..', 'orchestration', 'configs', 'servers', 'auth-oidc.json'))
with open(orch_file, 'w') as fid:
json.dump(data, fid, indent=4)

print(f"Wrote OIDC config to {orch_file}")

def main():
print("Bootstrapping OIDC config")
Expand Down Expand Up @@ -126,6 +126,7 @@ def main():
orch_file = os.path.abspath(os.path.join(HERE, '..', 'orchestration', 'configs', 'replica_sets', 'auth-oidc.json'))
with open(orch_file, 'w') as fid:
json.dump(data, fid, indent=4)
print(f"Wrote OIDC config to {orch_file}")


if __name__ == '__main__':
Expand Down
33 changes: 24 additions & 9 deletions .evergreen/auth_oidc/start_local_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,31 @@
# prequisites and usage.
#
set -eux
if [[ -z "${AWS_ROLE_ARN}" || -z "${AWS_ACCESS_KEY_ID}" || -z "${AWS_SECRET_ACCESS_KEY}" ]]; then
echo "Missing AWS credentials"
exit 1
fi

DRIVERS_TOOLS=${DRIVERS_TOOLS:-$(readlink -f ../..)}
echo "Drivers tools: $DRIVERS_TOOLS"
ENTRYPOINT=${ENTRYPOINT:-/root/docker_entry.sh}
USE_TTY=""
VOL="-v ${DRIVERS_TOOLS}:/root/drivers-evergreen-tools"
AWS_PROFILE=${AWS_PROFILE:-""}

if [ -z "$AWS_PROFILE" ]; then
if [[ -z "${AWS_SESSION_TOKEN}" || -z "${AWS_ACCESS_KEY_ID}" || -z "${AWS_SECRET_ACCESS_KEY}" ]]; then
echo "Please set AWS_PROFILE or set AWS credentials environment variables" 1>&2
exit 1
fi
ENV="-e AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID"
ENV="$ENV -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY"
else
ENV="-e AWS_PROFILE=$AWS_PROFILE"
VOL="$VOL -v $HOME/.aws:/root/.aws"
fi

rm -rf $DRIVERS_TOOLS/.evergreen/auth_oidc/authoidcvenv
rm -rf $DRIVERS_TOOLS/mongodb
rm -rf $DRIVERS_TOOLS/legacy-shell-download
rm -rf $DRIVERS_TOOLS/mongosh
test -t 1 && USE_TTY="-t"

echo "Drivers tools: $DRIVERS_TOOLS"
pushd ../docker
docker build -t drivers-evergreen-tools ./ubuntu20.04
popd
docker build -t oidc-test .
docker run -it -v ${DRIVERS_TOOLS}:/home/root/drivers-evergreen-tools -p 27017:27017 -p 27018:27018 -e HOME=/home/root -e AWS_ROLE_ARN=${AWS_ROLE_ARN} -e AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} -e AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} -e NO_IPV6=true oidc-test
docker run --rm -i $USE_TTY $VOL $ENV -p 27017:27017 -p 27018:27018 oidc-test $ENTRYPOINT
46 changes: 45 additions & 1 deletion .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,39 @@ functions:
CRYPT_SHARED_LIB_PATH="${CRYPT_SHARED_LIB_PATH}" \
sh ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh

"run docker test":
- command: shell.exec
type: test
params:
working_dir: "src"
script: |
${PREPARE_SHELL}
set -ex
cd $DRIVERS_TOOLS/.evergreen/docker
ENTRYPOINT=/root/test-entrypoint.sh bash run-local.sh
# Generate a test results file
cd ${PROJECT_DIRECTORY}
make test

"run oidc test":
- command: ec2.assume_role
params:
role_arn: ${aws_test_secrets_role}
- command: shell.exec
type: test
params:
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
export ENTRYPOINT=/root/docker_entry_base.sh
bash start_local_server.sh
blink1073 marked this conversation as resolved.
Show resolved Hide resolved
# Generate a test results file
cd ${PROJECT_DIRECTORY}
make test

"cleanup":
- command: shell.exec
params:
Expand Down Expand Up @@ -722,6 +755,16 @@ tasks:
commands:
- func: "run serverless tests"

- name: "test-docker"
tags: ["latest"]
commands:
- func: "run docker test"

- name: "test-oidc"
tags: ["latest"]
commands:
- func: "run oidc test"

# }}}


Expand Down Expand Up @@ -943,6 +986,8 @@ buildvariants:
- name: "test-3.6-replica_set"
- name: "test-3.6-sharded_cluster"
- name: "test-3.6-standalone"
- name: "test-docker"
- name: "test-oidc"

- matrix_name: "tests-nossl"
matrix_spec: {"os-nossl": "*", auth: "*", ssl: "nossl" }
Expand Down Expand Up @@ -1073,4 +1118,3 @@ buildvariants:
# Debian 7.1 does not support MongoDB 2.4
# SUSE12 x86_64 is only supported by MongoDB 3.2+
# vim: set et sw=2 ts=2 :

43 changes: 43 additions & 0 deletions .evergreen/docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Drivers Evergreen Tools Dockerfile

The ``Dockerfile`` and scripts in the subdirector(ies) serve dual purposes.

- Run a local server in docker container.
- Extend and run a driver test in a docker container.

You will need Docker (or podman aliased to Docker) installed and running
locally.

# Run Local Server

To run a local server, change to this directory and run:

```bash
bash ./run-local.sh
```

This will build the docker image and run it with appropriate settings.
Note that any of the environment variables used by `run-orchestration`
will be passed through to the container.
The appropriate port(s) will be exposed, allowing you to run local test against
the running docker container.

The default image can be overridden with `IMAGE``, and the entrypoint with `ENTRYPOINT`.
To use a specific architecture, use `PLATFORM`, e.g. `--platform linux/amd64`.

## Driver Testing in Docker

To extend this image and run against a driver test suite, first build the
image locally.

```bash
docker build -t drivers-evergreen-tools .
```

Then, in your `Dockerfile`, use `FROM drivers-evergreen-tools`.

When running your derived image, use `-v $DRIVERS_TOOLS:/root/drivers-evergreen-tools`
to use the local checkout.

In your entry point script, run `run-orchestration.sh` before running your test suite.
Note that you will probably want to expose the environment variables as is done in `run-local.sh`.
47 changes: 47 additions & 0 deletions .evergreen/docker/run-local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
#
# Run a local MongoDB orchestration inside a docker container
#
set -eu

NAME=drivers-evergreen-tools
ENTRYPOINT=${ENTRYPOINT:-/root/local-entrypoint.sh}
IMAGE=${TARGET_IMAGE:-ubuntu20.04}
PLATFORM=${DOCKER_PLATFORM:-}
# e.g. --platform linux/amd64

docker build $PLATFORM -t $NAME $IMAGE
cd ../..

AUTH=${AUTH:-noauth}
SSL=${SSL:-nossl}
TOPOLOGY=${TOPOLOGY:-server}
LOAD_BALANCER=${LOAD_BALANCER:-}
STORAGE_ENGINE=${STORAGE_ENGINE:-}
REQUIRE_API_VERSION=${REQUIRE_API_VERSION:-}
DISABLE_TEST_COMMANDS=${DISABLE_TEST_COMMANDS:-}
MONGODB_VERSION=${MONGODB_VERSION:-latest}
MONGODB_DOWNLOAD_URL=${MONGODB_DOWNLOAD_URL:-}
ORCHESTRATION_FILE=${ORCHESTRATION_FILE:-basic.json}

ENV="-e MONGODB_VERSION=$MONGODB_VERSION"
ENV+=" -e TOPOLOGY=$TOPOLOGY"
ENV+=" -e AUTH=$AUTH"
ENV+=" -e SSL=$SSL"
ENV+=" -e ORCHESTRATION_FILE=$ORCHESTRATION_FILE"
ENV+=" -e LOAD_BALANCER=$LOAD_BALANCER"
ENV+=" -e STORAGE_ENGINE=$STORAGE_ENGINE"
ENV+=" -e REQUIRE_API_VERSION=$REQUIRE_API_VERSION"
ENV+=" -e DISABLE_TEST_COMMANDS=$DISABLE_TEST_COMMANDS"
ENV+=" -e MONGODB_DOWNLOAD_URL=$MONGODB_DOWNLOAD_URL"

if [ "$TOPOLOGY" == "server" ]; then
PORT="-p 27017:2017"
else
PORT="-p 27017:2017 -p 27018:2018 -p 27019:2019"
fi
USE_TTY=""
test -t 1 && USE_TTY="-t"
VOL="-v `pwd`:/root/drivers-evergreen-tools"

docker run $PLATFORM --rm $ENV $PORT $VOL -i $USE_TTY $NAME $ENTRYPOINT
eramongodb marked this conversation as resolved.
Show resolved Hide resolved
33 changes: 33 additions & 0 deletions .evergreen/docker/ubuntu20.04/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM ubuntu:20.04

RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get -qq update && apt-get -qqy install --no-install-recommends \
git \
ca-certificates \
curl \
wget \
sudo \
gnupg \
python \
python3 \
python3.8-venv \
lsof \
software-properties-common \
libsnmp35 \
net-tools \
&& rm -rf /var/lib/apt/lists/*

ARG USER_ID
ARG GROUP_ID

ENV DRIVERS_TOOLS=/root/drivers-evergreen-tools
ENV PROJECT_ORCHESTRATION_HOME=/root/drivers-evergreen-tools/.evergreen/orchestration
ENV MONGODB_BINARIES=/root/mongodb/bin
ENV MONGODB_BINARY_ROOT=/root
ENV MONGO_ORCHESTRATION_HOME=/root
ENV SKIP_LEGACY_SHELL=1
ENV DOCKER_RUNNING=true

COPY ./local-entrypoint.sh /root/local-entrypoint.sh
COPY ./base-entrypoint.sh /root/base-entrypoint.sh
COPY ./test-entrypoint.sh /root/test-entrypoint.sh
14 changes: 14 additions & 0 deletions .evergreen/docker/ubuntu20.04/base-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -eu

rm -f $DRIVERS_TOOLS/results.json
cd $DRIVERS_TOOLS/.evergreen
bash run-orchestration.sh

# Preserve host permissions of files we have created.
cd $DRIVERS_TOOLS
files=(results.json uri.txt .evergreen/mongo_crypt_v1.so .evergreen/mo-expansion.yml)
chown --reference=action.yml "${files[@]}"
chmod --reference=action.yml "${files[@]}"

echo "Server started!"
5 changes: 5 additions & 0 deletions .evergreen/docker/ubuntu20.04/local-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -eu

bash /root/base-entrypoint.sh
tail -f $MONGO_ORCHESTRATION_HOME/server.log
7 changes: 7 additions & 0 deletions .evergreen/docker/ubuntu20.04/test-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -eu

bash /root/base-entrypoint.sh
source $DRIVERS_TOOLS/.evergreen/mo-expansion.sh
$MONGODB_BINARIES/mongosh --eval 'db'
echo "Test complete!"
Loading
Loading