Skip to content

Commit

Permalink
Make docker usage self-contained (#565)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Dec 20, 2024
1 parent 87a632c commit c907e2d
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 60 deletions.
8 changes: 6 additions & 2 deletions .evergreen/auth_oidc/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
FROM drivers-evergreen-tools

COPY ./docker_entry.sh /root/docker_entry.sh
COPY ./docker_entry_base.sh /root/docker_entry_base.sh
COPY ./.evergreen/auth_oidc/docker_entry.sh /root/docker_entry.sh
COPY ./.evergreen/auth_oidc/docker_entry_base.sh /root/docker_entry_base.sh

ENV TOPOLOGY=replica_set
ENV DRIVERS_TOOLS=/root/drivers-tools
ENV MONGO_ORCHESTRATION_HOME=/root/drivers-tools/.evergreen/orchestration
ENV MONGODB_BINARIES=/root/drivers-tools/mongodb/bin
ENV DOCKER_RUNNING=true
29 changes: 21 additions & 8 deletions .evergreen/auth_oidc/start_local_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ EOF

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
Expand All @@ -37,18 +36,32 @@ if [ -z "$AWS_PROFILE" ]; then
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"
VOL=""
else
ENV="-e AWS_PROFILE=$AWS_PROFILE"
VOL="$VOL -v $HOME/.aws:/root/.aws"
VOL="-v $HOME/.aws:/root/.aws"
fi

test -t 1 && USE_TTY="-t"

echo "Drivers tools: $DRIVERS_TOOLS"
pushd ../docker
rm -rf ./ubuntu20.04/mongodb
rm -rf ./ubuntu20.04/orchestration
docker build -t drivers-evergreen-tools ./ubuntu20.04

if command -v podman &> /dev/null; then
DOCKER="podman --storage-opt ignore_chown_errors=true"
else
DOCKER=docker
fi
if [ -n "${DOCKER_COMMAND:-}" ]; then
DOCKER=$DOCKER_COMMAND
fi

# Build from the root directory so we can include files.
pushd $DRIVERS_TOOLS
PLATFORM="--platform linux/amd64"
cp .gitignore .dockerignore
USER="--build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g)"
$DOCKER build $PLATFORM -t drivers-evergreen-tools -f $SCRIPT_DIR/../docker/ubuntu20.04/Dockerfile $USER .
$DOCKER build $PLATFORM -t oidc-test $VOL -f $SCRIPT_DIR/Dockerfile $USER .
popd
docker build -t oidc-test .
docker run --rm -i $USE_TTY $VOL $ENV -p 27017:27017 -p 27018:27018 oidc-test $ENTRYPOINT

$DOCKER run --rm -i $USE_TTY $ENV -p 27017:27017 -p 27018:27018 oidc-test $ENTRYPOINT
25 changes: 16 additions & 9 deletions .evergreen/docker/run-client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@
set -eu

# Docker related variables.
IMAGE=${TARGET_IMAGE:-ubuntu20.04}
PLATFORM=${DOCKER_PLATFORM:-}
# e.g. --platform linux/amd64

if command -v podman &> /dev/null; then
DOCKER="podman --storage-opt ignore_chown_errors=true"
else
DOCKER=docker
fi
if [ -n "${DOCKER_COMMAND:-}" ]; then
DOCKER=$DOCKER_COMMAND
fi

# Mongo orchestration related variables.
MONGODB_VERSION=${MONGODB_VERSION:-latest}
TOPOLOGY=${TOPOLOGY:-replica_set}
Expand All @@ -18,19 +26,18 @@ SKIP_CRYPT_SHARED_LIB=${SKIP_CRYPT_SHARED_LIB:-false}
AUTH=${AUTH:-""}
SSL=${SSL:-""}

# Internal variables.
ROOT_DRIVERS_TOOLS=/root/drivers-evergeen-tools
MONGODB_BINARIES="ROOT_DRIVERS_TOOLS/.evergreen/docker/$IMAGE/mongodb/bin"
CONT_DRIVERS_TOOLS=/root/drivers-tools

# Build up the arguments.
ARGS="$PLATFORM --rm -i"
ARGS+=" -e MONGODB_VERSION=$MONGODB_VERSION -e TOPOLOGY=$TOPOLOGY"
ARGS+=" -e SSL=$SSL -e AUTH=$AUTH"
ARGS+=" -e MONGODB_BINARIES=$MONGODB_BINARIES"
ARGS+=" -e CRYPT_SHARED_LIB_PATH=$MONGODB_BINARIES/mongosh_crypt_v1.so"
ARGS+=" -e MONGO_ORCHESTRATION_HOME=$CONT_DRIVERS_TOOLS/.evergreen/orchestration"
ARGS+=" -e MONGODB_BINARIES=$CONT_DRIVERS_TOOLS/mongodb/bin"
ARGS+=" -e DOCKER_RUNNING=true"
ARGS+=" -e CRYPT_SHARED_LIB_PATH=$CONT_DRIVERS_TOOLS/mongosh_crypt_v1.so"
ARGS+=" -e ORCHESTRATION_FILE=$ORCHESTRATION_FILE"
ARGS+=" -e SKIP_CRYPT_SHARED_LIB=$SKIP_CRYPT_SHARED_LIB"
ARGS+=" -e DRIVERS_TOOLS=$ROOT_DRIVERS_TOOLS"

# Ensure host.docker.internal is available on MacOS.
if [ "$(uname -s)" = "Darwin" ]; then
Expand All @@ -47,7 +54,7 @@ test -t 1 && ARGS+=" -t"

# Map the cwd to /src and map in DRIVERS_TOOLS.
ARGS+=" -v `pwd`:/src"
ARGS+=" -v $DRIVERS_TOOLS:/root/drivers-evergreen-tools"
ARGS+=" -v $DRIVERS_TOOLS:$CONT_DRIVERS_TOOLS"

# Launch client docker container.
docker run $ARGS "$@"
$DOCKER run $ARGS "$@"
18 changes: 5 additions & 13 deletions .evergreen/docker/run-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,20 @@ if [[ -z $PLATFORM && -n $ARCH ]]; then
fi

if command -v podman &> /dev/null; then
DOCKER=podman
DOCKER="podman --storage-opt ignore_chown_errors=true"
else
DOCKER=docker
fi
if [ -n "${DOCKER_COMMAND:-}" ]; then
DOCKER=$DOCKER_COMMAND
fi

pushd $SCRIPT_DIR
# Build from the root directory so we can include files.
pushd $DRIVERS_TOOLS
cp .gitignore .dockerignore
USER="--build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g)"
$DOCKER build $PLATFORM -t $NAME $USER $IMAGE
$DOCKER build $PLATFORM -t $NAME -f $SCRIPT_DIR/$IMAGE/Dockerfile $USER .
popd
pushd $DRIVERS_TOOLS

# Remove existing mongodb and orchestration files
rm -rf $SCRIPT_DIR/$IMAGE/mongodb
rm -rf $SCRIPT_DIR/$IMAGE/orchestration

# Handle environment variables.
AUTH=${AUTH:-noauth}
Expand Down Expand Up @@ -77,10 +74,5 @@ fi
# If there is a tty, add the -t arg.
test -t 1 && ARGS+=" -t"

# Map in the DRIVERS_TOOLS directory.
ARGS+=" -v `pwd`:/root/drivers-evergreen-tools"

# Launch server container.
$DOCKER run $ARGS $NAME $ENTRYPOINT

popd
14 changes: 6 additions & 8 deletions .evergreen/docker/ubuntu18.04/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM artifactory.corp.mongodb.com/dockerhub/ubuntu:18.04
FROM ubuntu:18.04

RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get -qq update && apt-get -qq -y install --no-install-recommends \
Expand Down Expand Up @@ -46,12 +46,10 @@ RUN export DEBIAN_FRONTEND=noninteractive \
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/drivers-evergreen-tools/.evergreen/docker/ubuntu18.04/mongodb/bin
ENV MONGO_ORCHESTRATION_HOME=/root/drivers-evergreen-tools/.evergreen/docker/ubuntu18.04/orchestration
ENV DRIVERS_TOOLS=/root/drivers-tools
ENV MONGO_ORCHESTRATION_HOME=/root/drivers-tools/.evergreen/orchestration
ENV MONGODB_BINARIES=/root/drivers-tools/mongodb/bin
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
COPY . /root/drivers-tools
COPY .evergreen/docker/ubuntu18.04/*.sh /root
6 changes: 0 additions & 6 deletions .evergreen/docker/ubuntu18.04/base-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,4 @@ set -eu
cd $DRIVERS_TOOLS
make run-server

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

echo "Server started!"
14 changes: 6 additions & 8 deletions .evergreen/docker/ubuntu20.04/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM artifactory.corp.mongodb.com/dockerhub/ubuntu:20.04
FROM ubuntu:20.04

RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get -qq update && apt-get -qq -y install --no-install-recommends \
Expand All @@ -21,12 +21,10 @@ RUN export DEBIAN_FRONTEND=noninteractive && \
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/drivers-evergreen-tools/.evergreen/docker/ubuntu20.04/mongodb/bin
ENV MONGO_ORCHESTRATION_HOME=/root/drivers-evergreen-tools/.evergreen/docker/ubuntu20.04/orchestration
ENV DRIVERS_TOOLS=/root/drivers-tools
ENV MONGO_ORCHESTRATION_HOME=/root/drivers-tools/.evergreen/orchestration
ENV MONGODB_BINARIES=/root/drivers-tools/mongodb/bin
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
COPY . /root/drivers-tools
COPY .evergreen/docker/ubuntu20.04/*.sh /root
6 changes: 0 additions & 6 deletions .evergreen/docker/ubuntu20.04/base-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,4 @@ set -eu
cd $DRIVERS_TOOLS
make run-server

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

echo "Server started!"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ mo-expansion.sh
.evergreen/socks5srv
.evergreen/mongodl
.evergreen/mongosh-dl
.dockerignore

# Azure functions.
.python_packages/
Expand Down

0 comments on commit c907e2d

Please sign in to comment.