pact-foundation / pact-stub-server

Standalone pact stub server
MIT License
75 stars 19 forks source link

Application panics on Option::unwrap() when run in non-interactive Docker #2

Closed mefellows closed 7 years ago

mefellows commented 7 years ago

When wrapped in a Docker container for headless use, the binary panics as follows (even with logging disabled):

matt ~/ λ docker run -d -p 8080:8080 -v "$(pwd)/pacts/:/app/pacts" pact-foundation/pact-stub-server -p 8080 -d pacts -l none
9a0f91e528007641a8ed231cd24046144db254fd5a9a4d1dcbeddb480143516c
matt ~/ λ docker logs 9a0
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', ../src/libcore/option.rs:323
note: Run with `RUST_BACKTRACE=1` for a backtrace.
matt ~/ λ

See https://github.com/pact-foundation/pact-reference/issues/6, I'm assuming it's the same issue?

To reproduce:

FROM debian
RUN apt-get update && apt-get install -y curl wget gzip
RUN wget $(curl -s https://api.github.com/repos/uglyog/pact-stub-server/releases | grep browser_download_url | head -n 1 | cut -d '"' -f 4) && \
    mkdir /app && \
    gunzip *.gz && \
    chmod +x pact* && \
    mv pact* /app/pact-stub-server

WORKDIR /app
ENTRYPOINT ["/app/pact-stub-server"]
CMD ["--help"]

Then build and run:

docker build -t pact-foundation/pact-stub-server
docker run -it -p 8080:8080 -v "$(pwd)/pacts/:/app/pacts" pact-foundation/pact-stub-server -p 8080 -d pacts

Example pact file test.json:

{
  "provider": {
    "name": "metrics"
  },
  "consumer": {
    "name": "api"
  },
  "interactions": [
    {
      "description": "a get metrics request",
      "request": {
        "method": "GET",
        "path": "/metrics"
      },
      "response": {
        "status": 200,
        "headers": {
          "Content-Type": "application/json"
        },
        "body": {
          "property_id": "42",
          "sensor_id": "13",
          "measured_at": "2017-03-06T05:36:47.914Z",
          "metrics": {
            "moisture_30": 234,
            "temperature": 180
          }
        }
      }
    }
  ],
  "metadata": {
    "pact-specification": {
      "version": "2.0.0"
    }
  }
}
uglyog commented 7 years ago

It works with the -t switch, as this makes docker create a tty for the container. Leaving that out causes the panic.

uglyog commented 7 years ago

v0.0.2 has been released with this fix.

mefellows commented 7 years ago

legend, thanks.

FWIW the -t flag (without interactive) worked ;)