Capistrano - deployment Rails app to Staging
I have a Rails app on production and I want to deploy my app to Staging using Capistrano
before I roll out to production so my team has made a copy of the application on different host which is supposed to act as Staging. I have 2 separate Capistrano environment setups, one for production, the other one for staging. They actually differ by the IP address of the server, the rest is the same standard setup.
I have also added config/evironments/staging.rb
file which is very similar to config.environments/production.rb
with the only difference in
config.action_controller.asset_host
because on Staging I need to load assets from the staging host.
config/environments/production.rb
config.action_controller.asset_host = "my_production_host"
config/environments/staging.rb
config.action_controller.asset_host = "my_staging_host"
but after I do bundle exec cap staging deploy
and inspect the browser console I can see an error 404 Failed to load resource
and it points to the production host assets for some reason.
404 Failed to load resource
<link rel="stylesheet" media="all" href="https://my_prduction_host/assets/application-7d22d41de3a16146e566368364a8b2c769a9ebd68d1333e71d624250fa2fd187.css" />
so it seems it does not read my config/environments/staging.rb
.
config/deploy/staging.rb
server "1.2.3.4", user: "my_user", roles: %w{app db web}, port: 50022
set :stage, :staging
set :rails_env, :staging
Capistrano logs shows current release: current (production)
config/environments/staging.rb
is added to the repo, so why is it not reading my staging configuration? What am I missing? Any idea why it is running the app in production mode?
UPDATE
ruby-on-rails capistrano
add a comment |
I have a Rails app on production and I want to deploy my app to Staging using Capistrano
before I roll out to production so my team has made a copy of the application on different host which is supposed to act as Staging. I have 2 separate Capistrano environment setups, one for production, the other one for staging. They actually differ by the IP address of the server, the rest is the same standard setup.
I have also added config/evironments/staging.rb
file which is very similar to config.environments/production.rb
with the only difference in
config.action_controller.asset_host
because on Staging I need to load assets from the staging host.
config/environments/production.rb
config.action_controller.asset_host = "my_production_host"
config/environments/staging.rb
config.action_controller.asset_host = "my_staging_host"
but after I do bundle exec cap staging deploy
and inspect the browser console I can see an error 404 Failed to load resource
and it points to the production host assets for some reason.
404 Failed to load resource
<link rel="stylesheet" media="all" href="https://my_prduction_host/assets/application-7d22d41de3a16146e566368364a8b2c769a9ebd68d1333e71d624250fa2fd187.css" />
so it seems it does not read my config/environments/staging.rb
.
config/deploy/staging.rb
server "1.2.3.4", user: "my_user", roles: %w{app db web}, port: 50022
set :stage, :staging
set :rails_env, :staging
Capistrano logs shows current release: current (production)
config/environments/staging.rb
is added to the repo, so why is it not reading my staging configuration? What am I missing? Any idea why it is running the app in production mode?
UPDATE
ruby-on-rails capistrano
what server you are use? Unicorn? Puma? Can you add full capistrano deploy log?
– igor_rb
Nov 25 '18 at 20:06
I am using Passenger + Nginx. I'd rather not paste the deploy log as it contains sensitive information, such as IP addresses, etc. but they clearly say that the app is run in production mode for some reason.
– jedi
Nov 25 '18 at 20:16
check passenger_app_env value. More info here: phusionpassenger.com/library/config/nginx/reference/…Passenger sets the default value to production.
– igor_rb
Nov 26 '18 at 6:26
Nowhere in any nginx config file do I seepassenger_app_env
var
– jedi
Nov 26 '18 at 9:22
set it to staging in you nginx config file.
– igor_rb
Nov 26 '18 at 9:32
add a comment |
I have a Rails app on production and I want to deploy my app to Staging using Capistrano
before I roll out to production so my team has made a copy of the application on different host which is supposed to act as Staging. I have 2 separate Capistrano environment setups, one for production, the other one for staging. They actually differ by the IP address of the server, the rest is the same standard setup.
I have also added config/evironments/staging.rb
file which is very similar to config.environments/production.rb
with the only difference in
config.action_controller.asset_host
because on Staging I need to load assets from the staging host.
config/environments/production.rb
config.action_controller.asset_host = "my_production_host"
config/environments/staging.rb
config.action_controller.asset_host = "my_staging_host"
but after I do bundle exec cap staging deploy
and inspect the browser console I can see an error 404 Failed to load resource
and it points to the production host assets for some reason.
404 Failed to load resource
<link rel="stylesheet" media="all" href="https://my_prduction_host/assets/application-7d22d41de3a16146e566368364a8b2c769a9ebd68d1333e71d624250fa2fd187.css" />
so it seems it does not read my config/environments/staging.rb
.
config/deploy/staging.rb
server "1.2.3.4", user: "my_user", roles: %w{app db web}, port: 50022
set :stage, :staging
set :rails_env, :staging
Capistrano logs shows current release: current (production)
config/environments/staging.rb
is added to the repo, so why is it not reading my staging configuration? What am I missing? Any idea why it is running the app in production mode?
UPDATE
ruby-on-rails capistrano
I have a Rails app on production and I want to deploy my app to Staging using Capistrano
before I roll out to production so my team has made a copy of the application on different host which is supposed to act as Staging. I have 2 separate Capistrano environment setups, one for production, the other one for staging. They actually differ by the IP address of the server, the rest is the same standard setup.
I have also added config/evironments/staging.rb
file which is very similar to config.environments/production.rb
with the only difference in
config.action_controller.asset_host
because on Staging I need to load assets from the staging host.
config/environments/production.rb
config.action_controller.asset_host = "my_production_host"
config/environments/staging.rb
config.action_controller.asset_host = "my_staging_host"
but after I do bundle exec cap staging deploy
and inspect the browser console I can see an error 404 Failed to load resource
and it points to the production host assets for some reason.
404 Failed to load resource
<link rel="stylesheet" media="all" href="https://my_prduction_host/assets/application-7d22d41de3a16146e566368364a8b2c769a9ebd68d1333e71d624250fa2fd187.css" />
so it seems it does not read my config/environments/staging.rb
.
config/deploy/staging.rb
server "1.2.3.4", user: "my_user", roles: %w{app db web}, port: 50022
set :stage, :staging
set :rails_env, :staging
Capistrano logs shows current release: current (production)
config/environments/staging.rb
is added to the repo, so why is it not reading my staging configuration? What am I missing? Any idea why it is running the app in production mode?
UPDATE
ruby-on-rails capistrano
ruby-on-rails capistrano
edited Nov 25 '18 at 20:11
jedi
asked Nov 25 '18 at 19:19
jedijedi
577420
577420
what server you are use? Unicorn? Puma? Can you add full capistrano deploy log?
– igor_rb
Nov 25 '18 at 20:06
I am using Passenger + Nginx. I'd rather not paste the deploy log as it contains sensitive information, such as IP addresses, etc. but they clearly say that the app is run in production mode for some reason.
– jedi
Nov 25 '18 at 20:16
check passenger_app_env value. More info here: phusionpassenger.com/library/config/nginx/reference/…Passenger sets the default value to production.
– igor_rb
Nov 26 '18 at 6:26
Nowhere in any nginx config file do I seepassenger_app_env
var
– jedi
Nov 26 '18 at 9:22
set it to staging in you nginx config file.
– igor_rb
Nov 26 '18 at 9:32
add a comment |
what server you are use? Unicorn? Puma? Can you add full capistrano deploy log?
– igor_rb
Nov 25 '18 at 20:06
I am using Passenger + Nginx. I'd rather not paste the deploy log as it contains sensitive information, such as IP addresses, etc. but they clearly say that the app is run in production mode for some reason.
– jedi
Nov 25 '18 at 20:16
check passenger_app_env value. More info here: phusionpassenger.com/library/config/nginx/reference/…Passenger sets the default value to production.
– igor_rb
Nov 26 '18 at 6:26
Nowhere in any nginx config file do I seepassenger_app_env
var
– jedi
Nov 26 '18 at 9:22
set it to staging in you nginx config file.
– igor_rb
Nov 26 '18 at 9:32
what server you are use? Unicorn? Puma? Can you add full capistrano deploy log?
– igor_rb
Nov 25 '18 at 20:06
what server you are use? Unicorn? Puma? Can you add full capistrano deploy log?
– igor_rb
Nov 25 '18 at 20:06
I am using Passenger + Nginx. I'd rather not paste the deploy log as it contains sensitive information, such as IP addresses, etc. but they clearly say that the app is run in production mode for some reason.
– jedi
Nov 25 '18 at 20:16
I am using Passenger + Nginx. I'd rather not paste the deploy log as it contains sensitive information, such as IP addresses, etc. but they clearly say that the app is run in production mode for some reason.
– jedi
Nov 25 '18 at 20:16
check passenger_app_env value. More info here: phusionpassenger.com/library/config/nginx/reference/…
Passenger sets the default value to production.
– igor_rb
Nov 26 '18 at 6:26
check passenger_app_env value. More info here: phusionpassenger.com/library/config/nginx/reference/…
Passenger sets the default value to production.
– igor_rb
Nov 26 '18 at 6:26
Nowhere in any nginx config file do I see
passenger_app_env
var– jedi
Nov 26 '18 at 9:22
Nowhere in any nginx config file do I see
passenger_app_env
var– jedi
Nov 26 '18 at 9:22
set it to staging in you nginx config file.
– igor_rb
Nov 26 '18 at 9:32
set it to staging in you nginx config file.
– igor_rb
Nov 26 '18 at 9:32
add a comment |
3 Answers
3
active
oldest
votes
You should add RAILS_ENV environment variable on you staging sever. See here for more info: https://askubuntu.com/a/58828/369247
To set variable only for current shell:
VARNAME="my value"
To set it for current shell and all processes started from current shell:
export VARNAME="my value" # shorter, less portable version
To set it permanently for all future bash sessions add such line to your .bashrc file in your $HOME directory.
That didn't work. Besides, Capistrano doesn't mention that RAILS_ENV should be set manually. They actually say to set it in deploy/#{environment}.rb file.
– jedi
Nov 25 '18 at 19:48
add a comment |
I have figured it out. I had to add rails_env staging;
to /etc/nginx/sites-available/my_site
and restart Nginx.
add a comment |
Capistrano doesn't set the RAILS_ENV, you probably need to configure this at application-server level, e.g.:
root /home/www/public/app-name/current/public;
passenger_ruby /home/app-name/.rbenv/shims/ruby;
passenger_app_env staging;
passenger_enabled on;
(this here is a Passenger+nginx config, but similar settings will exist for other apps)
Here passenger_app_env
tells Passenger to load the app in using the staging environment.
This didn't work. It broke the app completely, actually. I got 502 error code after accessing the page after deployment.
– jedi
Nov 25 '18 at 19:48
Sorry to hear that it broke the app. Not sure what you did wrong, maybe you copied the paths without changing them to match your situation, but the line that is important,passenger_app_env staging;
, is equivalent torails_env staging;
, see: phusionpassenger.com/library/config/nginx/reference/…
– murb
Nov 27 '18 at 12:52
Yeah, it didn't work. What did work was rails_env staging; This is not the first time I've seen wrong documentation on Passenger site. Their whole tutorial on how to install nginx with passenger is compeltely wrong and does not work at all.
– jedi
Nov 28 '18 at 0:14
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53471011%2fcapistrano-deployment-rails-app-to-staging%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You should add RAILS_ENV environment variable on you staging sever. See here for more info: https://askubuntu.com/a/58828/369247
To set variable only for current shell:
VARNAME="my value"
To set it for current shell and all processes started from current shell:
export VARNAME="my value" # shorter, less portable version
To set it permanently for all future bash sessions add such line to your .bashrc file in your $HOME directory.
That didn't work. Besides, Capistrano doesn't mention that RAILS_ENV should be set manually. They actually say to set it in deploy/#{environment}.rb file.
– jedi
Nov 25 '18 at 19:48
add a comment |
You should add RAILS_ENV environment variable on you staging sever. See here for more info: https://askubuntu.com/a/58828/369247
To set variable only for current shell:
VARNAME="my value"
To set it for current shell and all processes started from current shell:
export VARNAME="my value" # shorter, less portable version
To set it permanently for all future bash sessions add such line to your .bashrc file in your $HOME directory.
That didn't work. Besides, Capistrano doesn't mention that RAILS_ENV should be set manually. They actually say to set it in deploy/#{environment}.rb file.
– jedi
Nov 25 '18 at 19:48
add a comment |
You should add RAILS_ENV environment variable on you staging sever. See here for more info: https://askubuntu.com/a/58828/369247
To set variable only for current shell:
VARNAME="my value"
To set it for current shell and all processes started from current shell:
export VARNAME="my value" # shorter, less portable version
To set it permanently for all future bash sessions add such line to your .bashrc file in your $HOME directory.
You should add RAILS_ENV environment variable on you staging sever. See here for more info: https://askubuntu.com/a/58828/369247
To set variable only for current shell:
VARNAME="my value"
To set it for current shell and all processes started from current shell:
export VARNAME="my value" # shorter, less portable version
To set it permanently for all future bash sessions add such line to your .bashrc file in your $HOME directory.
answered Nov 25 '18 at 19:42
igor_rbigor_rb
923627
923627
That didn't work. Besides, Capistrano doesn't mention that RAILS_ENV should be set manually. They actually say to set it in deploy/#{environment}.rb file.
– jedi
Nov 25 '18 at 19:48
add a comment |
That didn't work. Besides, Capistrano doesn't mention that RAILS_ENV should be set manually. They actually say to set it in deploy/#{environment}.rb file.
– jedi
Nov 25 '18 at 19:48
That didn't work. Besides, Capistrano doesn't mention that RAILS_ENV should be set manually. They actually say to set it in deploy/#{environment}.rb file.
– jedi
Nov 25 '18 at 19:48
That didn't work. Besides, Capistrano doesn't mention that RAILS_ENV should be set manually. They actually say to set it in deploy/#{environment}.rb file.
– jedi
Nov 25 '18 at 19:48
add a comment |
I have figured it out. I had to add rails_env staging;
to /etc/nginx/sites-available/my_site
and restart Nginx.
add a comment |
I have figured it out. I had to add rails_env staging;
to /etc/nginx/sites-available/my_site
and restart Nginx.
add a comment |
I have figured it out. I had to add rails_env staging;
to /etc/nginx/sites-available/my_site
and restart Nginx.
I have figured it out. I had to add rails_env staging;
to /etc/nginx/sites-available/my_site
and restart Nginx.
answered Nov 26 '18 at 11:57
jedijedi
577420
577420
add a comment |
add a comment |
Capistrano doesn't set the RAILS_ENV, you probably need to configure this at application-server level, e.g.:
root /home/www/public/app-name/current/public;
passenger_ruby /home/app-name/.rbenv/shims/ruby;
passenger_app_env staging;
passenger_enabled on;
(this here is a Passenger+nginx config, but similar settings will exist for other apps)
Here passenger_app_env
tells Passenger to load the app in using the staging environment.
This didn't work. It broke the app completely, actually. I got 502 error code after accessing the page after deployment.
– jedi
Nov 25 '18 at 19:48
Sorry to hear that it broke the app. Not sure what you did wrong, maybe you copied the paths without changing them to match your situation, but the line that is important,passenger_app_env staging;
, is equivalent torails_env staging;
, see: phusionpassenger.com/library/config/nginx/reference/…
– murb
Nov 27 '18 at 12:52
Yeah, it didn't work. What did work was rails_env staging; This is not the first time I've seen wrong documentation on Passenger site. Their whole tutorial on how to install nginx with passenger is compeltely wrong and does not work at all.
– jedi
Nov 28 '18 at 0:14
add a comment |
Capistrano doesn't set the RAILS_ENV, you probably need to configure this at application-server level, e.g.:
root /home/www/public/app-name/current/public;
passenger_ruby /home/app-name/.rbenv/shims/ruby;
passenger_app_env staging;
passenger_enabled on;
(this here is a Passenger+nginx config, but similar settings will exist for other apps)
Here passenger_app_env
tells Passenger to load the app in using the staging environment.
This didn't work. It broke the app completely, actually. I got 502 error code after accessing the page after deployment.
– jedi
Nov 25 '18 at 19:48
Sorry to hear that it broke the app. Not sure what you did wrong, maybe you copied the paths without changing them to match your situation, but the line that is important,passenger_app_env staging;
, is equivalent torails_env staging;
, see: phusionpassenger.com/library/config/nginx/reference/…
– murb
Nov 27 '18 at 12:52
Yeah, it didn't work. What did work was rails_env staging; This is not the first time I've seen wrong documentation on Passenger site. Their whole tutorial on how to install nginx with passenger is compeltely wrong and does not work at all.
– jedi
Nov 28 '18 at 0:14
add a comment |
Capistrano doesn't set the RAILS_ENV, you probably need to configure this at application-server level, e.g.:
root /home/www/public/app-name/current/public;
passenger_ruby /home/app-name/.rbenv/shims/ruby;
passenger_app_env staging;
passenger_enabled on;
(this here is a Passenger+nginx config, but similar settings will exist for other apps)
Here passenger_app_env
tells Passenger to load the app in using the staging environment.
Capistrano doesn't set the RAILS_ENV, you probably need to configure this at application-server level, e.g.:
root /home/www/public/app-name/current/public;
passenger_ruby /home/app-name/.rbenv/shims/ruby;
passenger_app_env staging;
passenger_enabled on;
(this here is a Passenger+nginx config, but similar settings will exist for other apps)
Here passenger_app_env
tells Passenger to load the app in using the staging environment.
edited Nov 27 '18 at 12:49
answered Nov 25 '18 at 19:35
murbmurb
788822
788822
This didn't work. It broke the app completely, actually. I got 502 error code after accessing the page after deployment.
– jedi
Nov 25 '18 at 19:48
Sorry to hear that it broke the app. Not sure what you did wrong, maybe you copied the paths without changing them to match your situation, but the line that is important,passenger_app_env staging;
, is equivalent torails_env staging;
, see: phusionpassenger.com/library/config/nginx/reference/…
– murb
Nov 27 '18 at 12:52
Yeah, it didn't work. What did work was rails_env staging; This is not the first time I've seen wrong documentation on Passenger site. Their whole tutorial on how to install nginx with passenger is compeltely wrong and does not work at all.
– jedi
Nov 28 '18 at 0:14
add a comment |
This didn't work. It broke the app completely, actually. I got 502 error code after accessing the page after deployment.
– jedi
Nov 25 '18 at 19:48
Sorry to hear that it broke the app. Not sure what you did wrong, maybe you copied the paths without changing them to match your situation, but the line that is important,passenger_app_env staging;
, is equivalent torails_env staging;
, see: phusionpassenger.com/library/config/nginx/reference/…
– murb
Nov 27 '18 at 12:52
Yeah, it didn't work. What did work was rails_env staging; This is not the first time I've seen wrong documentation on Passenger site. Their whole tutorial on how to install nginx with passenger is compeltely wrong and does not work at all.
– jedi
Nov 28 '18 at 0:14
This didn't work. It broke the app completely, actually. I got 502 error code after accessing the page after deployment.
– jedi
Nov 25 '18 at 19:48
This didn't work. It broke the app completely, actually. I got 502 error code after accessing the page after deployment.
– jedi
Nov 25 '18 at 19:48
Sorry to hear that it broke the app. Not sure what you did wrong, maybe you copied the paths without changing them to match your situation, but the line that is important,
passenger_app_env staging;
, is equivalent to rails_env staging;
, see: phusionpassenger.com/library/config/nginx/reference/…– murb
Nov 27 '18 at 12:52
Sorry to hear that it broke the app. Not sure what you did wrong, maybe you copied the paths without changing them to match your situation, but the line that is important,
passenger_app_env staging;
, is equivalent to rails_env staging;
, see: phusionpassenger.com/library/config/nginx/reference/…– murb
Nov 27 '18 at 12:52
Yeah, it didn't work. What did work was rails_env staging; This is not the first time I've seen wrong documentation on Passenger site. Their whole tutorial on how to install nginx with passenger is compeltely wrong and does not work at all.
– jedi
Nov 28 '18 at 0:14
Yeah, it didn't work. What did work was rails_env staging; This is not the first time I've seen wrong documentation on Passenger site. Their whole tutorial on how to install nginx with passenger is compeltely wrong and does not work at all.
– jedi
Nov 28 '18 at 0:14
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53471011%2fcapistrano-deployment-rails-app-to-staging%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
what server you are use? Unicorn? Puma? Can you add full capistrano deploy log?
– igor_rb
Nov 25 '18 at 20:06
I am using Passenger + Nginx. I'd rather not paste the deploy log as it contains sensitive information, such as IP addresses, etc. but they clearly say that the app is run in production mode for some reason.
– jedi
Nov 25 '18 at 20:16
check passenger_app_env value. More info here: phusionpassenger.com/library/config/nginx/reference/…
Passenger sets the default value to production.
– igor_rb
Nov 26 '18 at 6:26
Nowhere in any nginx config file do I see
passenger_app_env
var– jedi
Nov 26 '18 at 9:22
set it to staging in you nginx config file.
– igor_rb
Nov 26 '18 at 9:32