1

We have a PHP server with WordPress project on /var/www/ location. Entire /www/ root is under source control in Git. So when I push new code it deploys immediately and we get new fresh code.

At some point we have use image building tool on server which generates images from some data we put that in some package like.

/var/www/images/*.png

So I successfully generate image on that location; but when I add new changes and deploy again git removes all these png files from package.

I tired to add this to git ignore but that didn't help solve the problem.

Nick Volynkin
  • 14,023
  • 6
  • 43
  • 67
Amit Rana
  • 1,117
  • 1
  • 10
  • 32

1 Answers1

1

if I generate image on that location I get the image but when I add new changes and deploy again git remove this all png files from package.

If depends on how the deployment is done (Git 2.3+ has a push to deploy, for instance).
Usually, this is a post-receive hook, which does a

git --work-tree=/path/to/deploy checkout -f -- .

The issue is with the -f/--force option from git checkout:

When switching branches, proceed even if the index or the working tree differs from HEAD. This is used to throw away local changes.

One solution is to:

  • make sure to generate the png in a folder outside /path/to/deploy
  • restore a symlink to that outside folder after the git checkout -f

That means the post-receive hook would look like:

git --work-tree=/path/to/deploy checkout -f -- .
ln -s /path/to/pngs /path/to/deploy/png 
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Entire www/ package is deploying... And if I manage to set image out side / www/ than not able to access those images from web server. ...if have any idea in that direction let me know – Amit Rana Jun 09 '15 at 07:05
  • @AmitRana the symlink will restore the access. It will make those images seen be the server as if they are in `www/`. – VonC Jun 09 '15 at 07:06
  • @AmitRana but at least, with the symlink option, a checkout -f only wipes out that symlink, not the images. Restoring the symlink is easy. Restoring the wiped ouy images is not. – VonC Jun 09 '15 at 07:08