diff --git a/.dockerignore b/src/Mockaco/.dockerignore similarity index 84% rename from .dockerignore rename to src/Mockaco/.dockerignore index 2d15e48..2653418 100644 --- a/.dockerignore +++ b/src/Mockaco/.dockerignore @@ -17,4 +17,6 @@ **/*.jfm **/secrets.dev.yaml **/values.dev.yaml -**/.toolstarget \ No newline at end of file +**/.toolstarget +/Mocks/*.json +!/Mocks/hello.json \ No newline at end of file diff --git a/src/Mockaco/Dockerfile b/src/Mockaco/Docker/Dockerfile similarity index 87% rename from src/Mockaco/Dockerfile rename to src/Mockaco/Docker/Dockerfile index 624de4f..9095b56 100644 --- a/src/Mockaco/Dockerfile +++ b/src/Mockaco/Docker/Dockerfile @@ -4,9 +4,9 @@ EXPOSE 5000 FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build WORKDIR /src -COPY ./Mockaco.csproj . +COPY ./Mockaco.csproj ./ RUN dotnet restore -COPY . . +COPY ./ ./ RUN dotnet build "Mockaco.csproj" -c Release -o /app FROM build AS publish @@ -16,7 +16,7 @@ FROM base AS final ENV DOTNET_USE_POLLING_FILE_WATCHER=true WORKDIR /app COPY --from=publish /app . -COPY Mocks /app/Mocks +COPY ./Mocks/hello.json /app/Mocks/ COPY Settings /app/Settings VOLUME /app/Mocks VOLUME /app/Settings diff --git a/src/Mockaco/Docker/README.md b/src/Mockaco/Docker/README.md new file mode 100644 index 0000000..20082e2 --- /dev/null +++ b/src/Mockaco/Docker/README.md @@ -0,0 +1,94 @@ +# Quick reference + +- **Where to get help and to file issues**: + [GitHub repository](https://github.com/natenho/Mockaco/) + +- **Maintained by**: + [natenho](https://github.com/natenho) + +# What is Mockaco? + +Mockaco is an HTTP-based API mock server with fast setup, featuring: + +- Simple JSON-based configuration +- Pure C# scripting - you don't need to learn a new specific language or API to configure your mocks +- Fake data generation - built-in hassle-free fake data generation +- Callback support - trigger another service call when a request hits your mocked API + +logo + +# How to use this image + +## Running the demo + +The default image ships with a sample "hello" mock: + +```console +$ docker run -it --rm -p 5000:80 natenho/mockaco +``` + +Mockaco can be accessed by any HTTP client via `http://localhost:5000` + +```console +$ curl -iX GET http://localhost:5000/hello/docker +``` +```http +HTTP/1.1 200 OK +Date: Wed, 21 Jun 2019 05:10:00 GMT +Content-Type: application/json +Server: Kestrel +Transfer-Encoding: chunked + +{ + "message": "Hello docker!" +} +``` + +## Running and creating your own mocks + +The best way to use the image is by creating a directory on the host system (outside the container) and mount this to the `/app/Mocks` directory inside the container. + +1. Create a data directory on a suitable volume on your host system, e.g. `/my/own/mockdir`. +2. Start your `mockaco` container like this: + +```console +$ docker run -it --rm -p 5000:80 -v /my/own/mockdir:/app/Mocks natenho/mockaco +``` + +The `-v /my/own/mockdir:/app/Mocks` part of the command mounts the `/my/own/mockdir` directory from the underlying host system as `/app/Mocks` inside the container, where Mockaco by default will read its mock JSON files. + +3. Create a request/response template file named `PingPong.json` under `/my/own/mockdir` folder: + +```json +{ + "request": { + "method": "GET", + "route": "ping" + }, + "response": { + "status": "OK", + "body": { + "response": "pong" + } + } +} +``` + +4. Send a request and get the mocked response, running: + +```console +$ curl -iX GET http://localhost:5000/ping +``` +```http +HTTP/1.1 200 OK +Date: Wed, 21 Jun 2019 05:10:00 GMT +Content-Type: application/json +Server: Kestrel +Transfer-Encoding: chunked + +{ + "response": "pong" +} +``` + +For advanced usage scenarios, like scripting and fake data generation, refer to the [docs](https://github.com/natenho/Mockaco). \ No newline at end of file diff --git a/src/Mockaco/Mocks/HelloWorld-200.json b/src/Mockaco/Mocks/hello.json similarity index 100% rename from src/Mockaco/Mocks/HelloWorld-200.json rename to src/Mockaco/Mocks/hello.json