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.63k stars 348 forks source link

Problem with ruby in docker alpine #305

Closed kjenney closed 5 years ago

kjenney commented 5 years ago

Software versions

Expected behaviour

The ruby binary is installed and usable for testing.

Actual behaviour

The ruby binary is missing:

[2019-05-30T13:36:23.268Z] ERROR: pact-node@8.3.3/52 on 2f21113fe9d5:
    Pact Binary Error: /usr/src/app/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.65.1/lib/ruby/bin/ruby: line 6: /usr/src/app/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.65.1/lib/ruby/bin.real/ruby: No such file or directory

Steps to reproduce

Clone https://github.com/kjenney/pact-js-test-consumer and run docker build ..

docker build -f Dockerfile.ubuntu . works fine but the alpine tests fail because the standalone ruby version is missing.

YOU54F commented 5 years ago

https://github.com/pact-foundation/pact-js/issues/296

you need bash :) as alpine ships with sh

kjenney commented 5 years ago

I installed bash:


RUN apk -Uuv add --no-cache \
  make \
  curl \
  groff \
  less \
  nodejs-npm \
  bash \
  python \
  ruby```
YOU54F commented 5 years ago

The suspense is killing me, did it work or not? 🌮

In your example repo, you don't have bash installed?

https://github.com/kjenney/pact-js-test-consumer/blob/master/Dockerfile

YOU54F commented 5 years ago

just tested it, this works

FROM node:10.15.3-alpine

ARG NODE_ENV

RUN apk update

# Install base and dev packages
RUN apk add --no-cache --virtual build-dependencies build-base

# Install prod dependencies
RUN apk -Uuv add --no-cache \
  make \
  curl \
  groff \
  less \
  nodejs-npm \
  python 

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

SHELL ["/bin/bash", "-c"]

# Set timezone to UTC by default
RUN ln -sf /usr/share/zoneinfo/Etc/UTC /etc/localtime

# Update npm
RUN npm install -g npm

WORKDIR /usr/src/app

# Copy Package.json and lock
COPY package* ./

# Install NodeJS Dependencies
RUN npm install

# Copy code
COPY . .

# Run tests
RUN npm run test
[2019-05-30T22:53:01.991Z]  INFO: pact-node@8.4.0/64 on 3394e6f190f0: Created './standalone/linux-x64-1.65.1/bin/pact-mock-service service --consumer 'Test' --cors 'true' --pact_dir '/usr/src/app/pacts' --host '127.0.0.1' --log '/usr/src/app/logs/mockserver-verification.log' --pact-file-write-mode 'update' --port '8991' --provider 'Factory' --pact_specification_version '2'' process with PID: 105
[2019-05-30T22:53:03.030Z]  INFO: pact@8.2.4/64 on 3394e6f190f0:
    Setting up Pact with Consumer "Test" and Provider "Factory"
        using mock service on Port: "8991"
[2019-05-30T22:53:03.146Z] ERROR: pact-node@8.4.0/64 on 3394e6f190f0:
    Pact Binary Error: WARN: No content type found, performing text diff on body

[2019-05-30T22:53:03.238Z]  INFO: pact@8.2.4/64 on 3394e6f190f0: Pact File Written
[2019-05-30T22:53:03.239Z]  INFO: pact-node@8.4.0/64 on 3394e6f190f0: Removing Pact with PID: 105
[2019-05-30T22:53:03.244Z]  INFO: pact-node@8.4.0/64 on 3394e6f190f0:
    Deleting Pact Server with options:
    consumer = Test,
    cors = true,
    dir = /usr/src/app/pacts,
    host = 127.0.0.1,
    log = /usr/src/app/logs/mockserver-verification.log,
    pactFileWriteMode = update,
    port = 8991,
    provider = Factory,
    spec = 2,
    ssl = false,
    sslcert = ,
    sslkey =
PASS tests/unit/factory.pact.js

Test Suites: 2 passed, 2 total
Tests:       6 passed, 6 total
Snapshots:   0 total
Time:        4.412s
Ran all test suites.
Removing intermediate container 3394e6f190f0
 ---> fac2a6d11856
Successfully built fac2a6d11856

Magic step appeared to be this

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
YOU54F commented 5 years ago

not sure how I feel about alpine, as by the time you've added in all your deps, the image is massive.

that comes in at ~770mb uncompressed, obvs you've got the full project and node_modules in there too.

I tend to use debian:stretch and don't have to faff around with sprinking in extra magic to get small things to work.

Total Image size: 774 MB
Potential wasted space: 33 MB
Image efficiency score: 97 %
YOU54F commented 5 years ago

@kjenney sorted fella :)

YOU54F commented 5 years ago

btw I have some docker templates albeit for pact-ruby-standalone based on a few flavours. I'll pop up an alpine image soon

They are here - https://github.com/YOU54F/pact-standalone-docker-slim

mefellows commented 5 years ago

Thanks for following this up @YOU54F! Closing this issue, #296 has a working Alpine image.

kjenney commented 5 years ago

Thanks @YOU54F!

bethesque commented 5 years ago

What do we need bash for? Is it in the standalone scripts?

YOU54F commented 5 years ago

possibly, the four additions I made were

glibc-2.29-r0.apk plus the wget calls for the keys, bash
build-dependencies build-base

I'm about to crash for the night as it's well late here but worth isolating it by removing each one and seeing when it stops working :)

kjenney commented 5 years ago

My tests passed without switching the shell. All I needed was glibc.

kjenney commented 5 years ago

Thanks!

On Thu, May 30, 2019, 7:05 PM Yousaf Nabi notifications@github.com wrote:

btw I have some docker templates albeit for pact-ruby-standalone based on a few flavours. I'll pop up an alpine image soon

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pact-foundation/pact-js/issues/305?email_source=notifications&email_token=ABR7776A7HY2ZX4HXBY2FL3PYBMR7A5CNFSM4HRFLGV2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWTX6GQ#issuecomment-497516314, or mute the thread https://github.com/notifications/unsubscribe-auth/ABR7773NT5VSJ4PPER37R5LPYBMR7ANCNFSM4HRFLGVQ .

mefellows commented 5 years ago

I think there are some bashisms in the distribution. I'll see if I can pinpoint it Beth. I recall a conversation (it'll be in an issue somewhere)

mefellows commented 5 years ago

Yep, in fact a few of the tools use it directly (e.g. https://github.com/pact-foundation/pact-ruby-standalone/blob/master/packaging/pact-provider-verifier.sh#L1-L4).

kjenney commented 5 years ago

So you need bash installed but don't need to switch to the bash shell during install/test.

mefellows commented 5 years ago

Exactly.

On Sat, Jun 1, 2019, 4:47 PM Ken Jenney notifications@github.com wrote:

So you need bash installed but don't need to switch to the bash shell during install/test.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/pact-foundation/pact-js/issues/305?email_source=notifications&email_token=AAANFDCI35KMPVQR2XF3JDDPYILRVA5CNFSM4HRFLGV2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWW2JHQ#issuecomment-497919134, or mute the thread https://github.com/notifications/unsubscribe-auth/AAANFDEJYWCE6OHVW76QXP3PYILRVANCNFSM4HRFLGVQ .

ravindradhaka commented 2 years ago

2022/06/28 12:53:26 [ERROR] service: pact/lib/ruby/bin/ruby: line 6: /pact/lib/ruby/bin.real/ruby: No such file or directory 2022/06/28 12:53:36 [ERROR] Expected server to start < 10s. Timed out waiting for Mock Server to start on port 34059 - are you sure it's running? 2022/06/28 12:53:36 [ERROR] client: failed to wait for Mock Server: Expected server to start < 10s. Timed out waiting for Mock Server to start on port 34059 - are you sure it's running? 2022/06/28 12:53:36 Error on Verify: Post http://localhost:34059/interactions: dial tcp 127.0.0.1:34059: connect: connection refused

getting this issue in pact-go

mefellows commented 2 years ago

2022/06/28 12:53:26 [ERROR] service: /builds/panamera/fcg/service/dapi/pact/lib/ruby/bin/ruby: line 6: /builds/panamera/fcg/service/dapi/pact/lib/ruby/bin.real/ruby: No such file or directory 2022/06/28 12:53:36 [ERROR] Expected server to start < 10s. Timed out waiting for Mock Server to start on port 34059 - are you sure it's running? 2022/06/28 12:53:36 [ERROR] client: failed to wait for Mock Server: Expected server to start < 10s. Timed out waiting for Mock Server to start on port 34059 - are you sure it's running? 2022/06/28 12:53:36 Error on Verify: Post http://localhost:34059/interactions: dial tcp 127.0.0.1:34059: connect: connection refused

getting this issue in pact-go

This issue is closed @ravindradhaka. If you have a new issue, please raise it at pact-go with reproducible details. We run regular builds for Pact Go, so you'd need to prove that it's an issue that is not just unique to your situation, and that you've taken the steps noted here / https://docs.pact.io/docker to address it.

ravindradhaka commented 2 years ago

@mefellows getting this in ci/cd pipeline when I am running make consumer but in local machine its working fine