-
Notifications
You must be signed in to change notification settings - Fork 891
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-2989 [master] A Dockerfile for local development #1428
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Dockerfile for Go Driver local development. | ||
|
||
# Build libmongocrypt in a separate build stage. | ||
FROM ubuntu:20.04 as libmongocrypt | ||
|
||
RUN apt-get -qq update && \ | ||
apt-get -qqy install --no-install-recommends \ | ||
git \ | ||
ca-certificates \ | ||
curl \ | ||
build-essential \ | ||
libssl-dev \ | ||
python | ||
|
||
COPY etc/install-libmongocrypt.sh /root/install-libmongocrypt.sh | ||
RUN cd /root && bash ./install-libmongocrypt.sh | ||
|
||
|
||
# Inherit from the drivers-evergreen-tools image and copy in the files | ||
# from the libmongocrypt build stage. | ||
FROM drivers-evergreen-tools | ||
|
||
RUN export DEBIAN_FRONTEND=noninteractive && \ | ||
export TZ=Etc/UTC && \ | ||
apt-get -qq update && \ | ||
apt-get -qqy install --no-install-recommends \ | ||
pkg-config \ | ||
tzdata \ | ||
gpg \ | ||
apt-utils \ | ||
make && \ | ||
apt-add-repository ppa:longsleep/golang-backports && \ | ||
apt-get -qq update && \ | ||
apt-get -qqy install --no-install-recommends golang-go && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
COPY ./etc/docker_entry.sh /root/docker_entry.sh | ||
|
||
COPY --from=libmongocrypt /root/install /root/install | ||
|
||
ENTRYPOINT ["/bin/bash", "/root/docker_entry.sh"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,9 @@ If you are working on a bug or feature listed in Jira, please include the ticket | |
|
||
The driver tests can be run against several database configurations. The most simple configuration is a standalone mongod with no auth, no ssl, and no compression. To run these basic driver tests, make sure a standalone MongoDB server instance is running at localhost:27017. To run the tests, you can run `make` (on Windows, run `nmake`). This will run coverage, run go-lint, run go-vet, and build the examples. | ||
|
||
You can install `libmongocrypt` locally by running `bash etc/build-libmongocrypt.sh`, which will create an `install` directory | ||
in the repository top level directory. On Windows you will also need to add `c:/libmongocrypt/` to your `PATH`. | ||
|
||
### Testing Different Topologies | ||
|
||
To test a **replica set** or **sharded cluster**, set `MONGODB_URI="<connection-string>"` for the `make` command. | ||
|
@@ -111,6 +114,24 @@ The usage of host.docker.internal comes from the [Docker networking documentatio | |
|
||
There is currently no arm64 support for the go1.x runtime, see [here](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html). Known issues running on linux/arm64 include the inability to network with the localhost from the public.ecr.aws/lambda/go Docker image. | ||
|
||
### Testing in Docker | ||
|
||
We support local testing in Docker. Ensure ``docker`` is installed and running, and then run: | ||
|
||
```bash | ||
bash etc/run_docker.sh | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could be helpful to make this a make target: .PHONY: build-tests-docker
build-tests-docker:
etc/run_docker.sh There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It gets tricky with how to pass args. I thought we eventually want to remove the Makefile altogether? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha, that makes sense. Thanks! |
||
``` | ||
|
||
The script takes an optional argument for the ``MAKEFILE_TARGET`` and allows for some environment variable overrides. | ||
The docker container has the required binaries, including libmongocrypt. | ||
The entry script starts a MongoDB topology, and then executes the desired ``MAKEFILE_TARGET``. | ||
|
||
For example, to test against a sharded cluster, using enterprise auth, run: | ||
|
||
```bash | ||
TOPOLOGY=sharded_cluster bash etc/run_docker.sh evg-test-enterprise-auth | ||
``` | ||
|
||
## Talk To Us | ||
|
||
If you want to work on the driver, write documentation, or have questions/complaints, please reach out to us either via [MongoDB Community Forums](https://community.mongodb.com/tags/c/drivers-odms-connectors/7/go-driver) or by creating a Question issue in [Jira](https://jira.mongodb.org/secure/CreateIssue!default.jspa). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Entry point for Dockerfile for launching a server and running a go test. | ||
# | ||
set -eux | ||
|
||
# Start the server. | ||
bash /root/base-entrypoint.sh | ||
source $DRIVERS_TOOLS/.evergreen/mo-expansion.sh | ||
|
||
# Prep files. | ||
cd /src | ||
rm -f test.suite | ||
cp -r $HOME/install ./install | ||
export PATH="$MONGODB_BINARIES:$PATH" | ||
|
||
# Run the test. | ||
bash ./.evergreen/run-tests.sh |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env bash | ||
# install libmongocrypt | ||
# This script installs libmongocrypt into an "install" directory. | ||
set -eux | ||
|
||
LIBMONGOCRYPT_TAG="1.8.2" | ||
|
||
# Install libmongocrypt based on OS. | ||
if [ "Windows_NT" = "${OS:-}" ]; then | ||
mkdir -p c:/libmongocrypt/include | ||
mkdir -p c:/libmongocrypt/bin | ||
echo "fetching build for Windows ... begin" | ||
mkdir libmongocrypt-all | ||
cd libmongocrypt-all | ||
# The following URL is published from the upload-all task in the libmongocrypt Evergreen project. | ||
curl https://mciuploads.s3.amazonaws.com/libmongocrypt/all/$LIBMONGOCRYPT_TAG/libmongocrypt-all.tar.gz -o libmongocrypt-all.tar.gz | ||
tar -xf libmongocrypt-all.tar.gz | ||
cd .. | ||
cp libmongocrypt-all/windows-test/bin/mongocrypt.dll c:/libmongocrypt/bin | ||
cp libmongocrypt-all/windows-test/include/mongocrypt/*.h c:/libmongocrypt/include | ||
|
||
rm -rf libmongocrypt-all | ||
echo "fetching build for Windows ... end" | ||
else | ||
rm -rf libmongocrypt | ||
git clone https://github.com/mongodb/libmongocrypt --depth=1 --branch $LIBMONGOCRYPT_TAG 2> /dev/null | ||
if ! ( ./libmongocrypt/.evergreen/compile.sh >| output.txt 2>&1 ); then | ||
cat output.txt 1>&2 | ||
exit 1 | ||
fi | ||
mv output.txt install | ||
rm -rf libmongocrypt | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Script to run a test suite in docker locally | ||
set -eux | ||
|
||
if [ -z "$DRIVERS_TOOLS" ]; then | ||
echo "Please set DRIVERS_TOOLS env variable." | ||
exit 1 | ||
fi | ||
PLATFORM=${DOCKER_PLATFORM:-} | ||
|
||
pushd $DRIVERS_TOOLS/.evergreen/docker/ubuntu20.04 | ||
docker build $PLATFORM -t drivers-evergreen-tools . | ||
popd | ||
docker build $PLATFORM -t go-test . | ||
|
||
# Handle environment variables and optional positional arg for the makefile target. | ||
|
||
MAKEFILE_TARGET=${1:-evg-test-versioned-api} | ||
MONGODB_VERSION=${MONGODB_VERSION:-latest} | ||
TOPOLOGY=${TOPOLOGY:-replica_set} | ||
ORCHESTRATION_FILE=${ORCHESTRATION_FILE:-basic.json} | ||
AUTH=${AUTH:-""} | ||
SSL=${SSL:=""} | ||
GO_BUILD_TAGS=${GO_BUILD_TAGS:-""} | ||
|
||
ENV="-e MONGODB_VERSION=$MONGODB_VERSION -e TOPOLOGY=$TOPOLOGY" | ||
ENV="$ENV -e MAKEFILE_TARGET=$MAKEFILE_TARGET -e AUTH=$AUTH" | ||
ENV="$ENV -e ORCHESTRATION_FILE=$ORCHESTRATION_FILE -e SSL=$SSL" | ||
ENV="$ENV -e GO_BUILD_TAGS=$GO_BUILD_TAGS" | ||
|
||
VOL="-v `pwd`:/src" | ||
VOL="$VOL -v $DRIVERS_TOOLS:/root/drivers-evergreen-tools" | ||
USE_TTY="" | ||
test -t 1 && USE_TTY="-t" | ||
|
||
docker run $PLATFORM --rm $VOL $ENV -i $USE_TTY go-test | ||
if [ -f "test.suite" ]; then | ||
tail test.suite | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we include something about setting the DRIVER_TOOLS environment variable, rather than being informed only via error? E.g.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I applied this comment in the follow up PR: #1430