Issue with falcon web server when running containerized - ruby

I tried to use falcon within a container built from this Dockerfile:
FROM docker.io/library/ruby:3.1.2 AS build-stage
COPY Gemfile .
COPY Gemfile.lock .
RUN bundle install
WORKDIR /app
COPY . .
CMD falcon host
My falcon.rb looks as follows
#!/usr/bin/env -S falcon host
# frozen_string_literal: true
load :rack, :supervisor
rack 'localhost' do
endpoint Async::HTTP::Endpoint
.parse('http://0.0.0.0:3001')
end
supervisor
But when I try to launch this container I get the following error message:
{"time":"2022-12-02T14:29:44+00:00","severity":"info","class":"Falcon::Command::Host","oid":2680,"pid":2,"subject":"Falcon::Command::Host","message":"Falcon Host v0.42.3 taking flight!\n- Configuration: falcon.rb\n- To terminate: Ctrl-C or kill 2\n- To reload: kill -HUP 2\n"}
/usr/local/bundle/gems/falcon-0.42.3/lib/falcon/service/supervisor.rb:23:in `require': cannot load such file -- process/metrics (LoadError)
from /usr/local/bundle/gems/falcon-0.42.3/lib/falcon/service/supervisor.rb:23:in `<top (required)>'
from /usr/local/bundle/gems/falcon-0.42.3/lib/falcon/environments/supervisor.rb:23:in `require_relative'
from /usr/local/bundle/gems/falcon-0.42.3/lib/falcon/environments/supervisor.rb:23:in `block in load'
from /usr/local/bundle/gems/falcon-0.42.3/lib/falcon/configuration.rb:134:in `instance_eval'
from /usr/local/bundle/gems/falcon-0.42.3/lib/falcon/configuration.rb:134:in `block in load'
from /usr/local/bundle/gems/falcon-0.42.3/lib/falcon/configuration.rb:127:in `each'
from /usr/local/bundle/gems/falcon-0.42.3/lib/falcon/configuration.rb:127:in `load'
from /app/falcon.rb:4:in `load_file'
from /usr/local/bundle/gems/falcon-0.42.3/lib/falcon/configuration.rb:118:in `instance_eval'
from /usr/local/bundle/gems/falcon-0.42.3/lib/falcon/configuration.rb:118:in `load_file'
from /usr/local/bundle/gems/falcon-0.42.3/lib/falcon/configuration.rb:85:in `load_file'
from /usr/local/bundle/gems/falcon-0.42.3/lib/falcon/command/host.rb:54:in `block in configuration'
from /usr/local/bundle/gems/falcon-0.42.3/lib/falcon/command/host.rb:52:in `each'
from /usr/local/bundle/gems/falcon-0.42.3/lib/falcon/command/host.rb:52:in `configuration'
from /usr/local/bundle/gems/falcon-0.42.3/lib/falcon/controller/host.rb:39:in `initialize'
from /usr/local/bundle/gems/falcon-0.42.3/lib/falcon/command/host.rb:62:in `new'
from /usr/local/bundle/gems/falcon-0.42.3/lib/falcon/command/host.rb:62:in `controller'
from /usr/local/bundle/gems/falcon-0.42.3/lib/falcon/command/host.rb:84:in `call'
from /usr/local/bundle/gems/falcon-0.42.3/lib/falcon/command/top.rb:105:in `call'
from /usr/local/bundle/gems/samovar-2.1.4/lib/samovar/command.rb:36:in `call'
from /usr/local/bundle/gems/falcon-0.42.3/lib/falcon/command.rb:30:in `call'
from /usr/local/bundle/gems/falcon-0.42.3/bin/falcon:26:in `<top (required)>'
from /usr/local/bundle/bin/falcon:25:in `load'
from /usr/local/bundle/bin/falcon:25:in `<main>'
Interestingly everything works fine when running natively, but it seems when run inside a container there is an issue with the process/metrics dependency but I'm not sure how to resolve it.

As pointed out by #anothermh in the comments the solution was to use the bundler for running falcon in the Dockerfile:
CMD bundle exec falcon host

Related

Error while locally launching GitHub pages Jekyll page

I am building a GitHub pages website using Jekyll. I want to run this website locally but unfortunately I have a lot of errors.
I am running this command to launch my website on localhost
I followed this tutorial : https://docs.github.com/en/pages/setting-up-a-github-pages-site-with-jekyll/about-github-pages-and-jekyll
bundle exec jekyll serve
These are the errors I get :
$ bundle exec jekyll serve --incremental
done in 0.376 seconds.
Auto-regeneration: enabled for 'D:/melmasset.github.io'
C:/Ruby30/lib/ruby/gems/3.0.0/gems/jekyll-3.9.0/lib/jekyll/commands/serve/servlet.rb:3:in `require': cannot load such file -- webrick (LoadError)
from C:/Ruby30/lib/ruby/gems/3.0.0/gems/jekyll-3.9.0/lib/jekyll/commands/serve/servlet.rb:3:in `<top (required)>'
from C:/Ruby30/lib/ruby/gems/3.0.0/gems/jekyll-3.9.0/lib/jekyll/commands/serve.rb:184:in `require_relative'
from C:/Ruby30/lib/ruby/gems/3.0.0/gems/jekyll-3.9.0/lib/jekyll/commands/serve.rb:184:in `setup'
from C:/Ruby30/lib/ruby/gems/3.0.0/gems/jekyll-3.9.0/lib/jekyll/commands/serve.rb:102:in `process'
from C:/Ruby30/lib/ruby/gems/3.0.0/gems/jekyll-3.9.0/lib/jekyll/commands/serve.rb:93:in `block in start'
from C:/Ruby30/lib/ruby/gems/3.0.0/gems/jekyll-3.9.0/lib/jekyll/commands/serve.rb:93:in `each'
from C:/Ruby30/lib/ruby/gems/3.0.0/gems/jekyll-3.9.0/lib/jekyll/commands/serve.rb:93:in `start'
from C:/Ruby30/lib/ruby/gems/3.0.0/gems/jekyll-3.9.0/lib/jekyll/commands/serve.rb:75:in `block (2 levels) in init_with_program'
from C:/Ruby30/lib/ruby/gems/3.0.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
from C:/Ruby30/lib/ruby/gems/3.0.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
from C:/Ruby30/lib/ruby/gems/3.0.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
from C:/Ruby30/lib/ruby/gems/3.0.0/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
from C:/Ruby30/lib/ruby/gems/3.0.0/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
from C:/Ruby30/lib/ruby/gems/3.0.0/gems/jekyll-3.9.0/exe/jekyll:15:in `<top (required)>'
from C:/Ruby30/bin/jekyll:23:in `load'
from C:/Ruby30/bin/jekyll:23:in `<main>'
Ask me if you need other indications :)
This is a known issue with ruby 3 not having webrick by default anymore.
The good news are the issue has already been fixed and it's available from Jekyll 4.2.1.

Jekyll Build error

I am trying to build a jekyll site with the command jekyll build. When I run the command I get the following error:
/usr/local/share/ruby/gems/2.0/gems/bundler-1.13.1/lib/bundler/rubygems_ext.rb:45:in `full_gem_path': uninitialized constant Bundler::Plugin::API::Source (NameError)
from /usr/share/ruby/vendor_ruby/2.0/rubygems/specification.rb:1393:in `contains_requirable_file?'
from /usr/share/ruby/vendor_ruby/2.0/rubygems/core_ext/kernel_require.rb:68:in `block in require'
from /usr/share/ruby/vendor_ruby/2.0/rubygems/specification.rb:823:in `block in each'
from /usr/share/ruby/vendor_ruby/2.0/rubygems/specification.rb:822:in `each'
from /usr/share/ruby/vendor_ruby/2.0/rubygems/specification.rb:822:in `each'
from /usr/share/ruby/vendor_ruby/2.0/rubygems/core_ext/kernel_require.rb:67:in `find'
from /usr/share/ruby/vendor_ruby/2.0/rubygems/core_ext/kernel_require.rb:67:in `require'
from /usr/local/share/ruby/gems/2.0/gems/bundler-1.13.1/lib/bundler/plugin/api/source.rb:2:in `<top (required)>'
from /usr/local/share/ruby/gems/2.0/gems/bundler-1.13.1/lib/bundler/rubygems_ext.rb:45:in `full_gem_path'
from /usr/share/ruby/vendor_ruby/2.0/rubygems/specification.rb:1393:in `contains_requirable_file?'
from /usr/share/ruby/vendor_ruby/2.0/rubygems/core_ext/kernel_require.rb:68:in `block in require'
from /usr/share/ruby/vendor_ruby/2.0/rubygems/specification.rb:823:in `block in each'
from /usr/share/ruby/vendor_ruby/2.0/rubygems/specification.rb:822:in `each'
from /usr/share/ruby/vendor_ruby/2.0/rubygems/specification.rb:822:in `each'
from /usr/share/ruby/vendor_ruby/2.0/rubygems/core_ext/kernel_require.rb:67:in `find'
from /usr/share/ruby/vendor_ruby/2.0/rubygems/core_ext/kernel_require.rb:67:in `require'
from /usr/local/share/ruby/gems/2.0/gems/bundler-1.13.1/lib/bundler.rb:11:in `<top (required)>'
from /usr/share/ruby/vendor_ruby/2.0/rubygems/core_ext/kernel_require.rb:135:in `require'
from /usr/share/ruby/vendor_ruby/2.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
from /usr/share/ruby/vendor_ruby/2.0/rubygems/core_ext/kernel_require.rb:144:in `require'
from /usr/local/share/ruby/gems/2.0/gems/jekyll-3.2.1/lib/jekyll/plugin_manager.rb:34:in `require_from_bundler'
from /usr/local/share/ruby/gems/2.0/gems/jekyll-3.2.1/exe/jekyll:9:in `<top (required)>'
from /usr/local/bin/jekyll:23:in `load'
from /usr/local/bin/jekyll:23:in `<main>'
I am running Ruby version 2.2. My server is Amazon Linux AMI. Let me know if there is any other information needed to answer the question!
I ended up figuring this out. Apparently I was missing a javascript environment. Steps:
sudo rm -r Gemfile.lock
nano Gemfile. Add gem 'therubyracer'. Save and exit
bundle install
bundle exec jekyll build
This fixed the problem for me!
I ran into the same issue. This happens when you haven't initialized bundler and jekyll dependencies.
To fix this,
Go to root directory containing your jekyll files
Run jekyll new . --force. This will initialize the current folder with bundler and jekyll dependencies
Now run the server using bundler exec jekyll serve
jekyll new . --force works like git init for a new git repository. See the documentation for more information

'Jekyll Serve' Error

I'm trying to run my jekyll site locally but when executing the command:
jekyll serve
I receive the following error message:
bhavik-imac:dhokes.github.io bhavikdhokia$ jekyll serve
Configuration file: /Users/bhavikdhokia/Development/git/dhokes.github.io/_config.yml
/Users/bhavikdhokia/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- jekyll-sitemap (LoadError)
from /Users/bhavikdhokia/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/bhavikdhokia/.rvm/gems/ruby-2.2.1/gems/jekyll-2.5.3/lib/jekyll/plugin_manager.rb:29:in `block in require_gems'
from /Users/bhavikdhokia/.rvm/gems/ruby-2.2.1/gems/jekyll-2.5.3/lib/jekyll/plugin_manager.rb:26:in `each'
from /Users/bhavikdhokia/.rvm/gems/ruby-2.2.1/gems/jekyll-2.5.3/lib/jekyll/plugin_manager.rb:26:in `require_gems'
from /Users/bhavikdhokia/.rvm/gems/ruby-2.2.1/gems/jekyll-2.5.3/lib/jekyll/plugin_manager.rb:19:in `conscientious_require'
from /Users/bhavikdhokia/.rvm/gems/ruby-2.2.1/gems/jekyll-2.5.3/lib/jekyll/site.rb:79:in `setup'
from /Users/bhavikdhokia/.rvm/gems/ruby-2.2.1/gems/jekyll-2.5.3/lib/jekyll/site.rb:41:in `initialize'
from /Users/bhavikdhokia/.rvm/gems/ruby-2.2.1/gems/jekyll-2.5.3/lib/jekyll/commands/build.rb:29:in `new'
from /Users/bhavikdhokia/.rvm/gems/ruby-2.2.1/gems/jekyll-2.5.3/lib/jekyll/commands/build.rb:29:in `process'
from /Users/bhavikdhokia/.rvm/gems/ruby-2.2.1/gems/jekyll-2.5.3/lib/jekyll/commands/serve.rb:26:in `block (2 levels) in init_with_program'
from /Users/bhavikdhokia/.rvm/gems/ruby-2.2.1#global/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:in `call'
from /Users/bhavikdhokia/.rvm/gems/ruby-2.2.1#global/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:in `block in execute'
from /Users/bhavikdhokia/.rvm/gems/ruby-2.2.1#global/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:in `each'
from /Users/bhavikdhokia/.rvm/gems/ruby-2.2.1#global/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:in `execute'
from /Users/bhavikdhokia/.rvm/gems/ruby-2.2.1#global/gems/mercenary-0.3.5/lib/mercenary/program.rb:42:in `go'
from /Users/bhavikdhokia/.rvm/gems/ruby-2.2.1#global/gems/mercenary-0.3.5/lib/mercenary.rb:19:in `program'
from /Users/bhavikdhokia/.rvm/gems/ruby-2.2.1/gems/jekyll-2.5.3/bin/jekyll:20:in `<top (required)>'
from /Users/bhavikdhokia/.rvm/gems/ruby-2.2.1/bin/jekyll:23:in `load'
from /Users/bhavikdhokia/.rvm/gems/ruby-2.2.1/bin/jekyll:23:in `<main>'
from /Users/bhavikdhokia/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
from /Users/bhavikdhokia/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'
Any suggestions as to why this is and how to resolve this?
Seems like you have to install jekyll-sitemap Try to install it by gem install jekyll-sitemap.
For people Googling this problem, also try bundle update if you're using bundle.

rack unable to locate thin - load error

$ /usr/bin/rackup -s thin -o 0.0.0.0 -p 4000 config.ru
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:126:in `require': cannot load such file -- thin (LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:126:in `require'
from /Library/Ruby/Gems/2.0.0/gems/rack-1.6.0/lib/rack/handler/thin.rb:1:in `<top (required)>'
from /Library/Ruby/Gems/2.0.0/gems/rack-1.6.0/lib/rack/handler.rb:20:in `const_get'
from /Library/Ruby/Gems/2.0.0/gems/rack-1.6.0/lib/rack/handler.rb:20:in `block in get'
from /Library/Ruby/Gems/2.0.0/gems/rack-1.6.0/lib/rack/handler.rb:20:in `each'
from /Library/Ruby/Gems/2.0.0/gems/rack-1.6.0/lib/rack/handler.rb:20:in `inject'
from /Library/Ruby/Gems/2.0.0/gems/rack-1.6.0/lib/rack/handler.rb:20:in `get'
from /Library/Ruby/Gems/2.0.0/gems/rack-1.6.0/lib/rack/server.rb:290:in `server'
from /Library/Ruby/Gems/2.0.0/gems/rack-1.6.0/lib/rack/server.rb:214:in `block in logging_middleware'
from /Library/Ruby/Gems/2.0.0/gems/rack-1.6.0/lib/rack/server.rb:327:in `call'
from /Library/Ruby/Gems/2.0.0/gems/rack-1.6.0/lib/rack/server.rb:327:in `block in build_app'
from /Library/Ruby/Gems/2.0.0/gems/rack-1.6.0/lib/rack/server.rb:326:in `reverse_each'
from /Library/Ruby/Gems/2.0.0/gems/rack-1.6.0/lib/rack/server.rb:326:in `build_app'
from /Library/Ruby/Gems/2.0.0/gems/rack-1.6.0/lib/rack/server.rb:336:in `wrapped_app'
from /Library/Ruby/Gems/2.0.0/gems/rack-1.6.0/lib/rack/server.rb:272:in `start'
from /Library/Ruby/Gems/2.0.0/gems/rack-1.6.0/lib/rack/server.rb:147:in `start'
from /Library/Ruby/Gems/2.0.0/gems/rack-1.6.0/bin/rackup:4:in `<top (required)>'
from /usr/bin/rackup:23:in `load'
from /usr/bin/rackup:23:in `<main>'
I have thin ( gem install thin ) at : /Users/user25/.rbenv/shims/thin
where am i going wrong ? I tried to provide the absolute path to rackup but to no avail.
Did you run rbenv rehash after you installed the gem? You need to rehash whenever you add new shims.

How to rackup a config file from outside the root directory?

When I run rackup from within my app directory, it works fine:
walkraft#li234-166:~/discourse$ rackup config.ru
Flushing redis (development mode)
/home/walkraft/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `block in require': iconv will be deprecated in the future, use String#encode instead.
/home/walkraft/discourse/vendor/gems/message_bus/lib/message_bus.rb:130: warning: already initialized constant ENCODE_SITE_TOKEN
>> Thin web server (v1.5.0 codename Knife)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:9292, CTRL+C to stop
However, if I try running rackup from outside this directory:
walkraft#li234-166:~$ rackup discourse/config.ru
/home/walkraft/discourse/config/application.rb:7:in `require': cannot load such file -- ./lib/discourse_plugin_registry (LoadError)
from /home/walkraft/discourse/config/application.rb:7:in `<top (required)>'
from /home/walkraft/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /home/walkraft/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /home/walkraft/discourse/config/environment.rb:2:in `<top (required)>'
from /home/walkraft/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /home/walkraft/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /home/walkraft/discourse/config.ru:2:in `block in <main>'
from /home/walkraft/.rvm/gems/ruby-1.9.3-p374/gems/rack-1.4.4/lib/rack/builder.rb:51:in `instance_eval'
from /home/walkraft/.rvm/gems/ruby-1.9.3-p374/gems/rack-1.4.4/lib/rack/builder.rb:51:in `initialize'
from /home/walkraft/discourse/config.ru:in `new'
from /home/walkraft/discourse/config.ru:in `<main>'
from /home/walkraft/.rvm/gems/ruby-1.9.3-p374/gems/rack-1.4.4/lib/rack/builder.rb:40:in `eval'
from /home/walkraft/.rvm/gems/ruby-1.9.3-p374/gems/rack-1.4.4/lib/rack/builder.rb:40:in `parse_file'
from /home/walkraft/.rvm/gems/ruby-1.9.3-p374/gems/rack-1.4.4/lib/rack/server.rb:200:in `app'
from /home/walkraft/.rvm/gems/ruby-1.9.3-p374/gems/rack-1.4.4/lib/rack/server.rb:304:in `wrapped_app'
from /home/walkraft/.rvm/gems/ruby-1.9.3-p374/gems/rack-1.4.4/lib/rack/server.rb:254:in `start'
from /home/walkraft/.rvm/gems/ruby-1.9.3-p374/gems/rack-1.4.4/lib/rack/server.rb:137:in `start'
from /home/walkraft/.rvm/gems/ruby-1.9.3-p374/gems/rack-1.4.4/bin/rackup:4:in `<top (required)>'
from /home/walkraft/.rvm/gems/ruby-1.9.3-p374/bin/rackup:19:in `load'
from /home/walkraft/.rvm/gems/ruby-1.9.3-p374/bin/rackup:19:in `<main>'
from /home/walkraft/.rvm/gems/ruby-1.9.3-p374/bin/ruby_noexec_wrapper:14:in `eval'
from /home/walkraft/.rvm/gems/ruby-1.9.3-p374/bin/ruby_noexec_wrapper:14:in `<main>'
How can I run rackup when I'm not inside of the root directory?
If you don't want to manually cd to the Discourse root folder, then why not just add a fix to the rackup config.ru file:
# Insert as first line in config.ru
Dir.chdir(File.dirname(File.expand_path(__FILE__)))
Actually, it's not a problem with rackup; it's a problem with your code.
You have
require './lib/discourse_plugin_registry'
somewhere. This is not ideal. It should rather be something like:
require File.expand_path('../../lib/discourse_plugin_registry', __FILE__)
The way you have it, it uses the current directory explicitly, and no matter what you do to rackup, until you change the current directory - it won't work.

Resources