keep config file on heroku but remove from public repo on github? - heroku

I am trying out newrelic on a test app which is deployed to heroku.
I have both remotes origin(the public github repo) and heroku.
After pushing to heroku with the newrelic.yml file included, I would like to be able to push changes back to origin but not include the newrelic.yml file because it contains a license_key.
I tried putting config/newrelic.yml in .gitignore but it still tracks the file and pushes the file to origin. Then I tried deleting the file but can't get a clean "git status".
I tried rm config/newrelic.yml but then even with it in .gitignore the next time I push to heroku it removes the file on heroku causing newrelic monitoring to stop.
I saw other similar issues on SO with answers referring to heroku config vars https://devcenter.heroku.com/articles/config-vars but don't understand how this relates if it does, to removing the config file for github.
Thanks

Heroku take all your files from Github, each push replace all your files by the new ones. I don't think you can do something like this.
If you put your file in the .gitignore, you won't be able to push it to Heroku.
A solution may be to use branch on Github, on the master you keep your code without the config file, and on the branch "Heroku", you add the file and use it to do the push on Heroku.

Related

Trouble setting up a laravel instance across servers using git

I am struggling with properly configuring a git workflow for a laravel project. I created the laravel project locally. At the base directory I used the git init command. Then connected the repository to the bitbucket repository set up by the company I am working for like so:
git remote add origin https://address/xyz.git
I then made some new changes to a few of the files. Did a commit and then pushed to origin like this:
git push -u origin master
Now I logged into our development box (which is not my local dev box). Built the laravel default laravel application and then tried to pull down the project specific files by connected the dev box's laravel directory to the same repository, but I keep getting the following error:
error: The following untracked working tree files would be overwritten by checkout:
.gitignore
composer.json
package.json
resources/js/app.js
resources/js/bootstrap.js
webpack.mix.js
Please move or remove them before you can switch branches.
I know I probably missed some simple step or did not set up the development box correctly, but I can't find this scenario in the documentation and I can't seem to discover what I did wrong. Can anyone help?
It sounds like the repository on the main development box has some local changes that are not checked into git. Run the command
git status
On the remote development box. This will tell you any local changes.
If you want to remove any local unchecked in changes you can type
git reset --hard (resets any tracked files)
git clean -Xdf (resets all untracked files)
If you want to preserve any local changes, you can type
git stash
git stash --pop (recovers the changes - this may induce some conflicts)
Thanks for listing those tools Ben W, but it turns out that I the wording of my question was deceptive. When I went to the second machine (the development box), I should have built the laravel instance by using the git clone command.
git clone https://address/xyz.git
What I did instead, was build another full instance of laravel and try to link it to the same repository I created from the first box (my local notebook).
I upvoted your answer anyhow Brad W. because those are all great tools to know. Thanks.

How to push certain commits only to Heroku but not github

I am using a github repository that is public and deploy my app on Heroku. How do I only push commits to Heroku and not to github when I then push to origin again?
More specifically, I need to edit a .env file for Heroku that I do not want to publish on Github. I did a few commits on that file and pushed it to heroku via git push heroku master.
I do not want those commits to be pushed to github as well. Now when I make new commits and push it via git push origin master, are the previous commits (which were only ment for Heroku) pushed as well? If yes, how do I avoid this?
A few things:
1) .env probably shouldn't be checked in. A common pattern is to create a .env.sample file with placeholder values, add .env to gitignore and instruct users to copy .env.sample to .env and populate the placeholder values for development.
2) Those sensitive values can be set in Heroku's environment on the CLI via heroku config:set FOO=bar and will be available to your app through: ENV['FOO']

How to clear heroku remote repository? [duplicate]

My heroku slug size is 389mb, so push is rejected. Now the Point is, if i deploy my same application on new domain (by using heroku create again), the slug size, i am seeing is just 200mb.. Why its different? Then I have tried this approach:
Approach 1: by deleting .git folder from my project directory, then again git init. and then deploying again on same heroku app.. It didn't make any differences!
Approach 2: By declaring .slugignore file in root of project folder. But its too not making any diff!
Approach 3: as per this site, https://github.com/heroku/heroku-repo
I have reset my repo like this,
heroku repo:reset -a appname
But, nothing happened!! What to do now? Can u guide me? Thnx.
As Heroku suggests:
Inspect your slug with heroku run bash and by using commands such as ls and du
Move large assets like PDFs or audio files to asset storage
Remove unneeded dependencies and exclude unnecessary files via .slugignore
Hey I was able to find the solution. Here is what i have done:
I have downloed Heroku Repo plugin from this site :https://github.com/heroku/heroku-repo just by this line:
heroku plugins:install https://github.com/heroku/heroku-repo.git
then I have just rebuilt my app by this command:
heroku repo:rebuild -a appname
This will empty the remote repository and push the repository up again, effectively triggering an app rebuild. and I got whole working app with original downsized (207mb) again. that's it.

GIt Deployment + Configuration Files + Heroku

I'm using Heroku to host a Rails app, which means using Git to deploy to Heroku. Because of the "pure Git workflow" on Heroku, anything that needs to go upstream to the server has to be configured identically on my local box.
However I need to have certain configuration files be different depending on whether I'm in the local setup or deployed on Heroku. Again, because of the deployment method Heroku uses I can't use .gitignore and a template (as I have seen suggested many times, and have used in other projects).
What I need is for git to somehow track changes on a file, but selectively tell git not to override certain files when pulling from a particular repo -- basically to make certain changes one-way only.
Can this be done? I'd appreciate any suggestions!
You can have config vars persistently stored ON each heroku app's local setup so they do not have to be in your code at all! so the same code can run on multiple heroku sites but with different configuration. It very simple, easy, elegant...
It's the approach we used. (We used it for the SAME thing... we have multiple clones of the SAME app at Heroku, but we want only ONE source at github, in our dev local directory we do the PUSH to ORIGIN (github), then when we have it the way we like it, we CD to the prod local directory, which goes to the SAME github repository, and we ONLY PULL from GITHUB into this directory, never push (eg, all pushes to github come from our dev directory, the prod directory is just a staging area for the other heroku app.)
By having the different configs ON the different HEROKU sites (as explained below), the EXACT SAME CODE works on BOTH heroku sites.
So our workflow is: (the key is that BOTH directories point to SAME github repo)
cd myDEVdir
*....develop away....*
git add .
git commit -am "another day, another push"
git push origin *(to our SINGLE github repo)*
git push heroku *(test it out on heroku #1)*
cd ../myPRODdir
git pull *(grabs SAME code as used on other site *)
git push heroku *(now the SAME code runs on Heroku #2)*
that's it!
Now here's how you keep your site-specific config vars ON the heroku site:
http://docs.heroku.com/config-vars
on your local command line, for EACH of your two local directories, do:
$ heroku config:add FIRST_CONFIGVAR=fooheroku1
Adding config vars:
FIRST_CONFIGVAR => fooheroku1
$ heroku config:add SECOND_CONFIGVAR=barheroku1
Adding config vars:
SECOND_CONFIGVAR => barheroku1
to see the ones you have defined:
$ heroku config
FIRST_CONFIGVAR => fooheroku1
SECOND_CONFIGVAR => barheroku1
then cd to your other directory myPRODdir and do the SAME thing, only set the same remote heroku vars to fooheroku2 and barheroku2.
then in your rails app you simple refer to them like so:
a = ENV['FIRST_CONFIGVAR']
One app will read 'fooheroku1' the other app will read 'fooheroku2'
And finally, on your LOCAL directory myDEVdir, where you run in DEV mode, put the same config commands in your config/environment/development.rb file your 'dev' version of the config vars will be set to whatever they should be:
ENV['FIRST_CONFIGVAR'] = "foodev"
ENV['SECOND_CONFIGVAR'] = "bardev"
Easy, elegant. Thanks, Heroku!
Here are a few solutions:
1) If you want to ignore files only on heroku, use slugignore
2) If your changes are minor, stay DRY and use universal config files, inserting switches for server-specific behavior
if Rails.env == "production"
#production server code
elsif Rails.env == "development"
#development server code
else
#test server code
end
3) If your changes are major, write one config file and add a "smudge file" to config/initializers for each additional server. Basically, you would have separate files using the technique in (2).
4) If your changes are SWEEPING (unlikely), then maintain separate branches for each server.
5) This script can do exactly what you requested, but may be overkill.
I hope that helped.

Using local configs in a Heroku deployment environment

I'm trying to migrate my app to Heroku - I have a config file that varies with development/staging/production environments as it contains uniquely assigned keys (from Facebook, S3, etc.), so I keep it out of the repository and keep the configs local.
As such I'm trying to find a solution for Heroku to have that config file since Heroku deploys from the repository. I noticed Heroku deploys from the master branch - can it deploy from another branch? Because then I could commit the Heroku configs there, and have it not overwrite the other environments' configs every time it pulls.
Thanks!
I believe Heroku always launches the master branch of the Gt repo, but they support config vars to address exactly this issue.
You can use foreman and heroku-config for this.
Check out the article at heroku dev center:
http://devcenter.heroku.com/articles/config-vars
I love this because you can keep the .env file in .gitignore and shield your production variables from ending up in the repository.

Resources