Travis CI: start rails server - ruby-on-rails

I need to start a rails server on Travis to run integration tests.
I've added this to the config file:
before_script:
- psql -c 'create database scalia_test;' -U postgres
- "bundle exec rails server -p 3000 &"
However, I still get an error from Cypress:
http://localhost:3000/users/sign_in
We attempted to make an http request to this URL but the request failed without a response.
We received this error at the network level:
> Error: connect ECONNREFUSED 127.0.0.1:3000
Common situations why this would fail:
- you don't have internet access
- you forgot to run / boot your web server
- your web server isn't accessible
- you have weird network configuration settings on your computer
The stack trace for this error is:
Error: connect ECONNREFUSED 127.0.0.1:3000
at Object.exports._errnoException (util.js:1024:11)
at exports._exceptionWithHostPort (util.js:1047:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1150:14)
Does anybody knows how to start a Rails server on Travis ?

You are using & to send the command to the background, then you are running your tests right?
By the time you are running the tests Travis is still booting up your Rails server in the background therefore it's erroring out saying it can't connect. In my opinion it doesn't have to do anything with port binding.
In order to fix that you should use the -d parameter to daemonize rails after it started:
before_script:
- psql -c 'create database scalia_test;' -U postgres
- "bundle exec rails server -p 3000 -d"
rails server will block until it listens on port 3000 then sends itself to the background and continue running your scripts.
Do note that after your tests have run you may kill the rails server again using:
kill -9 $(cat tmp/pids/server.pid)
Otherwise you'll get a timeout or another error from travis.

Try binding rails to the loopback IP in that port
bundle exec rails s -p 3000 -b 127.0.0.1

probably that port is in use. Type lsof -i :8000 in terminal to see if that port is beeing used
U can try to start server with difrent port like rails server -p 3050

Related

Docker tutorial, localhost:4000 is inaccessible

Following the tutorial on https://docs.docker.com/get-started/part2/.
I start my docker container with docker run -p 4000:80 friendlyhello
and see
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://0.0.0.0:8088/ (Press CTRL+C to quit)
But it's inaccessible from the expected path of localhost:4000.
$ curl http://localhost:4000/
curl: (7) Failed to connect to localhost port 4000: Connection refused
$ curl http://127.0.0.1:4000/
curl: (7) Failed to connect to 127.0.0.1 port 4000: Connection refused
Okay, so maybe it's not on my local host. Getting the container ID I retrieve the IP with
docker inspect --format '{{ .NetworkSettings.IPAddress }}' 7e5bace5f69c
and it returns 172.17.0.2 but no luck! curl continues to give the same responses. I can confirm something is running on 4000....
lsof -i :4000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
com.docke 94812 travis 18u IPv6 0x7516cbae76f408b5 0t0 TCP *:terabase (LISTEN)
I'm pulling my hair out on this. I've read through the troubleshooting guide and can confirm
* not on a proxy
* don't use a custom dns
* I'm having issues connecting to docker, not docker connecting to my pip server.
Running the app.py with python app.py the server starts and I'm able to hit it. What am I missing?
Did you accidentally put port=8088 at the bottom of your app.py file? When you are running this the last line of your output is saying that your python app is exposed on port 8088 not 80.
To confirm you can run either modify the app.py file and rebuild the image, or alternatively you could run: docker run -p 4000:8088 friendlyhello which would map your local port 4000 to 8088 in the container.
Try to run it using:
docker run -p 4000:8088 friendlyhello
As you can see from the logs, your app starts on port 8088, but you connect 4000 to 80 where on 80, nothing is actually listening.

Issue with getting RubyMine debugger to work with Docker

I'm setting up RubyMine Debugger with Docker but I believe I have an issue with the matching the ports and I can't find documentation that thoroughly explains what the "configuration form in ruby mine is asking for and how to find the related information for the form input fields" all I can find is generic information.
I have had many error messages and even crashing when I click the debugger button. I have tried a lot more then what I'm posting but I never wrote it down. This is just where I am at this current moment
I have followed https://confluence.jetbrains.com/display/RUBYDEV/How+to+setup+and+run+ruby+remote+debug+session
I have added ports to the docker-compose.yml file.
Setup configuration for remote Remote Ruby SDK and Gem.
Setup Ruby remote debug configuration.
I have tried working my way through every error but I just get more as I go.
This app uses docker-compose and I'm not familiar with it at all other then all the reading I been doing to get this debugger setup
docker-compose.yml file
app:
build: wffffffe_api
dockerfile: Dockerfile-development
command: rails server --port 3000 --binding 0.0.0.0
stdin_open: true
tty: true
ports:
- "3000:3000"
- "1234:1234"
- "26162:26162"
volumes:
- './wfffffe_api:/var/www/weffffffe_api'
- './dotfiles/.vimrc-basic:/root/.vimrc'
The debugger configuration
Remote host: 0.0.0.0
Remote port: 3000
Remote root folder: /var/www/wffffffe_api
local port: 26162
local root folder: /Users/josh/Work/wffffffe_api
I have tried doing
docker-compose exec app rdebug-ide --host 0.0.0.0 --port 3000 --dispatcher-port 26162 -- bin/rails server
If the docker container is already running I get:
Fatal exception in DebugThread loop:
Address already in use - bind(2) for "0.0.0.0" port 3000
If the docker container is not already running I get:
Fast Debugger (ruby-debug-ide 0.6.1, debase 0.2.2, file filtering is supported) listens on 0.0.0.0:3000
I then do docker-compose up --build -d
ERROR: for app Cannot start service app: b'driver failed programming external connectivity on endpoint work_app_1 (1e830daaecd39fab784b817a03893b592635542a8dfe3de69859c0ba7d39b483): Error starting userland proxy: Bind for 0.0.0.0:3000 failed: port is already allocated'
Do I need to have two separate servers running?
Your problem is that you are trying to debug on port 3000, which already bound by your rails application.
The --port of rdebug-ide specify the port that RubyMine will use for its debug protocol.
When you execute rails server --port 3000 --binding 0.0.0.0, you are binding port 3000 as your rails application (and not as debug port).
Change your remote port debug to 1234 (which you already exposed in your docker-compose.yml) and it should work.
To summarise, your command should look like:
docker-compose exec app rdebug-ide --host 0.0.0.0 --port 1234 --dispatcher-port 26162 -- bin/rails server --port 3000 --binding 0.0.0.0

AWS kills server upon ssh client auto logout

I am running rails application by calling "rails server". I use ssh client to connect to aws. The ssh client connection to aws always auto logout. The message is "Connection reset by 13.250.214.114 port 22". When auto logout, the "rails server" is killed.
Could i stop aws from killing the rails application ?
Instead of
rails server
do:
rails s -d
then to kill it, find which process is using the port:
lsof -i :3000
finally, kill the process:
kill -9 $(lsof -i :3000 -t)
Create aliases:
alias startRails='rails server -d'
alias stopRails='kill -9 $(lsof -i :3000 -t)'
Source

Deleted Server.pids but still can not run app in Rails

After deleting the file Server.pids as instructed in the below link, I still can not run my app. Please see at the end of this message the output in terminal.
How can I solve this?
Thanks
Link:
Server is already running in Rails
New error in terminal (Mac):
Exiting
/Users/agustinguerrero/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/socket.rb:206:in `bind': Address already in use - bind(2) for 0.0.0.0:3000 (Errno::EADDRINUSE)
You are getting this error because another server is really running - try running localhost:3000 in your browser.
It doesn't need to be the same rails app - it is simply saying that port 3000 is already taken. You might:
Restart your machine
Run app on different port: rails s -p 3001 #or other port
Find what is taking port 3000 and kill it (you must be sure it is ok to kill it first though):
fuser -n tcp 3000 #=> 3000/tcp: xxxx
kill xxxx
Kill the already running instance by getting the pid through:
ps aux | grep rails
Then kill it

cURL cannot connect to localhost but browser can

I'm running a Rails app locally (Thin server), and I can connect locally from the browser (localhost:3000), but when I try to use curl, I get:
curl -H 'id:1' -i 'http://localhost:3000/api/data' -v
* Hostname was NOT found in DNS cache
* Trying ::1...
* Adding handle: conn: 0x7fd121808200
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fd121808200) send_pipe: 1, recv_pipe: 0
* Connection failed
* connect to ::1 port 3000 failed: Connection refused
* Trying fe80::1...
* Connection failed
* connect to fe80::1 port 3000 failed: Connection refused
* Failed to connect to localhost port 3000: Connection refused
* Closing connection 0
curl: (7) Failed to connect to localhost port 3000: Connection refused
This used to work just fine, but I recently updated to Mavericks, which I suspect may have broken something. I can also curl successfully from the web.
This is a curl bug (a strange one), where curl fails to fall back to IPv4 if there's an IPv6 entry in /etc/hosts that doesn't respond.
You can force it to use IPv4 via the -4 option.
Instead of
curl localhost:3000
try
curl 0.0.0.0:3000
It works.
If it doesn't, check the output when you start your rails server:
=> Booting WEBrick
=> Rails 3.2.13 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2014-10-28 15:30:08] INFO WEBrick 1.3.1
[2014-10-28 15:30:08] INFO ruby 2.0.0 (2014-02-24) [x86_64-darwin12.5.0]
[2014-10-28 15:30:08] INFO WEBrick::HTTPServer#start: pid=4004 port=3000
Use the url at the end of line 2 instead of ENV['HOST']
Are you behind a proxy? Then use the below to bypass the proxy altogether.
curl -x "" "http://127.0.0.1:3000"
Assuming that you have not touched /etc/hosts and scutil reports are positive:
$ scutil -r 127.0.0.1
Reachable,Local Address
$ scutil -r localhost
Reachable,Local Address
then my guess is that the Firewall is active and not accepting connections from curl.
Try adding curl to the list accepted applications under (I'm guessing at the language alternatives since my machine is set to use Swedish) Preference --> Security --> Firewall alternatives --> plus sign --> (serach for curl and add it)
Note: make sure that you add the curl that you are actually using in your shell.
$ type -a curl
curl is /opt/local/bin/curl
curl is /usr/bin/curl
Another cause of this issue can be a poorly configured system with a proxy address. Run
export http_proxy=
and rerun the curl command, to eliminate this as a contributing factor. It fixed this issue for me.
Restarting the computer can sometimes fix odd connection issues. I'm not sure why.

Resources