Hey all. I’m trying to run pact-go in docker in ou...
# pact-go
w
Hey all. I’m trying to run pact-go in docker in our CI/CD, but I’m having issues building the container in CI. The plan is to create a test binary in an initial build stage, and then copy that binary alone into the next stage to keep the image size down. So in the build stage, I’m downloading and unzipping the FFI library into the correct location, but when I then try to build the binary, pact-go seems to have issues with finding the library that cause the build to fail. There’s no other obvious setup thats mentioned on the github, has anyone else had any success in getting a docker image built with pact-go?
m
Mind sharing the Dockerfile? I can take a look for you
when you say “build the binary” which one - pact go?
w
Copy code
# syntax=docker/dockerfile:1

FROM europe-docker.pkg.dev/management1c0c88c4/oci/go:latest AS builder
USER root

ARG NAME
ARG VERSION=unknown
ARG GITHUB_AUTH_TOKEN

ENV VERSION=$VERSION
ENV GITHUB_AUTH_TOKEN=$GITHUB_AUTH_TOKEN
ENV GOOUT=.

COPY . .

RUN \
wget <https://github.com/pact-foundation/pact-reference/releases/download/libpact_ffi-v0.4.0/libpact_ffi-linux-x86_64.so.gz>
RUN gunzip libpact_ffi-linux-x86_64.so.gz
RUN mv libpact_ffi-linux-x86_64.so /usr/local/lib/libpact_ffi.so
RUN ldconfig /usr/local/lib/libpact_ffi.so

RUN \
  GOMODCACHE=/usr/src/.go/pkg/mod \
  go test -c ./internal/provider/mas


# Stage 2 - Copy binary from Build Stage
FROM pactfoundation/pact-cli:latest

COPY --from=builder /mas.test /go-tests

COPY --from=builder /pact/entrypoint.sh /go-tests

ENTRYPOINT ["/go-tests/entrypoint.sh"]
There’s still some stuff I’ve been playing around with in there, but this is the current state
And building the binary I mean the
go test -c
command
👍 1
m
ta
OK so I can’t reproduce with your docker image for various reasons (which are no doubt obvious to you 😆 ) But what is obviously standing out is that it can’t access the
native
package
the fully qualified package is
"<http://github.com/pact-foundation/pact-go/v2/internal/native|github.com/pact-foundation/pact-go/v2/internal/native>"
I’m wondering if the mod file is incorrect and hasn’t pulled in the package properly?
w
Haha yeah thought you’d struggle to replicate 😄 Okay let me take a gander at that package
Hmmm so I’ve not explicitly got the native package called out anywhere, but I’m guessing it would just implicitly be apart of
<http://github.com/pact-foundation/pact-go/v2|github.com/pact-foundation/pact-go/v2>
anyways right?
Our
go.sum
currently has the following two lines
Copy code
<http://github.com/pact-foundation/pact-go/v2|github.com/pact-foundation/pact-go/v2> v2.0.0-beta.17.0.20230125022501-fa1a8deab0a0 h1:z0o1WaPGcDEHQ8uNRfwL0V6OfWqAt7/P26jWmMHn8TA=
<http://github.com/pact-foundation/pact-go/v2|github.com/pact-foundation/pact-go/v2> v2.0.0-beta.17.0.20230125022501-fa1a8deab0a0/go.mod h1:kB2X26JGY+sd07XdG9LI4OK+aY8cTQ/IB56oBg2wT9o=
And
go.mod
has
Copy code
<http://github.com/pact-foundation/pact-go/v2|github.com/pact-foundation/pact-go/v2> v2.0.0-beta.17.0.20230125022501-fa1a8deab0a0
I’ve just used
go install
to add them
m
I think so
I don’t think you do need all of the sub packages there, but if it was just the consumer that could be a problem.
w
Have you had any experience with running it in github actions? Part of the reason I am where I am is because there didn’t seem to be a clear way to generate the contract in one action, and then pass the contract into the CLI docker image in order to push it into the broker
I’m not sure if I’m missing something and there’s actually a more sensible way to do it perhaps
m
oh right, then there is definitely a way to do that
w
Ya
m
I was about to question the whole enterprise of build stages, because I can’t see why that’s a good thing to do 😆
w
I am all ears]
Hahaha yeah it seemed like the most simple course when I was chatting with one of my devs. Because of the FFI lib pre-req, I didn’t know how to get that running in actions
m
Have you had any experience with running it in github actions? Part of the reason I am where I am is because there didn’t seem to be a clear way to generate the contract in one action, and then pass the contract into the CLI docker image in order to push it into the broker
so you just want to: 1. Run the pact tests 2. Publish the contract file In a single action, or must it be across multiple stages?
(please ignore the use of tags, it is not really important for the build, but should be using
--branch
because that’s what we tell people to do)
w
A single action in itself would be fine ye. Currently the test runs as part of the unit tests, but the pact one always fails because the lib isn’t installed iirc
That publish command is part of the CLI right>
1
Ah yeah its the docker image
m
Apologies, the latest version of that for the 2.x.x branch is https://github.com/pact-foundation/pact-go/blob/2.x.x/Makefile
it’s very similar, but there are other parts of the Makefile that might be helpful - e.g. installing the lib
I have to run, but hopefully the info there is helpful?
w
Yeah I’ll see where I can get with this, thanks Matt. One last q, do these all run as part of a single action, or is it across multiple?
m
I run it as a single. There is usually no need to delay publishing the pact file. You could have it as a separate step in the pipeline (we do that in our examples, see howtoexamples) but that’s up to you
🙏 1
s
m
The Pact Broker/PactFlow is designed to have large amounts of duplicate pacts published - so just send it without fear. It’s our job to make it performant
w
Nice thanks Matt, really appreciate your help as always
👍 1
❤️ 1