kaytrance
kaytrance

Reputation: 2757

Folder gets emptied upon deployment to heroku via git push

I have a nodejs project on my local pc. Inside there is a books folder where books are being written (when working on production server) as files.

I put my code to production server (on heroku) via git push heroku master. I also added a .gitignore file to books directory with the following content for git to ignore any files/folders in this books directory:

!.gitignore

In my mind this pattern should tell git not to overwrite books folder content on production server upon next git push, but make sure that the folder itself exists (because it exist on local machine and is empty).

People working with production server make some books, which are then saved as files to books/ directory.

The problem is that when I do a git push heroku master on my local machine, the content of books directory on server still being deleted.

I have 2 reasons why this happens:

  1. heroku automatically cleans all files before pushing
  2. If not (1), then I still cannot write .gitignore correctly.

Any advises to to force books folder on heroku production server not loose its content upon next git push heroku master?

Upvotes: 0

Views: 55

Answers (1)

Chris
Chris

Reputation: 136918

Missing books

This has nothing to do with your Git ignores (though they appear to be wrong, see below).

Like most PaaS providers, Heroku does not provide a persistent filesystem. Anything you write to disk will be lost each time you deploy.

One popular option recommended by Heroku is to store uploaded files on Amazon S3.

.gitignore patterns

To get Git to ignore files in the books/ directory, something like this in a root .gitignore should do the trick:

/books/*

Unless you've got other ignores that you aren't sharing with us, your current rule just says not to ignore the books/.gitignore, but nowhere does it say to ignore the rest of the files in that directory.

The most common method I've seen for keeping "empty" directories in Git is to add an empty .gitkeep file to them.

Upvotes: 2

Related Questions