How can I force git to NOT replace folder contents?

67 views Asked by At

I host my php project on cloudcontrol.com , in my project I have a static folder where I save user profile pictures in, like so :

uploads/profile/userpic1.jpg
uploads/profile/userpic2.jpg
uploads/profile/userpic2.jpg

I .gitignore all files inside profile folder with .gitignore file:

*
!.gitignore

in my local environment, when I make some testing I upload some pics inside that folder. In my production environment, Users also change their profile pictures and save them in that folder.

My problem is:

Whenever I push any updates to the production server, I lost all files inside profile directory on the server!! It seems like git (or cloudcontrol) REPLACE the profile directory not just update its contents without touching the old files/pictures .

Any advice how can I fix this. I thought it was just an .gitignore problem, and i did everything to make this work but I couldn't. I'm kind of a new to Git and PaaS stuff .

Thank you

2

There are 2 answers

1
poke On BEST ANSWER

cloudControl, like most cloud application hosters, replace the full application folder when it’s being deployed. This is usually done to allow horizontal scaling and to ensure that every deployment is based on the same (empty) state.

See also the documentation on the non-persistent filesystem:

Non-Persistent Filesystem

TL;DR:

  • Each container has its own filesystem.
  • The filesystem is not persistent.
  • Don't store uploads on the filesystem.

Deployments on the cloudControl platform have access to a writable filesystem. This filesystem however is not persistent. Data written may or may not be accessible again in future requests, depending on how the routing tier routes requests across available containers, and is deleted after each deploy. This does include deploys you trigger manually, but also re-deploys done by the platform itself during normal operation.

For customer uploads (e.g. user profile pictures) we recommend object stores like Amazon S3 or the GridFS feature available as part of the MongoLab Add-on.

So if you want to store files dynamically, you will have to look into a separate solution for that.

3
turntwo On

That's how most deployment apps using git works. In any case, git is not best suited for versioning assets, it should be mainly used for code. Having said that, you can still utilize .gitignore as long as you have a clear identifier between the content you want versioned and those you don't want versioned. Say all your own files all start with the word version you can do something like this

/public/assets/images/users/*
!/public/assets/images/users/version*