How do deploy web app with git without having to chown the app directory on every deploy?How to keep git from changing file ownershipHow can I add an empty directory to a Git repository?How do I clear my local working directory in git?How to have git log show filenames like svn log -vHow to convert existing non-empty directory into a Git working directory and push files to a remote repositoryHow can I delete all Git branches which have been merged?How to remove a directory from git repository?How do I ignore files in a directory in Git?Git push error: Unable to unlink old (Permission denied)Git checkout map destinationgit pull or git checkout to deploy

Why was the small council so happy for Tyrion to become the Master of Coin?

whey we use polarized capacitor?

How to add power-LED to my small amplifier?

Why CLRS example on residual networks does not follows its formula?

Email Account under attack (really) - anything I can do?

Example of a relative pronoun

Can I make popcorn with any corn?

"You are your self first supporter", a more proper way to say it

How much RAM could one put in a typical 80386 setup?

Prevent a directory in /tmp from being deleted

DOS, create pipe for stdin/stdout of command.com(or 4dos.com) in C or Batch?

Why is "Reports" in sentence down without "The"

Infinite past with a beginning?

black dwarf stars and dark matter

What do you call something that goes against the spirit of the law, but is legal when interpreting the law to the letter?

Circuitry of TV splitters

I see my dog run

When blogging recipes, how can I support both readers who want the narrative/journey and ones who want the printer-friendly recipe?

I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine

Could a US political party gain complete control over the government by removing checks & balances?

How can the DM most effectively choose 1 out of an odd number of players to be targeted by an attack or effect?

TGV timetables / schedules?

Is there really no realistic way for a skeleton monster to move around without magic?

Is Social Media Science Fiction?



How do deploy web app with git without having to chown the app directory on every deploy?


How to keep git from changing file ownershipHow can I add an empty directory to a Git repository?How do I clear my local working directory in git?How to have git log show filenames like svn log -vHow to convert existing non-empty directory into a Git working directory and push files to a remote repositoryHow can I delete all Git branches which have been merged?How to remove a directory from git repository?How do I ignore files in a directory in Git?Git push error: Unable to unlink old (Permission denied)Git checkout map destinationgit pull or git checkout to deploy






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















What's a good way to use git for deployment and now have to "chown -R" the whole app directory to the www user every time I deploy?



Basically I want to deploy using a post receive hook. Currently I have a post-receive hook that looks something like this:



#!/bin/sh
git --work-tree=/home/www/my-web-app --git-dir=/home/john/repo/my-web-app.git checkout -f
sudo chown -R www:www /home/www/my-web-app
sudo /home/john/scripts/reload-my-web-app.sh


It works, but the problem is that the chown step is slow, because there are millions of files in the my-web-app folder.



I thought I'd get around the problem using git as user www, so that the checked out files already have the correct owner. So I changed the so that the git line in the post-receive hook to:



sudo -u www git --work-tree=/home/www/my-web-app --git-dir=/home/john/repo/my-web-app.git checkout -f


But this doesn't work because I get a permission error about not being able to write the index.lock file in the git repo. Obviously user www doesn't have permission to write in the git repo, and I don't want to give www that permission because it seems like it would be unfavorable for the server security.



So, what's an elegant solution in this situation? Would you checkout to a temp directory, and then rsync from the temp directory to the /home/www/my-web-app directory so that you copy the files and change the owner at the same time? I feel like there must be some simple solution that I'm missing.










share|improve this question




























    1















    What's a good way to use git for deployment and now have to "chown -R" the whole app directory to the www user every time I deploy?



    Basically I want to deploy using a post receive hook. Currently I have a post-receive hook that looks something like this:



    #!/bin/sh
    git --work-tree=/home/www/my-web-app --git-dir=/home/john/repo/my-web-app.git checkout -f
    sudo chown -R www:www /home/www/my-web-app
    sudo /home/john/scripts/reload-my-web-app.sh


    It works, but the problem is that the chown step is slow, because there are millions of files in the my-web-app folder.



    I thought I'd get around the problem using git as user www, so that the checked out files already have the correct owner. So I changed the so that the git line in the post-receive hook to:



    sudo -u www git --work-tree=/home/www/my-web-app --git-dir=/home/john/repo/my-web-app.git checkout -f


    But this doesn't work because I get a permission error about not being able to write the index.lock file in the git repo. Obviously user www doesn't have permission to write in the git repo, and I don't want to give www that permission because it seems like it would be unfavorable for the server security.



    So, what's an elegant solution in this situation? Would you checkout to a temp directory, and then rsync from the temp directory to the /home/www/my-web-app directory so that you copy the files and change the owner at the same time? I feel like there must be some simple solution that I'm missing.










    share|improve this question
























      1












      1








      1


      1






      What's a good way to use git for deployment and now have to "chown -R" the whole app directory to the www user every time I deploy?



      Basically I want to deploy using a post receive hook. Currently I have a post-receive hook that looks something like this:



      #!/bin/sh
      git --work-tree=/home/www/my-web-app --git-dir=/home/john/repo/my-web-app.git checkout -f
      sudo chown -R www:www /home/www/my-web-app
      sudo /home/john/scripts/reload-my-web-app.sh


      It works, but the problem is that the chown step is slow, because there are millions of files in the my-web-app folder.



      I thought I'd get around the problem using git as user www, so that the checked out files already have the correct owner. So I changed the so that the git line in the post-receive hook to:



      sudo -u www git --work-tree=/home/www/my-web-app --git-dir=/home/john/repo/my-web-app.git checkout -f


      But this doesn't work because I get a permission error about not being able to write the index.lock file in the git repo. Obviously user www doesn't have permission to write in the git repo, and I don't want to give www that permission because it seems like it would be unfavorable for the server security.



      So, what's an elegant solution in this situation? Would you checkout to a temp directory, and then rsync from the temp directory to the /home/www/my-web-app directory so that you copy the files and change the owner at the same time? I feel like there must be some simple solution that I'm missing.










      share|improve this question














      What's a good way to use git for deployment and now have to "chown -R" the whole app directory to the www user every time I deploy?



      Basically I want to deploy using a post receive hook. Currently I have a post-receive hook that looks something like this:



      #!/bin/sh
      git --work-tree=/home/www/my-web-app --git-dir=/home/john/repo/my-web-app.git checkout -f
      sudo chown -R www:www /home/www/my-web-app
      sudo /home/john/scripts/reload-my-web-app.sh


      It works, but the problem is that the chown step is slow, because there are millions of files in the my-web-app folder.



      I thought I'd get around the problem using git as user www, so that the checked out files already have the correct owner. So I changed the so that the git line in the post-receive hook to:



      sudo -u www git --work-tree=/home/www/my-web-app --git-dir=/home/john/repo/my-web-app.git checkout -f


      But this doesn't work because I get a permission error about not being able to write the index.lock file in the git repo. Obviously user www doesn't have permission to write in the git repo, and I don't want to give www that permission because it seems like it would be unfavorable for the server security.



      So, what's an elegant solution in this situation? Would you checkout to a temp directory, and then rsync from the temp directory to the /home/www/my-web-app directory so that you copy the files and change the owner at the same time? I feel like there must be some simple solution that I'm missing.







      git web-deployment






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 22:06









      toby-onetoby-one

      826




      826






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Considering Git is not a deployment tool, your rsync might be a better solution.



          But check if setting the group is enough in your case, with a setgid on your my-web-app folder, as explained here. That might avoid the need to chown the files.






          share|improve this answer























          • Thank you - setgid looks like a good option. My plan is now to chmod g+s+w /home/www/my-web-app That way the files that git checks out will belong to group www (thanks to g+s), and when the web app is running as user www data it will be able to write/delete files in the my-web-app directory (thanks to g+w). And I can get rid of the chown line in the post-receive hook.

            – toby-one
            Mar 8 at 16:00











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55053560%2fhow-do-deploy-web-app-with-git-without-having-to-chown-the-app-directory-on-ever%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Considering Git is not a deployment tool, your rsync might be a better solution.



          But check if setting the group is enough in your case, with a setgid on your my-web-app folder, as explained here. That might avoid the need to chown the files.






          share|improve this answer























          • Thank you - setgid looks like a good option. My plan is now to chmod g+s+w /home/www/my-web-app That way the files that git checks out will belong to group www (thanks to g+s), and when the web app is running as user www data it will be able to write/delete files in the my-web-app directory (thanks to g+w). And I can get rid of the chown line in the post-receive hook.

            – toby-one
            Mar 8 at 16:00















          0














          Considering Git is not a deployment tool, your rsync might be a better solution.



          But check if setting the group is enough in your case, with a setgid on your my-web-app folder, as explained here. That might avoid the need to chown the files.






          share|improve this answer























          • Thank you - setgid looks like a good option. My plan is now to chmod g+s+w /home/www/my-web-app That way the files that git checks out will belong to group www (thanks to g+s), and when the web app is running as user www data it will be able to write/delete files in the my-web-app directory (thanks to g+w). And I can get rid of the chown line in the post-receive hook.

            – toby-one
            Mar 8 at 16:00













          0












          0








          0







          Considering Git is not a deployment tool, your rsync might be a better solution.



          But check if setting the group is enough in your case, with a setgid on your my-web-app folder, as explained here. That might avoid the need to chown the files.






          share|improve this answer













          Considering Git is not a deployment tool, your rsync might be a better solution.



          But check if setting the group is enough in your case, with a setgid on your my-web-app folder, as explained here. That might avoid the need to chown the files.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 8 at 6:06









          VonCVonC

          853k30127173281




          853k30127173281












          • Thank you - setgid looks like a good option. My plan is now to chmod g+s+w /home/www/my-web-app That way the files that git checks out will belong to group www (thanks to g+s), and when the web app is running as user www data it will be able to write/delete files in the my-web-app directory (thanks to g+w). And I can get rid of the chown line in the post-receive hook.

            – toby-one
            Mar 8 at 16:00

















          • Thank you - setgid looks like a good option. My plan is now to chmod g+s+w /home/www/my-web-app That way the files that git checks out will belong to group www (thanks to g+s), and when the web app is running as user www data it will be able to write/delete files in the my-web-app directory (thanks to g+w). And I can get rid of the chown line in the post-receive hook.

            – toby-one
            Mar 8 at 16:00
















          Thank you - setgid looks like a good option. My plan is now to chmod g+s+w /home/www/my-web-app That way the files that git checks out will belong to group www (thanks to g+s), and when the web app is running as user www data it will be able to write/delete files in the my-web-app directory (thanks to g+w). And I can get rid of the chown line in the post-receive hook.

          – toby-one
          Mar 8 at 16:00





          Thank you - setgid looks like a good option. My plan is now to chmod g+s+w /home/www/my-web-app That way the files that git checks out will belong to group www (thanks to g+s), and when the web app is running as user www data it will be able to write/delete files in the my-web-app directory (thanks to g+w). And I can get rid of the chown line in the post-receive hook.

          – toby-one
          Mar 8 at 16:00



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55053560%2fhow-do-deploy-web-app-with-git-without-having-to-chown-the-app-directory-on-ever%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          1928 у кіно

          Захаров Федір Захарович

          Ель Греко