Using a RabbitMQ service to test NPM package

Hiya folks!

Has anyone had any luck using a RabbitMQ service? I’ve tried a few different ways but can’t seem to be able to connect to the instance; I always get an  ENOTFOUND error.

Here’s a smattering of snippets I’ve tried thus far, with REMIT_URL being the RabbitMQ address to connect to:

Using a container:

container:
image: node:10.16-jessie

services:
  rabbitmq:
    image: rabbitmq
    ports:
      - 5672:5672

steps:
  - uses: actions/checkout@v1
  - uses: actions/setup-node@v1
    with:
      node-version: 12
  - run: npm ci
  - name: 'test package'
    run: npm test
    env:
      REMIT_URL: amqp://rabbitmq:${{ job.services.rabbitmq.ports[5672] }}

Using a VM:

services:
  rabbitmq:
    image: rabbitmq
    ports:
      - 5672/tcp

steps:
  - uses: actions/checkout@v1
  - uses: actions/setup-node@v1
    with:
      node-version: 12
  - run: npm ci
  - name: 'test package'
    run: npm test
    env:
      REMIT_URL: amqp://localhost:${{ job.services.rabbitmq.ports[5672] }}

Both VM and container methods (adjusting between  localhost and  rabbitmq accordingly), while also using health checks:

services:
  rabbitmq:
    image: rabbitmq
    ports:
      - 5672/tcp
    options: '--health-cmd "rabbitmqctl status" --health-interval 10s --health-timeout 10s --health-retries 6 --health-start-period 60s'

Both VM and container methods (adjusting between localhost and  rabbitmq accordingly), while also using ufoscout/docker-compose-wait to wait for the RabbitMQ instance to be available (the check times out waiting):

steps:
  - uses: actions/checkout@v1
  - uses: actions/setup-node@v1
    with:
      node-version: 12
  - run: npm ci
  - name: 'test package'
    run: |
./.github/utils/wait
npm test
    env:
      WAIT_HOSTS: localhost:${{ job.services.rabbitmq.ports[5672] }}
      REMIT_URL: amqp://localhost:${{ job.services.rabbitmq.ports[5672] }}

Am I missing something obvious? I don’t have too much experience with compose files so I may well be making a rookie error here, but if that’s not the case then what’s the best way to proceed debugging this?

Thanks folks!

Upon further investigation, it seems I’m just struggling to get the  rabbitmq container to run. I can get it working locally and the health checks pass okay, but it just never seems to boot inside a GHA VM.

What’s the best way of debugging the container that’s failing to start healthily here?

Following @dentarg’s example in actions/example-services#3, I now have it working, so I guess I’ll post this as the solution.

The config that finally seemed to work was using a VM (so not utilising  container > image ) and the following  services  block:

services:
  rabbitmq:
    image: rabbitmq:latest
    ports:
      - 5672/tcp
    options: --health-cmd "rabbitmqctl node_health_check" --health-interval 10s --health-timeout 5s --health-retries 5

Alongside accessing the instance using:

amqp://localhost:${{ job.services.rabbitmq.ports[5672] }}

As mentioned in the issue, I’m not really sure whether this is a meaningful change or whether something was fixed behind the scenes, but it works now!

Thanks for the fantastic work!