cbrz / mountebank-grpc

MIT License
20 stars 11 forks source link

Working Dockerfile for mountebank-grpc #18

Open bobruub opened 3 years ago

bobruub commented 3 years ago

Hi,

I was hoping someone could help me and provide me a working docker file for mountebank-grpc.

I've been poking at it for a couple of days now and always end up with error creating imposter: [{"code":"bad data","message":"the grpc protocol is not yet supported"}]

Current attempt:

FROM node:8.2

EXPOSE 2525
#CMD ["mb", "--configfile", "/tmp/perf_sven_grpc_poc/grpc_impostor.ejs", "--protofile","/tmp/perf_sven_grpc_poc/protocols.json","--allowInjection",  "--logfile", "/var/log/mb_gprc.log", "--port", "6105" ]

ENV MOUNTEBANK_VERSION=1.15.0

RUN cd /usr/lib/node_modules; npm install -g mountebank@${MOUNTEBANK_VERSION} --production \
 && npm cache clean --force 2>/dev/null \
 && rm -rf /tmp/npm* \
 && npm install xml2js \
 && npm install dateformat \
 && npm install node-uuid \
 && npm install url \
 && npm install sax \
 && npm install xmlbuilder

RUN mkdir /tmp/perf_sven_grpc_poc
RUN cd /tmp/perf_sven_grpc_poc
RUN git clone https://github.com/cbrz/mountebank-grpc
RUN npm install

COPY ./protocols.json /tmp/perf_sven_grpc_poc/protocols.json
COPY ./01_grpc_unary_unary.ejs /tmp/perf_sven_grpc_poc/01_grpc_unary_unary.ejs
COPY ./grpc_impostor.ejs /tmp/perf_sven_grpc_poc/grpc_impostor.ejs
COPY ./start_mb_grpc.sh /tmp/perf_sven_grpc_poc/start_mb_grpc.sh
cbrz commented 3 years ago

Hi @bobruub ,

I haven't had a lot of time to look into things (been busy with other projects)... There's been changes to grpc where some of the mock here was probably made obsolete. This is applicable to all custom protocols.

For mountebank-grpc it should go somehting like this (i did this on a win10 host, so adjust accordingly):

Directory Structure

C:\mydir\mountebank-grpc
C:\mydir\mountebank-grpc\mountebank-grpc    # cloned repo
C:\mydir\mountebank-grpc\Dockerfile                 # Dockerfile below
C:\mydir\mountebank-grpc\protocols.json           # protocols.json below

Dockerfile

FROM debian:buster

RUN set -ex; \
    apt-get update; \
    apt-get install -y --no-install-recommends ca-certificates dirmngr gnupg wget;\
    apt-get install -y --no-install-recommends curl; \
    curl -fsSL https://deb.nodesource.com/setup_12.x | bash -; \
    apt-get install -y nodejs; \
    \
    # add whatever you want here
    rm -rf /var/lib/apt/lists/*; \
    apt-get clean;

COPY . /etc/mountebank
WORKDIR /etc/mountebank

RUN set -ex; \
    # install mountebank global
    npm install -g mountebank; \
    # install mountebank-grpc local
    npm install ./mountebank-grpc;

ENTRYPOINT ["mb", "start", "--protofile", "protocols.json"]

protocols.json

{
    "grpc": {
        "createCommand": "node /etc/mountebank/mountebank-grpc/src/index.js"
    }
}

Build the image and run

docker build --tag=mb-grpc:latest
docker run -p 2525:2525 -p 4545:4545 --rm -it mb-grpc

After that I was able to use postman/curl to load the imposter from the README.md

PS C:\mydir\mountebank-grpc> docker run -p 2525:2525 --rm -it mb-grpc
info: [mb:2525] Loaded custom protocol grpc
info: [mb:2525] mountebank v2.4.0 now taking orders - point your browser to http://localhost:2525/ for help
info: [mb:2525] POST /imposters
info: [grpc:4545] Open for business...
info: [grpc:4545] [2021-08-21T21:14:08.925Z] server started on port '4545'

I didn't test the overall grpc functionality since i don't have the tools on this machine.

This should at least get you started. Hope it helps!