What does deploy_env do in Capistrano deploy script? - capistrano

In the Capistrano Multi-staging documentation set :deploy_env, 'production' is used. Is deploy_env the same as rails_env which tells Capistrano which environment to use when running the app/migrations?
If they are not the same, what does deploy_env do and how should it be used?

It appears to be a typo. See Issue #189 for capistrano gem on github. Use rails_env not deploy_env.

Related

Capistrano - how to disable git pull (Bitbucket pipelines)

I have deploy via bitbucket pipelines, which is uses Capistrano for deploy release to server. But there is one problem, Capistrano is pulling actual version of branch, but i need to deploy not actual branch, but version from pipeline(this need for redeploy previous stable version). And because in pipeline is already needed version of files, i just need to disable pulling if its possible.
Used ruby bundle for deploy.
Ruby: 2.5.5
Capistrano 3.8.0
Part of deploy.rb configuration:
set :repo_url, 'git#bitbucket.org:user/repo.git'
set :deploy_via, :remote_cache
set :copy_exclude, [ '.git' ]
set :pty, true
Thanks.
I was tried to replace git command for disable git pull with command:
replace_git_pull() {
if [ $1 = "pull" ]; then
echo "Git pull is disabled, exit";
return 0;
fi;
$(which git) "$#";
}
alias git='replace_git_pull'
Locally its works, but its doesn't have affect to Capistrano deploy, seems like Capistrano not uses console for pulling.
Tried replace git:update command, - receive error.
Deployment tool was changed to Deployer (php)
https://github.com/deployphp/deployer

Maintaining DJANGO_SETTINGS_MODULE between local and production environments

Running into an issue when we deployed to production, had to update manage.py to set os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local") to config.settings.production. Of course this broke local settings when we pulled back to our dev branch.
We're running our containers via the docker-compose local.yml commands recommended in the documentation.
Am I missing something? Is this by design?
This environment variable should be set via a .env file, the production one is located under .envs/.production/.django, and is not in source control (for security reasons). So yes, it is by design.
Depending on how you start your server, this file might be missing and the environment will end up unset.

Setting Environment with Puppet and test it with TravisCI

I want to use TravisCI for testing pull requests for my github repo. But i use puppet for setting environment and installing dependencies. Is there any way to build dependencies with puppet in .travis.yml.
You need to customize the build environment by writing a shell script that installs and runs puppet.

To do certain action after deployment

I am using capifony (it is capistrano for symfony) to deply.
I have to do some work after deployment such as changing access rights for some directories.
chmod 0777 test
For now I am doing this by manual operation.
Could I include this in my capifony deploy.rb?
Im not sure about capifony but if you put something like after 'deploy', 'sometask' in your capistrano deploy.rb file it is ran after deploy.
Here is the list of all the Capistrano deployment tasks. You can do a before or after for any of them.
Looks like this answer might help you.

How to deploy heroku app with secret yaml configuration file without committing the file?

In other rails projects, I'd have a local database.yml and in source code repository only commit the database.sample file. When deploying, a capistrano script that would symlink a shared version of database.yml to all the releases.
When deploying to heroku, git is used and they seem to override database.yml altogether and do something internal.
That's all fine and good for database.yml, but what if I have s3 configurations in config/s3.yml. And I'm putting my project on github so I don't want to commit the s3.yml where everyone can see my credentials. It'd rather commit a sample s3.sample which people will override with their own settings, and keep a local s3.yml file uncommitted in my working directory.
what is the best way to handle this?
Heroku have some guidance on this -
http://devcenter.heroku.com/articles/config-vars
An alternative solution is to create a new local-branch where you modify .gitignore so secret-file can be pushed to heroku.
DON'T push this branch to your Github repo.
To push non-master branch to heroku, use:
git push heroku secret-branch:master
More info can be found on:
https://devcenter.heroku.com/articles/multiple-environments#advanced-linking-local-branches-to-remote-apps
Use heroku run bash and then ls to check whether your secret-file have been pushed on to heroku or not
Store the s3 credentials in environment variables.
$ cd myapp
$ heroku config:add S3_KEY=8N029N81 S3_SECRET=9s83109d3+583493190
Adding config vars:
S3_KEY => 8N029N81
S3_SECRET => 9s83109d3+583493190
Restarting app...done.
In your app:
AWS::S3::Base.establish_connection!(
:access_key_id => ENV['S3_KEY'],
:secret_access_key => ENV['S3_SECRET']
)
See the Heroku Config Vars documentation which explain development setup etc.
If using Rails 4.1 beta, try the heroku_secrets gem, from https://github.com/alexpeattie/heroku_secrets:
gem 'heroku_secrets', github: 'alexpeattie/heroku_secrets'
This lets you store secret keys in Rails 4.1's config/secrets.yml (which is not checked in to source control) and then just run
rake heroku:secrets RAILS_ENV=production
to make its contents available to heroku (it parses your secrets.yml file and pushes everything in it to heroku as environment variables, per the heroku best practice docs).
You can also check out the Figaro gem.
I solved this by building the credentials from env variables during the build time, and write it to where I need it to be before the slug is created.
Some usecase specific info that you can probably translate to your situation:
I'm deploying a Node project, and in the package.json in the postinstall script I call "bash create-secret.sh". Since postinstall is performed before the slug is created, the file will be added to the slug.
I had to use a bash script because I had some trouble printing strings that contained newlines that had to be printed correctly, and I wasn't able to get it done with Node. Probably just me not being skilled enough, but maybe you run into a similar problem.
Looking into this with Heroku + Build & Deploy-time Secrets. It seems like it's not something Heroku supports. This means for a rails app, there is no way other than committing BUNDLE_GITHUB__COM for example to get from private repo.
I'll try to see if there is a way to have CI bundle private deps before beaming at heroku