pact-foundation / pact-js-core

Core binaries for pact-js, a Contract Testing Framework. NOTE: If you are looking to do Pact contract testing in node, you almost certainly want pact-js, not pact-node.
https://docs.pact.io
MIT License
150 stars 79 forks source link

Update to ruby-standalone 1.8.0 and delegate publishPacts to new pact-publish executable #49

Closed mefellows closed 6 years ago

mefellows commented 7 years ago

@bethesque commented on Sat Sep 30 2017

The pact-publish command merges pact files for the same consumer/provider (that have been created by running in specs in parallel) before publishing them to the broker.

Usage:
  pact-publish PACT_DIRS_OR_FILES ... -a, --consumer-app-version=CONSUMER_APP_VERSION -b, --broker-base-url=BROKER_BASE_URL

Options:
  -a, --consumer-app-version=CONSUMER_APP_VERSION  # The consumer application version
  -b, --broker-base-url=BROKER_BASE_URL            # The base URL of the Pact Broker
  -n, [--broker-username=BROKER_USERNAME]          # Pact Broker basic auth username
  -p, [--broker-password=BROKER_PASSWORD]          # Pact Broker basic auth password
  -t, [--tag=TAG]                                  # Tag name for consumer version. Can be specified multiple times.
  -v, [--verbose=VERBOSE]                          # Verbose output

Publish pacts to a Pact Broker.

@mefellows commented on Mon Oct 16 2017

cc: @mboudreau I assume this needs to go in pact-node?


@mboudreau commented on Mon Oct 16 2017

@mefellows pact-node/pact-standalone, yep.

mboudreau commented 7 years ago

@bethesque @mefellows I cannot move forward with this as the pact-publish ruby exec doesn't seem to follow authentication rules. It never passes the basic auth credentials with the request, hence it's failing the tests we already had in place for pact publish.

Please fix this issue and re-release the standalone so this can be done. Thanks.

bethesque commented 7 years ago

I bumped into this yesterday too. I've just released 1.10.0 with the fix.

bethesque commented 7 years ago

Please use the long versions of the option names, as I did a naughty breaking change and made the username flag -u instead of -n (long story - I'd been trying to keep it consistent with the pact-verifier shortened names, which used -n, but changed my mind now the -u option for the pact-verifier is removed now anyway)

mboudreau commented 7 years ago

We've always used the long names. Thanks for fixing this so quickly. Cheers.

On Thu., 19 Oct. 2017, 1:26 pm Beth Skurrie, notifications@github.com wrote:

Please use the long versions of the option names, as I did a naughty breaking change and made the username flag -u instead of -n (long story - I'd been trying to keep it consistent with the pact-verifier shortened names, which used -n, but changed my mind now the -u option for the pact-verifier is removed now anyway)

— You are receiving this because you were assigned.

Reply to this email directly, view it on GitHub https://github.com/pact-foundation/pact-node/issues/49#issuecomment-337781347, or mute the thread https://github.com/notifications/unsubscribe-auth/AAjA5IjVkEYTDH3tmzdSStE6NsImixfJks5strNEgaJpZM4P78xE .

mboudreau commented 7 years ago

@bethesque just deployed the latest standalone, however, I'm still seeing an issue with pact-publish. This time it's about the exit code being sent back. When it fails to publish, it just returns a 0 exit code, which means it should have succeeded, but it actually did fail. Could you please return an exit code of 1 on failure?

bethesque commented 7 years ago

It should be returning a 1 exit code, because there is this:

raise PactPublicationError, "One or more pacts failed to be published" unless success

Let me investigate why it isn't.

bethesque commented 7 years ago

Sneaky bugger of a Thor class needed a flag to tell it to exit(1) on error. That'll teach me to make assumptions!

I've released v 1.11.0 standalone with the fix, and I've made a small change to the way the command is invoked. Since I wrote that command, I've realised there is going to be a suite of pact-broker CLI commands (can-i-deploy, what-can-i-deploy, tag-version...) so I've moved pact-publish to pact-broker publish, figuring it's better to do it now before anyone is using it properly.

mboudreau commented 7 years ago

@bethesque just tried the latest standalone, the binaries work, however, it wasn't returning the URLs of the contracts being sent because I might of had the mocks wrong. So I'm looking for the correct response from the pact-broker when a contract is sent to be saved using the publish binary, so that it can tell the user the url to the contracts.

Anywho, I figured I would use the docker pact-broker to test on my local and get the response, then use it in the mock, however, when trying to run the pact-broker docker-compose file with the binary for a test, I get this error from the container:

broker_app_1  | *** Running /etc/my_init.d/00_regen_ssh_host_keys.sh...
broker_app_1  | *** Running /etc/my_init.d/30_presetup_nginx.sh...
broker_app_1  | *** Running /etc/rc.local...
broker_app_1  | *** Booting runit daemon...
broker_app_1  | *** Runit started as PID 11
broker_app_1  | Oct 20 05:51:48 13590c0606f4 syslog-ng[22]: syslog-ng starting up; version='3.5.3'
broker_app_1  | ok: run: /etc/service/nginx-log-forwarder: (pid 30) 0s
broker_app_1  | [ 2017-10-20 05:51:49.3534 31/7f11c055c7c0 age/Wat/Main.cpp:1274 ]: Starting Passenger watchdog...
broker_app_1  | [ 2017-10-20 05:51:49.3846 34/7f42422307c0 age/Cor/Main.cpp:957 ]: Starting Passenger core...
broker_app_1  | [ 2017-10-20 05:51:49.3848 34/7f42422307c0 age/Cor/Main.cpp:234 ]: Passenger core running in multi-application mode.
broker_app_1  | [ 2017-10-20 05:51:49.3898 34/7f42422307c0 age/Cor/Main.cpp:707 ]: Passenger core online, PID 34
broker_app_1  | [ 2017-10-20 05:51:49.4106 41/7f9a6f8937c0 age/Ust/Main.cpp:430 ]: Starting Passenger UstRouter...
broker_app_1  | [ 2017-10-20 05:51:49.4149 41/7f9a6f8937c0 age/Ust/Main.cpp:311 ]: Passenger UstRouter online, PID 41
broker_app_1  | Oct 20 06:17:01 13590c0606f4 /USR/SBIN/CRON[62]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
broker_app_1  | Oct 20 06:25:01 13590c0606f4 /USR/SBIN/CRON[65]: (root) CMD (test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ))
broker_app_1  | App 138 stdout: 
broker_app_1  | App 138 stderr:  --> Compiling passenger_native_support.so for the current Ruby interpreter...
broker_app_1  | App 138 stderr: 
broker_app_1  | App 138 stderr:      (set PASSENGER_COMPILE_NATIVE_SUPPORT_BINARY=0 to disable)
broker_app_1  | App 138 stderr: 
broker_app_1  | App 138 stderr:      Compilation succesful. The logs are here:
broker_app_1  | App 138 stderr:      /tmp/passenger_native_support-i8zx9n.log
broker_app_1  | App 138 stderr:  --> passenger_native_support.so successfully loaded.
broker_app_1  | App 138 stdout: 
broker_app_1  | [ 2017-10-20 06:25:43.1409 34/7f423c05d700 App/Implementation.cpp:303 ]: Could not spawn process for application /home/app/pact_broker: An error occured while starting up the preloader.
broker_app_1  |   Error ID: 00e17930
broker_app_1  |   Error details saved to: /tmp/passenger-error-dTt432.html
broker_app_1  |   Message from application: uninitialized constant PactBroker::Api::Resources::BaseResource (NameError)
broker_app_1  |   /home/app/pact_broker/vendor/bundle/ruby/2.2.0/gems/pact_broker-2.6.0/lib/pact_broker/api/resources/version.rb:8:in `<module:Resources>'
broker_app_1  |   /home/app/pact_broker/vendor/bundle/ruby/2.2.0/gems/pact_broker-2.6.0/lib/pact_broker/api/resources/version.rb:6:in `<module:Api>'
broker_app_1  |   /home/app/pact_broker/vendor/bundle/ruby/2.2.0/gems/pact_broker-2.6.0/lib/pact_broker/api/resources/version.rb:5:in `<module:PactBroker>'
broker_app_1  |   /home/app/pact_broker/vendor/bundle/ruby/2.2.0/gems/pact_broker-2.6.0/lib/pact_broker/api/resources/version.rb:4:in `<top (required)>'
broker_app_1  |   /home/app/pact_broker/vendor/bundle/ruby/2.2.0/gems/pact_broker-2.6.0/lib/pact_broker/api/resources.rb:9:in `require'
broker_app_1  |   /home/app/pact_broker/vendor/bundle/ruby/2.2.0/gems/pact_broker-2.6.0/lib/pact_broker/api/resources.rb:9:in `block in <top (required)>'
broker_app_1  |   /home/app/pact_broker/vendor/bundle/ruby/2.2.0/gems/pact_broker-2.6.0/lib/pact_broker/api/resources.rb:8:in `glob'
broker_app_1  |   /home/app/pact_broker/vendor/bundle/ruby/2.2.0/gems/pact_broker-2.6.0/lib/pact_broker/api/resources.rb:8:in `<top (required)>'
broker_app_1  |   /home/app/pact_broker/vendor/bundle/ruby/2.2.0/gems/pact_broker-2.6.0/lib/pact_broker/api.rb:2:in `require'
broker_app_1  |   /home/app/pact_broker/vendor/bundle/ruby/2.2.0/gems/pact_broker-2.6.0/lib/pact_broker/api.rb:2:in `<top (required)>'
broker_app_1  |   /home/app/pact_broker/vendor/bundle/ruby/2.2.0/gems/pact_broker-2.6.0/lib/pact_broker/app.rb:112:in `require'
broker_app_1  |   /home/app/pact_broker/vendor/bundle/ruby/2.2.0/gems/pact_broker-2.6.0/lib/pact_broker/app.rb:112:in `build_api'
broker_app_1  |   /home/app/pact_broker/vendor/bundle/ruby/2.2.0/gems/pact_broker-2.6.0/lib/pact_broker/app.rb:81:in `prepare_app'
broker_app_1  |   /home/app/pact_broker/vendor/bundle/ruby/2.2.0/gems/pact_broker-2.6.0/lib/pact_broker/app.rb:27:in `initialize'
broker_app_1  |   config.ru:8:in `new'
broker_app_1  |   config.ru:8:in `block in <main>'
broker_app_1  |   /home/app/pact_broker/vendor/bundle/ruby/2.2.0/gems/rack-2.0.3/lib/rack/builder.rb:55:in `instance_eval'
broker_app_1  |   /home/app/pact_broker/vendor/bundle/ruby/2.2.0/gems/rack-2.0.3/lib/rack/builder.rb:55:in `initialize'
broker_app_1  |   config.ru:1:in `new'
broker_app_1  |   config.ru:1:in `<main>'
broker_app_1  |   /usr/share/passenger/helper-scripts/rack-preloader.rb:107:in `eval'
broker_app_1  |   /usr/share/passenger/helper-scripts/rack-preloader.rb:107:in `preload_app'
broker_app_1  |   /usr/share/passenger/helper-scripts/rack-preloader.rb:153:in `<module:App>'
broker_app_1  |   /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>'
broker_app_1  |   /usr/share/passenger/helper-scripts/rack-preloader.rb:28:in `<main>'
broker_app_1  | 
broker_app_1  | 
broker_app_1  | [ 2017-10-20 06:25:43.1681 34/7f42377fe700 age/Cor/Req/CheckoutSession.cpp:252 ]: [Client 1-1] Cannot checkout session because a spawning error occurred. The identifier of the error is 00e17930. Please see earlier logs for details about the error.

from the publish binary, I'm getting:

Failed to publish consumer/publisher pact due to error: PactBroker::Client::Error - <!DOCTYPE html>
<html>
<head>
  <title>We're sorry, but something went wrong (500)</title>
  <style type="text/css">
    body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
    .dialog {
      width: 25em;
      padding: 0 4em;
      margin: 4em auto 0 auto;
      border: 1px solid #ccc;
      border-right-color: #999;
      border-bottom-color: #999;
    }
    h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
    #operator_info_panel {
      width: 27em;
      margin: 4em auto 0 auto;
      line-height: 1.2em;
    }
    #show_operator_info { text-decoration: none; color: #99f; font-size: smaller; }
    #show_operator_info:hover { text-decoration: underline; }
    #operator_info { color: #444; text-align: justify; }
  </style>
</head>

<body>
  <div class="dialog">
    <h1>We're sorry, but something went wrong.</h1>
    <p>We've been notified about this issue and we'll take a look at it shortly.</p>
  </div>
  <div id="operator_info_panel">
    <a id="show_operator_info" href="javascript:void(showOperatorInfo())">Information for the administrator of this website</a>
    <div id="operator_info" style="display: none">
      <p>The Phusion Passenger application server encountered an error while starting your web application.
        Because you are running this web application in staging or production mode, the details of the error
        have been omitted from this web page for security reasons.</p>
      <p><strong>Please read <a href="https://www.phusionpassenger.com/library/admin/log_file/">the Passenger log file</a> to find the details of the error.</strong></p>
      <p>Alternatively, you can turn on the "friendly error pages" feature (see below), which will make Phusion Passenger show many details about the error right in the browser.</p>
      <p>To turn on friendly error pages:</p>
      <ul>
        <li><a href="https://www.phusionpassenger.com/library/config/nginx/reference/#passenger_friendly_error_pages">Nginx integration mode</a></li>
        <li><a href="https://www.phusionpassenger.com/library/config/apache/reference/#passengerfriendlyerrorpages">Apache integration mode</a></li>
        <li><a href="https://www.phusionpassenger.com/library/config/standalone/reference/#--friendly-error-pages---no-friendly-error-pages-friendly_error_pages">Standalone mode</a></li>
      </ul>
    </div>
  </div>

  <script>
    function showOperatorInfo() {
      document.getElementById('operator_info').style.display = 'block';
    }
  </script>
</body>
</html>

One or more pacts failed to be published

Publishing consumer/publisher pact to pact broker at http://localhost:80

I'm not too sure what's going wrong, but since it's going from the standalone binary, to the pact-broker, to the binary, I doubt it has anything to do with the wrapping pact-node code.

Could you please investigate and fix anything that might be broken? thanks.

bethesque commented 7 years ago

I can't tell what's gone wrong in the broker from that message. Can you check docker logs?

Have a look at the RELEASING.md file and you'll see how to run it without docker compose. I know this works because I run it every time I do a release. TBH, I never run the docker compose, so I'm not even sure if it's configured correctly.

Or you can publish to the test broker at https://test.pact.dius.com.au/ The username is dXfltyFMgNOFZAxr8io9wJ37iUpY42M and the password is O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1

You'll want better output from the command if you're going to parse it. I suggest we add an --output json. Let's delay converting the js to use the CLI in this release if it's holding things up, and do it in the next one. The main reason for going through the publish CLI is that it's got the code to merge multiple pact files generated by mock services being run in parallel. It was requested by one of the users, but I think in the end, they worked out how to run their tests sequentially, so it's not super urgent any more.

bethesque commented 7 years ago

Oh, and I'll be on holidays next week. No internet apart from phones.

mboudreau commented 6 years ago

@bethesque I got the publish working, but the --output json causes the ruby binary to crash with:

/home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.11.0/lib/pact_broker/client/pact_file.rb:32:in `read': No such file or directory @ rb_sysopen - --output (Errno::ENOENT)
    from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.11.0/lib/pact_broker/client/pact_file.rb:32:in `read'
    from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.11.0/lib/pact_broker/client/pact_file.rb:28:in `pact_hash'
    from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.11.0/lib/pact_broker/client/pact_file.rb:16:in `pact_name'
    from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/rake-10.5.0/lib/rake/file_list.rb:81:in `each'
    from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/rake-10.5.0/lib/rake/file_list.rb:81:in `group_by'
    from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/rake-10.5.0/lib/rake/file_list.rb:81:in `group_by'
    from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.11.0/lib/pact_broker/client/publish_pacts.rb:41:in `publish_pacts'
    from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.11.0/lib/pact_broker/client/publish_pacts.rb:27:in `call'
    from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.11.0/lib/pact_broker/client/publish_pacts.rb:13:in `call'
    from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.11.0/lib/pact_broker/client/cli/broker.rb:96:in `publish_pacts'
    from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.11.0/lib/pact_broker/client/cli/broker.rb:48:in `publish'
    from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
    from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
    from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
    from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/thor-0.20.0/lib/thor/base.rb:466:in `start'
    from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.11.0/lib/pact_broker/client/cli/custom_thor.rb:15:in `start'
    from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/app/pact-broker.rb:2:in `<main>'
bethesque commented 6 years ago

There's no output json for the publish. I can add it, if you'll tell me what you want to put in it.

bethesque commented 6 years ago

Why not just output the message from the command itself?

mboudreau commented 6 years ago

I'm trying to get the pact broker urls of the published contracts. I ended up just reading the output and using regex to get them, which is fine.

On Tue., 7 Nov. 2017, 7:24 am Beth Skurrie, notifications@github.com wrote:

Why not just output the message from the command itself?

— You are receiving this because you were assigned.

Reply to this email directly, view it on GitHub https://github.com/pact-foundation/pact-node/issues/49#issuecomment-342275150, or mute the thread https://github.com/notifications/unsubscribe-auth/AAjA5Nyg9L0s9WoDRkYkqF24YaxF26mNks5sz2sZgaJpZM4P78xE .

bethesque commented 6 years ago

Why don't you just display the output of the command? If there are errors, it will contain important information.

mboudreau commented 6 years ago

I am outputting it, but it's not very convenient if a developer wants to use the URL somewhere else for another purpose and they have to parse the console output to get it.

On Tue, Nov 7, 2017 at 11:38 AM Beth Skurrie notifications@github.com wrote:

Why don't you just display the output of the command? If there are errors, it will contain important information.

— You are receiving this because you were assigned.

Reply to this email directly, view it on GitHub https://github.com/pact-foundation/pact-node/issues/49#issuecomment-342336240, or mute the thread https://github.com/notifications/unsubscribe-auth/AAjA5AVjbf6M9kty-nEP7vSuVRdANwSNks5sz6aGgaJpZM4P78xE .

bethesque commented 6 years ago

Ah, so you want to yield the URLs to a callback when the publish is invoked? What JSON structure would be useful?

mboudreau commented 6 years ago

Again, don't worry about it for now, already got it working, just need to figure out all the tests for the broker mock.

On Tue., 7 Nov. 2017, 12:18 pm Beth Skurrie, notifications@github.com wrote:

Ah, so you want to yield the URLs to a callback when the publish is invoked? What JSON structure would be useful?

— You are receiving this because you were assigned.

Reply to this email directly, view it on GitHub https://github.com/pact-foundation/pact-node/issues/49#issuecomment-342343780, or mute the thread https://github.com/notifications/unsubscribe-auth/AAjA5Mi2Xb2U3n3ZzA4zNQ8Ure_dhaDaks5sz7ABgaJpZM4P78xE .

bethesque commented 6 years ago

Dude, we need a contract :P I can't guarantee that output won't change.

mboudreau commented 6 years ago

Yes, we do. It would be a great way to validate moving forward, but right now, I'm just trying to get this over the line with tests that work since I've been trying to get the new publish binary working with pact node for a couple weeks, and have more important things to work on, like the website.

I'd love to get to a point where we use our own tech to validate our own work, which would be great when we're doing major internal changes (pact reference anyone?) While still keeping all the functionality.

We can chat about this further another time, right now, just trying to get the publish binary done and dusted.

On Tue., 7 Nov. 2017, 1:36 pm Beth Skurrie, notifications@github.com wrote:

Dude, we need a contract :P I can't guarantee that output won't change.

— You are receiving this because you were assigned.

Reply to this email directly, view it on GitHub https://github.com/pact-foundation/pact-node/issues/49#issuecomment-342357010, or mute the thread https://github.com/notifications/unsubscribe-auth/AAjA5MWaZ6uanMrte2A6ViCCxksR0ykyks5sz8IWgaJpZM4P78xE .

mefellows commented 6 years ago

Is this done now? I can see that we spawn the binary for this publish instead of the previous API calls.

mboudreau commented 6 years ago

I believe so.

On Sun., 10 Dec. 2017, 9:48 am Matt Fellows, notifications@github.com wrote:

Is this done now? I can see that we spawn the binary for this publish instead of the previous API calls.

— You are receiving this because you were assigned.

Reply to this email directly, view it on GitHub https://github.com/pact-foundation/pact-node/issues/49#issuecomment-350511155, or mute the thread https://github.com/notifications/unsubscribe-auth/AAjA5JduacwJyQ6INerFH87eQQn1edVbks5s-w4kgaJpZM4P78xE .

mefellows commented 6 years ago

Awesome, closing this then.