Deploy Ubuntu 18.04 Bionic Beaver Discussion
I am wondering if there is a variant toturial for the Puma, Nginx and Capistrano setup? Is Puma a less viable app server for production? Can we invoke a small discussion on this?
Something I'll probably add a some point soon now that Puma ships with Rails by default.
Puma is great too, but this tutorial is intended for beginners and Puma requires you to setup, run, manage, and monitor a separate process on the server independent of NGINX. It's just a lot less beginner friendly in production so that's why Passenger is the default. It's much easier to get up and running to learn the ropes and once you've done it successfully you can swap over to Puma if you like.
Hello Chris,
it's the first time I'm trying to deploy an app on a server.
for the moment i have 2 problems.
first, optionnal: I don't have secrets.yml, secrets.yml.example and database.yml.example in my rails app. Do I have to create them and if yes what do I put in my secrets.yml (On the other hand, I have credentials.yml.enc and master.key)
secondly, i'm at the first deploy step and every time i run "cap production deploy" that stop at "git:check" with this message :
git@git.laguil.de: Permission denied (publickey,password).
01 fatal: Could not read from remote repository.
01
01 Please make sure you have the correct access rights
01 and the repository exists.
I had, beforedeploying, generate a pair of key in the sudo user on the server, I had add this public key to the deploy key section of my repo git. I tried to clone the repo on the server but I have the same message. but on local no problem. Do you have an idea of what I did wrong (I look for a solution on google, I try change the git address and several other things since one day). Did I miss something.
And of course thank you very much, Chris, for this article.
Hey Glory!
Sounds like your server can't authenticate with your git repo. There are two options for this.
- You can add SSH keys on your server. Take the public key from the server and add it as a deploy key on your git repo.
- Let Capistrano forward your development machine's ssh key to the server and use it to clone your git repo.
I usually use #2.
They outline a bunch of details of this here in the Capistrano docs: https://capistranorb.com/documentation/getting-started/authentication-and-authorisation/
Also, don't worry about secrets.yml. You'll need to symlink master.key on your server though so it can decrypt credentials. You'll go into the shared folder, and create the master.key file and then add it to the list of files to symlink every deploy. That should be all you need for that since the credentials.yml.enc is already stored in your git repo.
Hello Chris,
thanks for your answer.
About secrets.yml, I found it.
About git it's exactly the problem. Since the begin I did #1 but as I say that did not work.
So perhaps I've forgoten to do something, or I don't no what. So to be sur i'm going to delete the server and restart all from the beginning. I don't really understand the #2 for git authentication on my server, but I'm going to read the docs you send me, I hope that will works this time.
Thank you again for your work.
Even I am newbie... can you elaborate what do you mean by "shared folder", and create the master.key file and then add it to the list of files to symlink every deploy.. 2ndly I want to know, is it not possible to deploy simply copying our project folder to ec2 instance and run rails env=production? instead so many steps.... Sorry in advance, if it is a baseless question... Can you please clarify about secretkey, masterkey and credentials.. which one to use...
Hello,
Thanks for this nice tuto !
I follow instructions but finally I have a problem on cap production deploy.
Seems to upload from git perfectly but problem with bundle install :
*Your bundle only supports platforms ["x86-mingw32"] but your local platforms are
["ruby", "x86_64-linux"], and there's no compatible match between those two
lists.
*
Can you help me ?
Thanks
Follow steps mentioned in the below link, hope it solves
Soo close to deploying... stuck on capistrano... feeling like giving up on it all.. any help is appreciated.
https://gist.github.com/excid3/d951a3770ccda4c6b6b86b9fae4ba97e
I am seeing an odd error (at least odd to me, and I have spent a good portion of the day trying to figure this out to no avail:
I run on local: cap production deploy
Deployment starts, but at deploy:migrate, I have an issue:
00:31 deploy:migrate
[deploy:migrate] Run `rake db:migrate`
00:31 deploy:migrating
01 $HOME/.rbenv/bin/rbenv exec bundle exec rake db:migrate
01 rake aborted!
01 PG::ConnectionBad: could not connect to server: Connection refused
01 Is the server running on host "165.227.190.133" and accepting
01 TCP/IP connections on port 5432?
...
...
#<Thread:0x00007fc18a23b8a8@/Users/BryanBeshore/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /Users/BryanBeshore/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/Users/BryanBeshore/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as deploy@165.227.190.133: rake exit status: 1 (SSHKit::Runner::ExecuteError)
rake stdout: Nothing written
rake stderr: rake aborted!
PG::ConnectionBad: could not connect to server: Connection refused
Is the server running on host "165.227.190.133" and accepting
TCP/IP connections on port 5432?
UPDATE:
Ok. I am ... an idiot unless I have 5-cups of coffee in me and I take breaks after 10+hrs staring at a computer monitor.
I had two setups for the following when I should have only had one. One was directed to: myapp (literal) and myapp (my actual app). And I directed the IP to my actual IP address instead of 127.0.0.1
nano ~/myapp/.rbenv-vars
It's saying your Postgres server isn't running, or it can't connect to it through the IP and port. Double check your connection settings and that Postgres is running.
Thanks a lot for this.
just one thing beyond this,
I added sidekiq, now how can I start it and and hanlde auto restart on die etc things?
I have problem with yarn I do not load the files js of my application I made this change in the environments / production.rb config.assets.js_compressor = Uglifier.new (harmony: true)
config.assets.compile = true
so that I compiled the app I do not know what else to do me I get this warning back when I'm doing the deploy
01 warning "@rails/webpacker > postcss-cssnext@3.1.0" has unmet peer dependency "caniuse-lite@^1.0.30000697".
01 warning " > webpack-dev-server@2.11.2" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0".
01 warning "webpack-dev-server > webpack-dev-middleware@1.12.2" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0".
01 [4/4] Building fresh packages...
Hello Chris
I have this error:
FATAL: password authentication failed for user "deploy"
How is database.yml configured?
I had an interesting thing happen after following this. The instructions were PERFECT because I could not get Nginx or Apache to work with Puma on the production server after from DigitalOcean. So thank you very much for this guide!
Now I have an interesting issue. After successfully going through this guide, I tried running 'rails s' locally and kept getting the error: (erb):18:in fetch': key not found: "DATABASE_USER" (KeyError)
I thought that was strange, because it looks like it's trying to use my production database values rather than the development. I did confirm in my puma.rb file that it's set for the development environment.
I tried commenting out my DB username and pw fields as shown below but I was still getting the same error.
Here's my database.yml file:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: postgresql
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
<<: *default
database: db/development
username: seth
password:
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test
production:
adapter: postgresql
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
#username: <%= ENV.fetch("DATABASE_USER") %>
#password: <%= ENV.fetch("DATABASE_PW") %>
database: consumer_law
For now I've just deleted the username and password lines from the file and I'm able to successfully run 'rails s' and get Puma working locally again. It does explicitly show in the startup output that it's set to use the development environment settings.
Any ideas why it's trying to use my production username and password fields in development?
FYI the answer is because all environment variables get loaded, even if it's not in that environment. You're better off using the secrets.yml for easier credential management.
Hello Chris,
passenger-config restart-app /home/deploy/testbootstrap --ignore-app-not-running
There are no Phusion Passenger-served applications running whose paths begin with '/home/deploy/testbootstrap'.`
I keep getting this error when I deploy and my site is not accessible through my IP address. It pops up a 404 NOT FOUND.
First of all, thank you for the guide.
Question to you about Passenger setup. I'm running Ubuntu 18.04 and did everything like this guide said, but i keep getting an error that *** ERROR: Phusion Passenger doesn't seem to be running. If you are sure that it
Error occurs when cap is running a command to restart Phusion Passenger.
Anyone else ran into this issue?
Update Sorry, my fault - for some reason, i commented out a line in passenger conf file where you add rbenv line, and that was messing it up for me. Anyways, thank you again for the guide :)
hello cris good day, I tell you my problem, I'm following all the steps to do the question until step 4 all right but at the time of deploy I jump an error
NameError: uninitialized constant Dotenv
https://gist.github.com/JoseCed/664ad2516d034605cb8d31705a2795c2
I need help, please
Here are some links and tips I found helpful while setting up the production server. Feel free to add to this by commenting below or suggest any edits:
- Refer to this link to understand how to set up a Rails server on 18.04: https://gorails.com/deploy/ubuntu/18.04
- Refer to this link if you get a
packet_write wait
orbroken_pipe
error: https://www.digitalocean.com/community/questions/why-am-i-getting-packet_write_wait-connection-to-xxx-xx-xx-xxx-port-22-broken-pipe?answer=41458 This error usually comes up when you are installing Ruby on the production server and the client thinks the server is inactive. - Make sure
database.yml
,secrets.yml
,application.yml
files are created manually on the server (in theshared
folder) - Edit
nginx /etc/nginx/sites-enabled/app-name
file and make sure it points to the correct directory. Refer to this link: https://www.digitalocean.com/community/tutorials/how-to-move-an-nginx-web-root-to-a-new-location-on-ubuntu-18-04 - Make sure MySQL privileges are provided to the deploy user
If you are using GitLab, you'll need to generate SSH public and secret keys on the server and then add the public key to the GitLab user settings.
The steps to do that are as follows:su deploy
ssh-keygen -t rsa -b 2048
- Press
ENTER
thrice cat /home/<user-name>/.ssh/id_rsa.pub
to obtain the SSH key- Navigate to: https://gitlab.com/profile/keys and paste your key there
- You should be able to use Capistrano with GitLab now (as long as you have followed all the other instructions in the main article and setup deploy.rb correctly)
Make sure production secret key is set (this can be generated locally using
rails secret
) and then added to thesecrets.yml
file in the production server
Hi, thank you for your interest, but the problem remains the same.
NameError: uninitialized constant Dotenv
when i deploy my rails app to VPS then always appear
[deploy:migrate] Run
rake db:migrate
00:37 deploy:migrating
01 $HOME/.rbenv/bin/rbenv exec bundle exec rake db:migrate
01 config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:
01
01 * development - set it to false
01 * test - set it to false (unless you use a tool that preloads your test environment)
01 * production - set it to true
01
but the config/environments/*.rb already set same to above
Thank you very much I have the online project, now I have a question if I create a migration when you run cap production deploy will the migration in production run?
and on the other hand someone could help me on how to run a seed.rb in production.
regards
I keep getting the following error when I am making changes:
[2019-06-29T14:18:13.234079 #2060] DEBUG -- : ^[[1m^[[36mActiveRecord::InternalMetadata Load (0.2ms)^[[0m ^[[1m^[[34mSELECT `ar_internal_metadata`.* FROM `ar_internal_metad
ata` WHERE `ar_internal_metadata`.`key` = 'environment' LIMIT 1^[[0m
D, [2019-06-29T14:18:13.237139 #2060] DEBUG -- : ^[[1m^[[35m (0.1ms)^[[0m ^[[1m^[[34mSELECT RELEASE_LOCK('3070706570978732700')^[[0m
Everything will deploy fine and the app will work well but when I create datamigrations, this error pops up. I'm using MySQL on both development and production. I can't find anything on Stackoverflow/Google Searches that has helped so I'm hoping someone here has experience in this matter.
Have you checked the table to see if the 'environment' key has been set? This is a fail-safe for Rails apps to make sure that you aren't wiping out a production database by accident.
I had some problems to make it works, but after some trys, I did :)
(I'm so proud rs)
So, I create many Droplet on Digitalocean to do got this, and in my last try I installed the rails using gem install rails
and every thing works fine.