tombh / peas

Docker and Ruby based PaaS
GNU General Public License v2.0
601 stars 33 forks source link

Dockerfile(s) #3

Closed cameron closed 10 years ago

cameron commented 10 years ago

Would be great to make this easy to install :)

tombh commented 10 years ago

Absolutely! The only reason I haven't so far is because I've never tried the whole Docker in Docker thing. I know it's possible, just haven't got round to experimenting yet.

Primarily I want Peas to be hackable from a traditional bundle install. Then there are 2 reasons to build a Peas Docker image. 1) As you say, for ease of installation and local hacking and 2) I'd like to see Peas prioritise Docker as the main provider for distributing runtime nodes (or 'pods' as I'm going to call them). Therefore something like peas settings --provider docker then peas pods scale runtime=2 will create 2 new Docker containers that can have an arbitrary number of app containers in them. That way you can have a fully-fledged PaaS running on a single machine, which personally I believe is a massive plus point for ease of development.

DimShadoWWW commented 10 years ago

I'm trying to make Peas work into a Docker container, accessing docker from inside the container, but I have one problem: peas tried to read the machine uuid and fails.. this is the full backtrace:

Installing sidekiq-status 0.4.0
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
14:14:28 - INFO - Guard is using Libnotify to send notifications.
14:14:28 - INFO - Guard is using TerminalTitle to send notifications.
14:14:31 - INFO - Bundle already up-to-date
14:14:31 - INFO - Starting up sidekiq...
14:14:31 - INFO - bundle exec sidekiq --verbose --environment development --require ./config/sidekiq.rb --concurrency 5
14:14:31 - INFO - Guard::Puma will now start your app on port 4000 using development environment.
14:14:31 - INFO - Guard is now watching at '/var/www/peas'
14:14:31 - INFO - Stopping sidekiq...
14:14:31 - INFO - Stopped process sidekiq
process 600: D-Bus library appears to be incorrectly set up; failed to read machine uuid: Failed to open "/var/lib/dbus/machine-id": No such file or directory
See the manual page for dbus-uuidgen to correct this issue.
  D-Bus not built with -rdynamic so unable to print a backtrace
/opt/start_passenger: line 35:   600 Aborted                 bundle exec guard
tombh commented 10 years ago

@DimShadoWWW Progress at least! This just sounds like a base OS issue, probably just needs some apt package installed. What base Docker image are you using? Are you using a Dockerfile? When you come to needing to install buildstep (ie docker build progrium/buildstep) you'll need to have made yourself familiar with dind and perhaps read the Docker wiki about running containers inside containers.

EDIT: Brief googling suggests maybe apt-get install dbus-uuidgen and then dbus-uuidgen > /var/lib/dbus/machine-id. But my instinct tells me you shouldn't even need dbus and that I suspect that one of the development gems is responsible. Perhaps guard or rb-inotify?

DimShadoWWW commented 10 years ago

Hello, @tombh, sorry I didn't explain it well, these are the steps that I followed, using CoreOS and docker 0.9.0:

FROM mine/centos
ENV ROLE peas
RUN yum install -y gtkmm24-devel libnotify-devel
VOLUME ["/var/www/"]
ADD start_passenger /opt/start_passenger
CMD ["/bin/bash", "/opt/start_passenger"]

start_passenger:

set -e
source /usr/local/rvm/scripts/rvm
echo 'ruby-2.1.0' > /var/www/peas/.ruby-version
echo 'peas' > /var/www/peas/.ruby-gemset
cd /var/www/peas
cat > config/mongoid.yml <<-EOF
development:
  sessions:
    default:
      database: peas_dev
      hosts:
        - ${MONGODB_PORT_27017_TCP_ADDR}:${MONGODB_PORT_27017_TCP_PORT}
EOF
bundle install
bundle exec guard

I run the container with this command, checking the output:

docker run --name peas -privileged -v /var/run/docker.sock:/var/run/docker.sock -v /home/core/code/:/var/www/ -link redis:redis -link mongodb:mongodb shadow/peas
tombh commented 10 years ago

Ah! I see now. This is a clever setup, nice work :)

Okay there are few other things to address before the dbus issue. Firstly this isn't a Docker in Docker setup right? You're getting the docker command inside your Peas container to connect to the Docker daemon on your host machine, right? And also, your Mongo, Redis and Buildstep containers are running directly on your host machine as well? I like this. I'm sure others would much appreciate a documented or even scripted version of your setup and a PR for either would certainly be accepted.

May I ask why you're using Peas? Is it just to play around? I see you're using Passenger. Is that simply to run bundle exec guard? I'm just wondering that if you're thinking of heading more towards a production set up you might want to consider launching the Peas API (via the puma binary) and Sidekiq using something like (foreman)[https://github.com/ddollar/foreman].

The last thing and I think this most relates to your dbus issue, is that your using Centos, which I haven't tested on. I've only used Debian and Ubuntu so far. Did you see the edit to my previous comment?

EDIT: Brief googling suggests maybe apt-get install dbus-uuidgen and then dbus-uuidgen > /var/lib/dbus/machine-id. But my instinct tells me you shouldn't even need dbus and that I suspect that one of the development gems is responsible. Perhaps guard or rb-inotify?

Basically I think dbus should just be taken out of the whole equation somehow. You just need to figure out what's using it. I suspect it's guard wanting to send system notifications. In which case my suggestion of moving to something like foreman has more relevance.

DimShadoWWW commented 10 years ago

@tombh , I'm just playing around .. Well I followed your advices and make this changes:

source 'http://rubygems.org'

gem 'puma'
gem 'rack'
gem 'grape', github: 'intridea/grape'
gem 'grape-swagger'
gem 'mongoid', github: 'mongoid/mongoid'
gem 'sidekiq'
gem 'sidekiq-status'
gem 'foreman'
#!/bin/bash
# set -e
source /usr/local/rvm/scripts/rvm
if [[ -d /var/www/peas ]]
then
  cd /var/www/peas
  rm config/mongoid.yml
  git pull
else
  git clone https://github.com/tombh/peas.git /var/www/peas
fi

echo 'ruby-2.1.0' > /var/www/peas/.ruby-version
echo 'peas' > /var/www/peas/.ruby-gemset
cd /var/www/peas
cat > config/mongoid.yml <<-EOF
development:
  sessions:
    default:
      database: peas_dev
      hosts:
        - ${MONGODB_PORT_27017_TCP_ADDR}:${MONGODB_PORT_27017_TCP_PORT}
EOF
[[ -f Procfile ]] || cat > Procfile <<-EOF
web: bundle exec puma
sidekiq: bundle exec sidekiq -c 5 -e production -r . -C config/sidekiq.rb
EOF

bundle install
echo STARTING
export REDIS_PROVIDER="http://REDIS_PORT_8069_TCP_ADDR:REDIS_PORT_8069_TCP_PORT/1"
bundle exec foreman start

Now it tried to start, but failed with this output:

08:16:12 web.1     | started with pid 181
08:16:12 sidekiq.1 | started with pid 182
08:16:18 web.1     | Puma starting in single mode...
08:16:18 web.1     | * Version 2.8.1 (ruby 2.1.0-p0), codename: Sir Edmund Percival Hillary
08:16:18 web.1     | * Min threads: 0, max threads: 16
08:16:18 web.1     | * Environment: development
08:16:19 sidekiq.1 | (<unknown>): mapping values are not allowed in this context at line 14 column 60
08:16:19 sidekiq.1 | /usr/local/rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/psych.rb:369:in `parse'
08:16:19 sidekiq.1 | /usr/local/rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/psych.rb:369:in `parse_stream'
08:16:19 sidekiq.1 | /usr/local/rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/psych.rb:317:in `parse'
08:16:19 sidekiq.1 | /usr/local/rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/psych.rb:244:in `load'
08:16:19 sidekiq.1 | /usr/local/rvm/gems/ruby-2.1.0@peas/gems/sidekiq-2.17.7/lib/sidekiq/cli.rb:330:in `parse_config'
08:16:19 sidekiq.1 | /usr/local/rvm/gems/ruby-2.1.0@peas/gems/sidekiq-2.17.7/lib/sidekiq/cli.rb:185:in `setup_options'
08:16:19 sidekiq.1 | /usr/local/rvm/gems/ruby-2.1.0@peas/gems/sidekiq-2.17.7/lib/sidekiq/cli.rb:36:in `parse'
08:16:19 sidekiq.1 | /usr/local/rvm/gems/ruby-2.1.0@peas/gems/sidekiq-2.17.7/bin/sidekiq:7:in `<top (required)>'
08:16:19 sidekiq.1 | /usr/local/rvm/gems/ruby-2.1.0@peas/bin/sidekiq:23:in `load'
08:16:19 sidekiq.1 | /usr/local/rvm/gems/ruby-2.1.0@peas/bin/sidekiq:23:in `<main>'
08:16:19 sidekiq.1 | /usr/local/rvm/gems/ruby-2.1.0@peas/bin/ruby_executable_hooks:15:in `eval'
08:16:19 sidekiq.1 | /usr/local/rvm/gems/ruby-2.1.0@peas/bin/ruby_executable_hooks:15:in `<main>'
08:16:19 sidekiq.1 | exited with code 1
08:16:19 system    | sending SIGTERM to all processes
08:16:19 web.1     | ! Unable to load application
tombh commented 10 years ago

Nearly there! There are 2 errors in the final output, 1 from sidekiq and 1 from Puma.

There's currently no YAML config for Sidekiq so no need for the -C flag, it's all done through ./config/sidekiq.rb, so you need to specify that with the -r flag.

puma needs to know what app to run, I actually reckon rackup is the more natural way to do it.

So putting it all together your new Procfile should be:

web: bundle exec rackup -s Puma -p 4000
sidekiq: bundle exec sidekiq --verbose --environment production --require ./config/sidekiq.rb --concurrency 5
DimShadoWWW commented 10 years ago

it works now, but fails to get the redis connection that I specify exporting the variable REDIS_PROVIDER:

08:44:18 sidekiq.1 | 2014-04-08T12:44:18Z 177 TID-c8bko ERROR: Error connecting to Redis on 127.0.0.1:6379 (ECONNREFUSED)
08:44:18 sidekiq.1 | 2014-04-08T12:44:18Z 177 TID-c8bko ERROR: /usr/local/rvm/gems/ruby-2.1.0@peas/gems/redis-3.0.7/lib/redis/client.rb:290:in `rescue in establish_connection'
tombh commented 10 years ago

From what I can tell I think you just need to use REDIS_URL instead of REDIS_PROVIDER. There's some examples on the Sidekiq Wiki.

tombh commented 10 years ago

Right, we should have a working Docker installation method now: https://github.com/tombh/peas#docker Please let me know if it works for you.

And many thanks to @DimShadoWWW, your documented attempt helped significantly.

EDIT: BTW, I'm completely offline for the next week, sorry in advance for any slow replies.