How to use Rabbit inside a gitlab-ci.yml file?
Asked Answered
L

1

16

I want to test with gitlab-ci.yml a rpc nameko server.

I can't succeed to make work the Rabitt inside .gitlab-ci.yml::

image: python:latest

before_script:
  - apt-get update -yq
  - apt-get install -y python-dev python-pip tree
  - curl -I http://guest:guest@rabbitmq:8080/api/overview

mytest:
  artifacts:
    paths:
    - dist
  script:
  - pip install -r requirements.txt 
  - pip install .
  - pytest --amqp-uri=amqp://guest:guest@rabbitmq:5672 --rabbit-ctl-uri=http://guest:guest@rabbitmq:15672 tests
  # - python setup.py test
  - python setup.py bdist_wheel

look:
  stage: deploy
  script:
  - ls -lah dist
services:
  - rabbitmq:3-management

The Rabbit start correctly::

2017-04-13T18:19:23.436309219Z 
2017-04-13T18:19:23.436409026Z               RabbitMQ 3.6.9. Copyright (C) 2007-2016 Pivotal Software, Inc.
2017-04-13T18:19:23.436432568Z   ##  ##      Licensed under the MPL.  See http://www.rabbitmq.com/
2017-04-13T18:19:23.436451431Z   ##  ##
2017-04-13T18:19:23.436468542Z   ##########  Logs: tty
2017-04-13T18:19:23.436485607Z   ######  ##        tty
2017-04-13T18:19:23.436501886Z   ##########
2017-04-13T18:19:23.436519036Z               Starting broker...
2017-04-13T18:19:23.440790736Z 
2017-04-13T18:19:23.440809836Z =INFO REPORT==== 13-Apr-2017::18:19:23 ===
2017-04-13T18:19:23.440819014Z Starting RabbitMQ 3.6.9 on Erlang 19.3
2017-04-13T18:19:23.440827601Z Copyright (C) 2007-2016 Pivotal Software, Inc.
2017-04-13T18:19:23.440835737Z Licensed under the MPL.  See http://www.rabbitmq.com/
2017-04-13T18:19:23.443408721Z 
2017-04-13T18:19:23.443429311Z =INFO REPORT==== 13-Apr-2017::18:19:23 ===
2017-04-13T18:19:23.443439837Z node           : rabbit@ea1a207b738e
2017-04-13T18:19:23.443449307Z home dir       : /var/lib/rabbitmq
2017-04-13T18:19:23.443460663Z config file(s) : /etc/rabbitmq/rabbitmq.config
2017-04-13T18:19:23.443470393Z cookie hash    : h6vFB5LezZ4GR1nGuQOVSg==
2017-04-13T18:19:23.443480053Z log            : tty
2017-04-13T18:19:23.443489256Z sasl log       : tty
2017-04-13T18:19:23.443498676Z database dir   : /var/lib/rabbitmq/mnesia/rabbit@ea1a207b738e
2017-04-13T18:19:27.717290199Z 
2017-04-13T18:19:27.717345348Z =INFO REPORT==== 13-Apr-2017::18:19:27 ===
2017-04-13T18:19:27.717355143Z Memory limit set to 3202MB of 8005MB total.
2017-04-13T18:19:27.726821043Z 
2017-04-13T18:19:27.726841925Z =INFO REPORT==== 13-Apr-2017::18:19:27 ===
2017-04-13T18:19:27.726850927Z Disk free limit set to 50MB
2017-04-13T18:19:27.732864417Z 
2017-04-13T18:19:27.732882507Z =INFO REPORT==== 13-Apr-2017::18:19:27 ===
2017-04-13T18:19:27.732891347Z Limiting to approx 1048476 file handles (943626 sockets)
2017-04-13T18:19:27.733030868Z 
2017-04-13T18:19:27.733041770Z =INFO REPORT==== 13-Apr-2017::18:19:27 ===
2017-04-13T18:19:27.733049763Z FHC read buffering:  OFF
2017-04-13T18:19:27.733126168Z FHC write buffering: ON
2017-04-13T18:19:27.793026622Z 
2017-04-13T18:19:27.793043832Z =INFO REPORT==== 13-Apr-2017::18:19:27 ===
2017-04-13T18:19:27.793052900Z Database directory at /var/lib/rabbitmq/mnesia/rabbit@ea1a207b738e is empty. Initialising from scratch...
2017-04-13T18:19:27.800414211Z 
2017-04-13T18:19:27.800429311Z =INFO REPORT==== 13-Apr-2017::18:19:27 ===
2017-04-13T18:19:27.800438013Z     application: mnesia
2017-04-13T18:19:27.800464988Z     exited: stopped
2017-04-13T18:19:27.800473228Z     type: temporary
2017-04-13T18:19:28.129404329Z 
2017-04-13T18:19:28.129482072Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===
2017-04-13T18:19:28.129491680Z Waiting for Mnesia tables for 30000 ms, 9 retries left
2017-04-13T18:19:28.153509130Z 
2017-04-13T18:19:28.153526528Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===
2017-04-13T18:19:28.153535638Z Waiting for Mnesia tables for 30000 ms, 9 retries left
2017-04-13T18:19:28.193558406Z 
2017-04-13T18:19:28.193600316Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===
2017-04-13T18:19:28.193611144Z Waiting for Mnesia tables for 30000 ms, 9 retries left
2017-04-13T18:19:28.194448672Z 
2017-04-13T18:19:28.194464866Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===
2017-04-13T18:19:28.194475629Z Priority queues enabled, real BQ is rabbit_variable_queue
2017-04-13T18:19:28.208882072Z 
2017-04-13T18:19:28.208912016Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===
2017-04-13T18:19:28.208921824Z Starting rabbit_node_monitor
2017-04-13T18:19:28.211145158Z 
2017-04-13T18:19:28.211169236Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===
2017-04-13T18:19:28.211182089Z Management plugin: using rates mode 'basic'
2017-04-13T18:19:28.224499311Z 
2017-04-13T18:19:28.224527962Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===
2017-04-13T18:19:28.224538810Z msg_store_transient: using rabbit_msg_store_ets_index to provide index
2017-04-13T18:19:28.226355958Z 
2017-04-13T18:19:28.226376272Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===
2017-04-13T18:19:28.226385706Z msg_store_persistent: using rabbit_msg_store_ets_index to provide index
2017-04-13T18:19:28.227832476Z 
2017-04-13T18:19:28.227870221Z =WARNING REPORT==== 13-Apr-2017::18:19:28 ===
2017-04-13T18:19:28.227891823Z msg_store_persistent: rebuilding indices from scratch
2017-04-13T18:19:28.230832501Z 
2017-04-13T18:19:28.230872729Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===
2017-04-13T18:19:28.230893941Z Adding vhost '/'
2017-04-13T18:19:28.385440862Z 
2017-04-13T18:19:28.385520360Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===
2017-04-13T18:19:28.385540022Z Creating user 'guest'
2017-04-13T18:19:28.398092244Z 
2017-04-13T18:19:28.398184254Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===
2017-04-13T18:19:28.398206496Z Setting user tags for user 'guest' to [administrator]
2017-04-13T18:19:28.413704571Z 
2017-04-13T18:19:28.413789806Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===
2017-04-13T18:19:28.413810378Z Setting permissions for 'guest' in '/' to '.*', '.*', '.*'
2017-04-13T18:19:28.451109821Z 
2017-04-13T18:19:28.451162892Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===
2017-04-13T18:19:28.451172185Z started TCP Listener on [::]:5672
2017-04-13T18:19:28.475429729Z 
2017-04-13T18:19:28.475491074Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===
2017-04-13T18:19:28.475501172Z Management plugin started. Port: 15672
2017-04-13T18:19:28.475821397Z 
2017-04-13T18:19:28.475835599Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===
2017-04-13T18:19:28.475844143Z Statistics database started.
2017-04-13T18:19:28.487572236Z  completed with 6 plugins.
2017-04-13T18:19:28.487797794Z 
2017-04-13T18:19:28.487809763Z =INFO REPORT==== 13-Apr-2017::18:19:28 ===
2017-04-13T18:19:28.487818426Z Server startup complete; 6 plugins started.
2017-04-13T18:19:28.487826288Z  * rabbitmq_management
2017-04-13T18:19:28.487833914Z  * rabbitmq_web_dispatch
2017-04-13T18:19:28.487841610Z  * rabbitmq_management_agent
2017-04-13T18:19:28.487861057Z  * amqp_client
2017-04-13T18:19:28.487875546Z  * cowboy
2017-04-13T18:19:28.487883514Z  * cowlib

*********

But I get this error

$ pytest --amqp-uri=amqp://guest:guest@rabbitmq:5672 --rabbit-ctl-uri=http://guest:guest@rabbitmq:15672 tests
============================= test session starts ==============================
platform linux -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0
...
E           Exception: Connection error for the RabbitMQ management HTTP API at http://guest:guest@rabbitmq:15672/api/overview, is it enabled?
...
source:565: DeprecationWarning: invalid escape sequence \*
ERROR: Job failed: exit code 1
Lucianaluciano answered 14/4, 2017 at 10:45 Comment(1)
related to #43410294Lucianaluciano
S
11

I used it the following way and it worked for me

image: "ruby:2.3.3" //not required by rabbitmq

services:
  - rabbitmq:latest

variables:
  RABBITMQ_DEFAULT_USER: guest
  RABBITMQ_DEFAULT_PASS: guest
  AMQP_URL: 'amqp://guest:guest@rabbitmq:5672'

Now you can use the AMQP_URL env variable to connect to the rabbimq server. The general rule of thumb is any services declared will have the name (e.g. rabbitmq from rabbitmq:latest) as host or url or server. However in case you are running it in your own server or kubernetes cluster it will be localhost or 127.0.0.1. In my humble opinion that might be issue in your code. Hope it helps. :)

Setzer answered 22/5, 2018 at 9:19 Comment(5)
AMQP_URL this env variable is not defined in the docker hub documentation. From where did you get this? Thanks.Apotropaic
@Apotropaic the AMQP_URL is application defined. your application is referencing this variable to access rabbitmqSetzer
Yes. I figured it. Anyway, appreciate you replied mate. Thanks.Apotropaic
Following the above information , but I got exception and explained it on the following link : #57786888Enculturation
@YeasinArRahman I have mention the instruction but I got org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused).Enculturation

© 2022 - 2024 — McMap. All rights reserved.