Skip to content

Commit 0c11d8c

Browse files
committed
Local Edit feature
1 parent def641b commit 0c11d8c

File tree

3 files changed

+48
-10
lines changed

3 files changed

+48
-10
lines changed

Dockerfile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,19 @@ RUN apt-get update && apt-get install -y \
2121
rm -rf /var/lib/apt/lists/*
2222

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

3131
ENV HOME /home/ubuntu
32+
ENV WORKSPACE /workspace
3233
ENV CDRIVER_VERSION ${DRIVER_C_VERSION}
33-
ENV CPPDRIVER_VERSION ${DRIVER_VERSION}
3434
ENV LD_LIBRARY_PATH /usr/local/lib
35+
ENV DRIVER_VERSION ${DRIVER_VERSION}
36+
ENV MONGODB_URI ${MONGODB_URI}
3537

3638
WORKDIR ${HOME}
3739

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

4749
RUN cd ${HOME}
4850

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

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

6264
USER ubuntu
6365

64-
WORKDIR ${HOME}/cxx
66+
WORKDIR ${WORKSPACE}/cxx
6567

66-
CMD ["/bin/bash"]
68+
ENTRYPOINT ["/bin/bash", "-c"]

README.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,29 @@ Have Docker running on your machine. You can download and install from: https://
1616

1717
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/).
1818

19-
## Build Steps
19+
20+
## Execution Steps
21+
22+
1. Build Docker image with a tag name. Within the top level directory execute:
23+
```
24+
docker build . -t start-cxx
25+
```
26+
This will build a docker image with a tag name `start-cxx`.
27+
28+
2. Execute the helper shell script followed by the MongoDB URI that you would like to connect to.
29+
```
30+
./get-started.sh "mongodb+srv://usr:pwd@example.mongodb.net/dbname?retryWrites=true"
31+
```
32+
33+
To use a different driver version, specify the driver version after the MongoDB URI. For example:
34+
```
35+
./get-started.sh "mongodb+srv://usr:pwd@example.mongodb.net/dbname?retryWrites=true" 3.6.0
36+
```
37+
38+
39+
## Alternative Execution Steps (without helper)
40+
41+
#### Build Steps
2042
2143
1. Build Docker image with a tag name. Within this directory execute:
2244
* To use the default driver version and specify `MONGODB_URI`:
@@ -32,12 +54,12 @@ In order to execute the code example, you need to specify `MONGODB_URI` environm
3254
3355
2. Run the Docker image by executing:
3456
```
35-
docker run --tty --interactive --hostname cxx start-cxx
57+
docker run --tty --interactive --hostname cxx start-cxx bash
3658
```
3759
3860
The command above will run a `start-cxx` tagged Docker image. Sets the hostname as `cxx`.
3961
40-
## Execution Steps
62+
#### Execution
4163
4264
1. Compile and execute the code example by following below steps:
4365
* `c++ --std=c++11 getstarted.cpp -o getstarted $(pkg-config --cflags --libs libmongocxx)`

get-started.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
MONGODB_URI=${1}
3+
if [ -z ${MONGODB_URI} ]
4+
then
5+
read -p "MONGODB URI (Required): " MONGODB_URI
6+
fi
7+
8+
DRIVER_VERSION=${2:-3.6.2}
9+
echo "Executing ... "
10+
docker run --rm -e MONGODB_URI=${MONGODB_URI} \
11+
-v "$(pwd)":/workspace \
12+
-w /workspace/cxx start-cxx \
13+
"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; \
14+
./getstarted"

0 commit comments

Comments
 (0)