Skip to content

Commit

Permalink
Local Edit feature
Browse files Browse the repository at this point in the history
  • Loading branch information
sindbach committed Jan 8, 2021
1 parent def641b commit 0c11d8c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
16 changes: 9 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ RUN apt-get update && apt-get install -y \
rm -rf /var/lib/apt/lists/*

RUN export uid=1000 gid=1000 && \
mkdir -p /home/ubuntu && \
mkdir -p /home/ubuntu && mkdir /workspace && \
echo "ubuntu:x:${uid}:${gid}:Developer,,,:/home/ubuntu:/bin/bash" >> /etc/passwd && \
echo "ubuntu:x:${uid}:" >> /etc/group && \
echo "ubuntu ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/ubuntu && \
chmod 0440 /etc/sudoers.d/ubuntu && \
chown ${uid}:${gid} -R /home/ubuntu

ENV HOME /home/ubuntu
ENV WORKSPACE /workspace
ENV CDRIVER_VERSION ${DRIVER_C_VERSION}
ENV CPPDRIVER_VERSION ${DRIVER_VERSION}
ENV LD_LIBRARY_PATH /usr/local/lib
ENV DRIVER_VERSION ${DRIVER_VERSION}
ENV MONGODB_URI ${MONGODB_URI}

WORKDIR ${HOME}

Expand All @@ -46,10 +48,10 @@ RUN cd ${HOME}/mongo-c-driver-${CDRIVER_VERSION} && \

RUN cd ${HOME}

RUN wget https://github.com/mongodb/mongo-cxx-driver/archive/r${CPPDRIVER_VERSION}.tar.gz && \
tar -xzf r${CPPDRIVER_VERSION}.tar.gz
RUN wget https://github.com/mongodb/mongo-cxx-driver/archive/r${DRIVER_VERSION}.tar.gz && \
tar -xzf r${DRIVER_VERSION}.tar.gz

RUN cd ${HOME}/mongo-cxx-driver-r${CPPDRIVER_VERSION}/build && \
RUN cd ${HOME}/mongo-cxx-driver-r${DRIVER_VERSION}/build && \
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_VERSION=0.0.1 -DCMAKE_PREFIX_PATH=/usr/local .. && \
make EP_mnmlstc_core && \
make && make install
Expand All @@ -61,6 +63,6 @@ RUN chown -R ubuntu ${HOME}/cxx && chmod -R 750 ${HOME}/cxx

USER ubuntu

WORKDIR ${HOME}/cxx
WORKDIR ${WORKSPACE}/cxx

CMD ["/bin/bash"]
ENTRYPOINT ["/bin/bash", "-c"]
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,29 @@ Have Docker running on your machine. You can download and install from: https://

In order to execute the code example, you need to specify `MONGODB_URI` environment variable to connect to a MongoDB cluster. If you don't have any you can create one by signing up [MongoDB Atlas Free-tier M0](https://docs.atlas.mongodb.com/getting-started/).

## Build Steps

## Execution Steps

1. Build Docker image with a tag name. Within the top level directory execute:
```
docker build . -t start-cxx
```
This will build a docker image with a tag name `start-cxx`.

2. Execute the helper shell script followed by the MongoDB URI that you would like to connect to.
```
./get-started.sh "mongodb+srv://usr:[email protected]/dbname?retryWrites=true"
```
To use a different driver version, specify the driver version after the MongoDB URI. For example:
```
./get-started.sh "mongodb+srv://usr:[email protected]/dbname?retryWrites=true" 3.6.0
```
## Alternative Execution Steps (without helper)
#### Build Steps
1. Build Docker image with a tag name. Within this directory execute:
* To use the default driver version and specify `MONGODB_URI`:
Expand All @@ -32,12 +54,12 @@ In order to execute the code example, you need to specify `MONGODB_URI` environm
2. Run the Docker image by executing:
```
docker run --tty --interactive --hostname cxx start-cxx
docker run --tty --interactive --hostname cxx start-cxx bash
```
The command above will run a `start-cxx` tagged Docker image. Sets the hostname as `cxx`.
## Execution Steps
#### Execution
1. Compile and execute the code example by following below steps:
* `c++ --std=c++11 getstarted.cpp -o getstarted $(pkg-config --cflags --libs libmongocxx)`
Expand Down
14 changes: 14 additions & 0 deletions get-started.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
MONGODB_URI=${1}
if [ -z ${MONGODB_URI} ]
then
read -p "MONGODB URI (Required): " MONGODB_URI
fi

DRIVER_VERSION=${2:-3.6.2}
echo "Executing ... "
docker run --rm -e MONGODB_URI=${MONGODB_URI} \
-v "$(pwd)":/workspace \
-w /workspace/cxx start-cxx \
"c++ --std=c++11 ./getstarted.cpp -o getstarted -I/usr/local/include/mongocxx/v_noabi -I/usr/local/include/bsoncxx/v_noabi -L/usr/local/lib -lmongocxx -lbsoncxx; \
./getstarted"

0 comments on commit 0c11d8c

Please sign in to comment.