Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running Pact-Go Daemon in a Container #46

Closed
zbintliff opened this issue Aug 31, 2017 · 19 comments
Closed

Running Pact-Go Daemon in a Container #46

zbintliff opened this issue Aug 31, 2017 · 19 comments
Assignees

Comments

@zbintliff
Copy link
Contributor

zbintliff commented Aug 31, 2017

Is there any way to limit which ports interactions can map to? i.e. main server is 6666 and then 20100-20200 are used for interactions?

Right now we just expose every port over 1024 in our container but would like a little more constraints than that.

@zbintliff
Copy link
Contributor Author

To add, digging through the code I see that it picks randomly here. Would you be open to feature requests to limit that?

@mefellows
Copy link
Member

I'd be open to a feature request to specify the port itself, and default to randomly picked as is it's current behaviour.

@zbintliff
Copy link
Contributor Author

Awesome I'll whip up a PR. Can you add some color though? We have only done consumer side (daemon.MockService) but hope to do producer side well. As far as I can tell with the code, another listener is only stood up when dealing with consumers. Is this right?

@zbintliff
Copy link
Contributor Author

Gave it an attempt in #47

@zbintliff
Copy link
Contributor Author

Would love to get your feedback on #49 before I go through and fix all the tests.

@mefellows
Copy link
Member

Thanks @zbintliff, I've been away last week but will look over in the next few days.

@zbintliff
Copy link
Contributor Author

Hope you had a great time away, closing as this is resolved.

@mefellows
Copy link
Member

I sure did. Thanks for you patience in getting this one in.

You're currently wrapped in a beta release v0.0.10. I'll see how this goes over the next few week or so and bump it to latest if all good. This will include updating documentation etc.

@zbintliff
Copy link
Contributor Author

Also, I noticed here it says dsl/mock_service.go fails gofmt -s but when I write locally and diff there are no changes. Can't figure out what is wrong with it.

And a pre-release is awesome because we can build our jenkins pipeline around it for our clients still.

@mefellows
Copy link
Member

Yeah, I don't get that either. Strange.

@zbintliff
Copy link
Contributor Author

I just realized I did all of this so I could expose a set of known ports on the daemon/mockservice. Then i wrote it to bind to localhost :/

@mefellows
Copy link
Member

Pull request welcome 🤪

@zbintliff
Copy link
Contributor Author

Have to apologize. Seems my PR didn't really solve any issue. The feature works, you can limit the ports the mock servers are spun up on. But it only works if daemon and mockservers are on localhost with the process running the dsl.

  1. The first issue is the fact that the DSL checks if port is open. If daemon is on a different host, no guarantees on the port being available. Also, that port will never be busy on the DSL process so will for each client started it will probably find the same port.
  2. If everything is on the same host/container, exposing ports aren't going to be needed.

I have some thoughts on how to fix #1 and that involves the daemon determining the port. The DSL just passes the whole allowed port string through, the daemon determines the port and returns it as part of the server again.

I just wanted to step back and run some things past you before I dig into that. Thinking of making the following three changes:

  1. If pact.Host is not 'localhost' bind to 0.0.0.0 for mock server
  2. DSL passes "range" of allowed ports. Daemon determines and provides port again. Similar to how it was done before my first PR.

@mefellows
Copy link
Member

No worries.

You make some good points, I'm happy for both of those suggestions to be done - go for it.

That being said, we need to move away from the Daemon at some point anyway. I'm going to expedite the implementation options of removing it and will document it over in #31. Your thoughts would be much appreciated on that one.

@mefellows mefellows reopened this Oct 10, 2017
@springerigor
Copy link
Contributor

@mefellows Good job with https://github.com/pact-foundation/pact-go/tree/feat/daemonless! 👍
I managed to dockerize setup and run it without a daemon (consumer part so far).

@mefellows
Copy link
Member

That's fantastic news, thanks @springerigor! Please, any further feedback you have is much appreciated.

@gaelollivier
Copy link
Contributor

Hey @mefellows, thanks for the good work ! I'm currently implementing contract testing in a golang codebase and I stumbled around the same issue when trying to run pact-go inside Docker containers.
I'm currently trying-out your feat/daemonless branch, and it seems to work like a charm 👍 Managed to run both my consumer + provider tests with it ! Looking forward to have it released, do you have any ETA for that ?

I'm not sure I can find the time to make code contributions, but here's some feedback I have so far with using pact-go with Docker:

  • first, I could not install the binaries using the default install script. Not sure why but using the official golang:1.9, the uname -i command returns undefined instead of x86_64 , resulting in a failure of the install script. This is probably an issue for https://github.com/pact-foundation/pact-ruby-standalone but as a workaround, here's the Dockerfile is used to make it work:
FROM golang:1.9

# Install Pact binaries
RUN cd /opt &&\
    curl -LO https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.43.0/pact-1.43.0-linux-x86_64.tar.gz &&\
    tar xzf pact-*.tar.gz

ENV PATH="$PATH:/opt/pact/bin"

# Copy sources
WORKDIR /go/src/path/to/your/sources
COPY . .

# Run all tests
CMD go test -v ./...
  • Other issue I encountered is related to error printing. At first, my Dockerfile was not setting-up the PATH properly and my tests were failing to find the pact-mock-service program. However, the only output I had was something like this:
=== RUN   TestConsumer
exit status 1

It took me some time to figure-out the issue was that here https://github.com/pact-foundation/pact-go/blob/feat/daemonless/client/service_manager.go#L147, the error message was not actually printed. This is probably due to some buffering not being flushed before the program exits. So maybe not using os.Exit(1) or flushing stdout would help here.

Appart from these minor issues, I managed to run my tests without needing to run a daemon, which is awesome 👏

@mefellows
Copy link
Member

Thanks for this @gaelduplessix that's awesome. That os.exit is something to look at. Not sure we need it anymore.

We're probably looking at making it real in next month or two. Feedback on the API and install are the main things we're waiting on, aside from a good tidy up of the code (it's very POCy at the moment as we explored the API).

Will take this feedback onboard

@mefellows mefellows self-assigned this Jul 14, 2018
mefellows added a commit that referenced this issue Jul 14, 2018
@mefellows
Copy link
Member

Closing this issue for three reasons:

  1. Removed use of os.Exit() in service manager (see c2dcd78)
  2. Daemon no longer exists in the latest release.
  3. @gaelduplessix 's docker container contains useful information for others to go on. I've considered created one for this project, but it's really not that difficult and most times I've done this I end up customising it to a specific set of needs anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants