pact-foundation / pact-js

JS version of Pact. Pact is a contract testing framework for HTTP APIs and non-HTTP asynchronous messaging systems.
https://pact.io
Other
1.64k stars 349 forks source link

Issue with binary while running inside Docker Node Alpine #296

Closed halfzebra closed 5 years ago

halfzebra commented 5 years ago

Hello friends!

Thank you for Pact, I like it very much. πŸ‘

Unfortunately, I'm unable to get it to work inside Docker. Any ideas on how I might be getting this to work?

Please help!

Software versions

Expected behaviour

I expect the test to fail gracefully with the following:

4 interactions, 4 failures

Failed interactions:

* A request for json data given date count > 0
* A request with an invalid date parameter given date count > 0
* A request with a missing date parameter given date count > 0
* A request for json data given date count == 0

Actual behaviour

My test crashes with:

[2019-04-23T22:00:08.256Z]  WARN: pact-node@8.1.2/26 on 6ef9934a5998: Pact exited with code 127.
 FAIL  ./pact.test.js
  dummy pact verification
    βœ• should validate the expectations of Our Little Consumer (98ms)

  ● dummy pact verification β€Ί should validate the expectations of Our Little Consumer

    /bin/sh: ./standalone/linux-x64-1.64.0/bin/pact-provider-verifier: not found

      at ChildProcess.<anonymous> (node_modules/@pact-foundation/pact-node/src/verifier.ts:156:55)

Steps to reproduce

https://github.com/halfzebra/pact-docker-issue

mefellows commented 5 years ago

Thanks for the kind words and repro. Before we investigate further, have you seen any of the following:

halfzebra commented 5 years ago

Thanks for the quick reply!

Very helpful links, I've read through all of them and here is what I have found.

I've tried adding build dependencies but it did not help.

RUN apk add --no-cache --virtual build-dependencies build-base

Adding Alpine-specific version of glibc as suggested here did not cut it as well.

RUN  apk --no-cache add ca-certificates wget \
     && wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
     && wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.29-r0/glibc-2.29-r0.apk \
     && apk add glibc-2.29-r0.apk

Both tries have resulted in the original error.

Using node:stretch works and I might go with it for now. It does not feel like an elegant solution, because I use a custom image based on node:alpine to run my apps πŸ˜•

mefellows commented 5 years ago

I think it just needs bash to run:

FROM node:8-alpine

RUN apk add --no-cache --virtual build-dependencies build-base

RUN  apk --no-cache add ca-certificates wget bash \
  && wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
  && wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.29-r0/glibc-2.29-r0.apk \
  && apk add glibc-2.29-r0.apk

WORKDIR /app

COPY package*.json /app/

RUN npm install

COPY . /app/

RUN npm test

Your test fails, but for the obvious reasons. Let me know how you go. If it works, I might just create a base image for use and update docs.

halfzebra commented 5 years ago

Adding bash worked for me, thank you for your help! πŸŽ‰

Please let me know if I could help with the docs, otherwise, this issue could be closed.

mefellows commented 5 years ago

That's great news. I'll mark as an enhancement and will update the docs / example when I get some time. Thanks for the report and repro πŸ‘

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

TimothyJones commented 5 years ago

Bumping so this doesn’t get closed unnecessarily. Should we remove stalebot?

TimothyJones commented 5 years ago

Also, I will check the docs tomorrow and close this off afterwards (if you haven’t already)

mefellows commented 5 years ago

I think stalebot is doing its job! Silly old Matt forgot to tag this with "Documentation" and also hasn't updated the docs.

In terms of getting this done, i'm thinking maybe the Wiki is the place for this (or at least, not the README). The README is really growing a bit too large/overwhelming, and I feel this is proverbial straw that justifies the move.

Ideas?

mefellows commented 5 years ago

I have added a section to our docs website on Docker, and will reference it in the README shortly: https://docs.pact.io/docker/

qmg-rwaller commented 3 years ago

Hi, thanks for the example and updating the docs! Is there an official docker image for that reference image (and for other node versions)? i.e.

FROM node:8-alpine

RUN apk add --no-cache --virtual build-dependencies build-base

RUN  apk --no-cache add ca-certificates wget bash \
  && wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
  && wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.29-r0/glibc-2.29-r0.apk \
  && apk add glibc-2.29-r0.apk

I tried using https://hub.docker.com/r/dius/pact-provider-verifier-docker instead, but it errored with line 1: yarn: not found, so not sure if I'm using it correctly. We want to run yarn install && yarn test (which runs pactJS) inside a suitable node alpine docker image

mefellows commented 3 years ago

We don't have an official docker image for it sorry. Most people seem to want to customise their own base anyway.

I wouldn't use the verifier docker, because it's for a separate thing that doesn't have JS on it.

Can you not just run your own?

qmg-rwaller commented 3 years ago

Thanks for quick reply! Yea just checking if there's something official first, but we can run our own :)

mefellows commented 3 years ago

Cool, worth checking. If we weren't maintaining 12 official languages, we probably would have done it because it's fairly easy - but we have enough stuff to maintain now as it is :)

bethesque commented 3 years ago

Actually, I did make a node base image of the cli here https://hub.docker.com/r/pactfoundation/pact-cli/tags?page=1&ordering=last_updated

mefellows commented 3 years ago

Ah cool - thanks past Beth! I'll add to docs.

TimothyJones commented 3 years ago

Slightly off topic, but there's also the pact-node binstubs, so you can:

npx -p @pact-foundation/pact-node pact-broker help

for no-install pact CLI usage without docker.

qmg-rwaller commented 3 years ago

Thanks @bethesque! I may have misunderstood something - that image doesn't have bash, and so my build errors when yarn test uses PactJS to verify a consumer pact and write it out to a JSON file: image

Should the image allow me to do that, or do I need to add bash? :)

❯ docker run -it --rm --entrypoint bash pactfoundation/pact-cli:latest-node14
docker: Error response from daemon: OCI runtime create failed: container_linux.go:370: 
starting container process caused: exec: "bash": executable file not found in $PATH: unknown.
bethesque commented 3 years ago

You need bash, sorry https://docs.pact.io/docker/#alpine-linux