Edouard Brèthes Edouard Brèthes - 5 months ago 30
Ruby Question

Deploying a rails 4.2 or above with AZK on Digital Ocean

I'm trying to deploy on DigitalOcean a Rails 4.2.1 app using AZK.

It works well locally on my mac, but i'm unable to deploy it. Problem seems to be related to gem with native extension, as the logs suggest :

azk: ✓ completed download of `azukiapp/ruby:2.3.0`

azk: ↻ provisioning `bodhi-server` system...
azk: ⎘ syncing files for `bodhi-server` system...
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
Fetching gem metadata from https://rubygems.org/............
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Installing rake 11.2.2
Installing i18n 0.7.0
Using json 1.8.3
Installing minitest 5.9.0
Installing thread_safe 0.3.5
Installing builder 3.2.2
Installing erubis 2.7.0
Installing mini_portile2 2.1.0
Installing pkg-config 1.1.7
Installing rack 1.6.4
Installing mime-types-data 3.2016.0521
Installing arel 6.0.3
Installing coffee-script-source 1.10.0
Installing execjs 2.7.0
Installing thor 0.19.1
Installing concurrent-ruby 1.0.2
Installing geokit 1.10.0
Using bundler 1.11.2
Installing multi_xml 0.5.5
Installing multi_json 1.12.1
Installing memcachier 0.0.2
Installing mono_logger 1.1.0
Installing newrelic_rpm 3.11.1.284
Installing pg 0.18.4 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory: /azk/bundler/ruby/2.3.0/gems/pg-0.18.4/ext
/usr/local/bin/ruby -r ./siteconf20160704-11-yekdkh.rb extconf.rb
Cannot allocate memory - /usr/local/bin/ruby -r ./siteconf20160704-11-yekdkh.rb extconf.rb 2>&1

Gem files will remain installed in /azk/bundler/ruby/2.3.0/gems/pg-0.18.4 for inspection.
Results logged to /azk/bundler/ruby/2.3.0/extensions/x86_64-linux/2.3.0-static/pg-0.18.4/gem_make.out
Installing puma 3.4.0 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory: /azk/bundler/ruby/2.3.0/gems/puma-3.4.0/ext/puma_http11
/usr/local/bin/ruby -r ./siteconf20160704-11-di2lvq.rb extconf.rb
Cannot allocate memory - /usr/local/bin/ruby -r ./siteconf20160704-11-di2lvq.rb extconf.rb 2>&1

Gem files will remain installed in /azk/bundler/ruby/2.3.0/gems/puma-3.4.0 for inspection.
Results logged to /azk/bundler/ruby/2.3.0/extensions/x86_64-linux/2.3.0-static/puma-3.4.0/gem_make.out
Installing redis 3.2.2
Installing tilt 2.0.5
Installing ruby-units 1.4.5
Installing sass 3.4.22
Installing timezone 0.4.3
Installing turbolinks-source 5.0.0
Installing rdoc 4.2.2
Installing tzinfo 1.2.2
/bin/bash: line 1: 11 Killed bundle install --path /azk/bundler
azk: An error occurred. It will stop all instances already running. See details below.

azk: Skip stoping, system `deploy` does not scale.
azk: ↓ stopping `postgres` system, 1 instances...
azk: System `worker` not running
azk: System `bodhi-server` not running
azk: Run `["/bin/bash","-c","(bundle install --path /azk/bundler && bundle exec rake db:create && bundle exec rake db:migrate RACK_ENV=production)"]` in system `bodhi-server` error:
azk: `See the back log`
azk: Sorry, an error has occurred.
azk: A crash report about this error will be sent to azk team in order to make azk better.
azk: Sending bug report to Azuki...
azk: Bug report was sent. Thanks.


Here is my Azkfile.js too :

/**
* Documentation: http://docs.azk.io/Azkfile.js
*/
// Adds the systems that shape your system
systems({
'bodhi-server': {
// Dependent systems
depends: ["postgres"],
// More images: http://images.azk.io
image: {"docker": "azukiapp/ruby:2.3.0"},
// Steps to execute before running instances
provision: [
"bundle install --path /azk/bundler",
"bundle exec rake db:create",
'bundle exec rake db:migrate RACK_ENV=production',
],
workdir: "/azk/#{manifest.dir}",
shell: "/bin/bash",
command: ["bundle", "exec", "rackup", "config.ru", "--pid", "/tmp/ruby.pid", "--port", "$HTTP_PORT", "--host", "0.0.0.0"],
wait: 20,
mounts: {
'/azk/#{manifest.dir}': sync("."),
'/azk/bundler': persistent("./bundler"),
'/azk/#{manifest.dir}/tmp': persistent("./tmp"),
'/azk/#{manifest.dir}/log': path("./log"),
'/azk/#{manifest.dir}/.bundle': path("./.bundle")
},
scalable: {"default": 1},
http: {
domains: [
'#{env.HOST_DOMAIN}', // used if deployed
'#{env.HOST_IP}', // used if deployed
'#{system.name}.#{azk.default_domain}', // default azk domain
]
},
ports: {
// exports global variables
http: "3000/tcp"
},
envs: {
// Make sure that the PORT value is the same as the one
// in ports/http below, and that it's also the same
// if you're setting it in a .env file
RUBY_ENV: "production",
RAILS_ENV: "production",
RACK_ENV: 'production',
WORKER_EMBEDDED: 'false',
WORKER_RETRY: 1,
BUNDLE_APP_CONFIG: '/azk/bundler',
APP_URL: '#{system.name}.#{azk.default_domain}',

}
},
worker: {
extends: 'bodhi-server',
command: ['bundle', 'exec', 'rake', 'resque:work'],
http: null,
ports: null
},
postgres: {
// Dependent systems
depends: [],
// More images: http://images.azk.io
image: {"docker": "azukiapp/postgres:9.4"},
shell: "/bin/bash",
wait: 150,
mounts: {
'/var/lib/postgresql/data': persistent("postgresql"),
'/var/log/postgresql': path("./log/postgresql")
},
ports: {
// exports global variables
data: "5432/tcp"
},
envs: {
// set instances variables
POSTGRES_USER: "azk",
POSTGRES_PASS: "azk",
POSTGRES_DB: "bodhi_production"
},
export_envs: {
// check this gist to configure your database
// https://gist.github.com/gullitmiranda/62082f2e47c364ef9617
DATABASE_URL: "postgres://#{envs.POSTGRES_USER}:#{envs.POSTGRES_PASS}@#{net.host}:#{net.port.data}/#{envs.POSTGRES_DB}",
DATABASE_NAME: '#{envs.POSTGRESQL_DB}',
DATABASE_USERNAME: '#{envs.POSTGRESQL_USER}',
DATABASE_PASSWORD: '#{envs.POSTGRESQL_PASS}',
DATABASE_HOST: '#{net.host}',
DATABASE_PORT: '#{net.port.data}'
}
},
deploy: {
image: {docker: 'azukiapp/deploy-digitalocean:0.0.7'},
mounts: {
'/azk/deploy/src': path('.'),
'/azk/deploy/.ssh': path('#{env.HOME}/.ssh'), // Required to connect with the remote server
'/azk/deploy/.config': persistent('deploy-config')
},
// This is not a server. Just run it with `azk deploy`
scalable: {default: 0, limit: 0},
envs: {
GIT_REF: 'azk',
AZK_RESTART_COMMAND: 'azk restart -Rvv',
BOX_NAME: 'bodhi-server',
BOX_SIZE: '512mb'
}
}
});


Again, am i the only one in that case ?

Answer

Edouard, the problem is the droplet ran out of memory while installing gems: ("Cannot allocate memory").

Try increasing the droplet size by doing:

  • Remove the droplet via DigitalOcean panel;
  • Change the deploy system in your Azkfile with the property: BOX_SIZE: '1gb';
  • azk deploy clear-cache (since you've removed the old droplet);
  • azk deploy.

Please let me know if this is enough to get your project up & running on DigitalOcean.

Comments