Hello all. I am having issue with publishing my pa...
# pact-broker
a
Hello all. I am having issue with publishing my pacts to broker hosted in bitbucket pipelines. I am using the docker-compose.yml from the github repo (pact-foundation/pact-broker-docker). My tests pass locally (using docker on Macbook) but when deployed to bitbucket pipelines, I get this error:
[03:20:05.795] INFO (62): pact-core@13.13.8: Publishing Pacts to Broker
[03:20:05.799] INFO (62): pact-core@13.13.8: Publishing pacts to broker at: <http://localhost:9292/>
[03:20:26.475] WARN (62): pact-core@13.13.8: Pact exited with code 1.
[03:20:26.476] ERROR (62): pact-core@13.13.8: Pact publication failed with non-zero exit code. Full output was:
`ERROR: Error making request - Errno::ECONNREFUSED Failed to open TCP connection to localhost:9292 (Connection refused - connect(2) for "localhost" port 9292) /opt/atlassian/pipelines/agent/build/node_modules/@pact-foundation/pact-core/standalone/linux-x64-1.92.0/pact/lib/vendor/ruby/2.4.0/gems/pact_broker-client-1.65.0/lib/pact_broker/client/hal/http_client.rb79in
block in perform_request', attempt 1 of 5
I have tried a few suggestions from other's post (stackoverflow/ Atlassian Support) but have to yet find a solution that works for me. Do you have any suggestions for me try?
m
Is the broker running on the CI environment? It looks like you’re trying to hit
localhost
but if it’s running on your machine, the CI won’t be able to reach that it should be deployed somewhere centrally that your dev environment, CI and other team members can access.
a
Yes, the docker containers are being deployed as part of the pipelines code execution. Here's the bitbucket-pipelines.yml
Copy code
#  Template NodeJS build

#  This template allows you to validate your NodeJS code.
#  The workflow allows running tests and code linting on the default branch.

image: node:16

options:
  docker: true

definitions:
  caches:
    docker-cliplugins: ~/.docker/cli-plugins
  yaml-anchors:
    - &setup-docker-compose-latest-script >-
      wget --no-verbose --no-clobber <https://github.com/docker/compose/releases/latest/download/docker-compose-linux-x86_64> --output-document ~/.docker/cli-plugins/docker-compose
      || true
      ; chmod a+x ~/.docker/cli-plugins/docker-compose
      && ln --symbolic ~/.docker/cli-plugins/docker-compose /usr/local/bin/docker-compose  

pipelines:
  default:
    - step:
        name: Install dependencies
        caches:
          - node
        script:
          - npm install
    - step:
        name: Start Docker container
        services: [docker]
        caches: [docker-cliplugins]
        script:
          - *setup-docker-compose-latest-script
          - docker compose version
          - docker-compose -f docker-compose.yml up -d
    - step:
        name: Run Contract Tests
        caches:
          - node
          - docker
        script:
          - npm run test:consumer
          - npm run test:provider
    - step:
        name: Stop Docker container
        services: [docker]
        caches: [docker-cliplugins]
        script:
          - docker-compose down
The PACT_BROKET_BASE_URL values include 'https://host.docker.internal http://host.docker.internal http://host.docker.internal:9292' but they don't seem to be used. I assume the tests call the pact broker based on the configuration (.yml files), localhost or host.docker.internal.
m
PACT_BROKER_BASE_URL
should point exactly to the base URL of your broker. It’s not a comma separated list
<https://host.docker.internal>
is a special DNS only available within docker containers, not from outside