简体   繁体   中英

How can I opensource my code on git and maintain deploy scripts with proper config files?

I have an app being developed on github. I want to opensource it. Currently we use a capistrano script to deploy to our staging & production servers.

I am trying to figure out how we can put our config files in a separate repo, and still use capistrano to execute one touch deploys. The goal is that we can open up our repo for anyone to use.

You have some options.

  • Use environment variables: You can set environment variables at both your local and production machines. In your app you'll read these vars by doing: <%= ENV['my_var'] %> . Doing this you can commit your app to a public repo without worrying about expose sensitive information like passwords and keys. For example, set a db_password environment var to store your database password and in your database.yml you could read it doing: password: <%= ENV['db_password'] %>

  • You can use gems link dotenv ( https://github.com/bkeepers/dotenv ) or figaro ( https://github.com/laserlemon/figaro ): By using these gems you won't need to set environment variables manually on your machines, you will define them in a .env file instead. You'll be able to read them the same way using <%= ENV['my_var'] %> . You will have to ignore your .env files at your .gitignore and tell capistrano to create the environment variables at your production server reading from your .env file.

  • Another alternative would be make different config files for development and production and ignore them in your .gitignore. You can store your config production files in a different repo and have it updated on your machine at the time of your deploy. You'll just need to copy your config files from your local machine to the production server ( https://coderwall.com/p/wgs6gw/copy-local-files-to-remote-server-using-capistrano-3 ) after updating the app repo on your production server.

The last alternative is the one I use most (in my case I use ansible in place of capistrano).

If you wanna see an example I have an application and a deployment task currently running in production that you can checkout:

Hope I made myself clear and you got the idea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM