How to keep files permission during gitlab auto deployment?











up vote
0
down vote

favorite












I am trying auto deploy branch from gitlab 11.06 to a staging server.Both gitlab server and staging server are centos 7.4



Below is the .gitlab-ci.yml:



stages:
- deploy
deploy_staging:
stage: deploy
tags:
- php
script:
/home/gitlab-runner/.local/bin/deploy.sh


deploy.sh as below:



#!/bin/bash
deploy_path="/var/www/html"
cd $deploy_path
git pull origin master


auto deploy works fine,but owner and permission of files changed.For example:



before auto deploy:
drwxr-xr-x 2 apache webadmin 77 Nov 19 8:41 phpmailer



After auto deploy:
drwxrwxr-x 2 gitlab-runner gitlab-runner 77 Nov 19 10:11 phpmailer



I need auto deploy,I need to keep files permisson too.

How to keep files permission during auto deployment?Thanks in advance for any solution!










share|improve this question
























  • Do you want to preserve ownership (apache/webadmin user/group) or permissions (drwxr-xr-x)? Or both?
    – phd
    Nov 20 at 15:13










  • @phd,both ownership and permissions.
    – kittygirl
    Nov 20 at 15:15















up vote
0
down vote

favorite












I am trying auto deploy branch from gitlab 11.06 to a staging server.Both gitlab server and staging server are centos 7.4



Below is the .gitlab-ci.yml:



stages:
- deploy
deploy_staging:
stage: deploy
tags:
- php
script:
/home/gitlab-runner/.local/bin/deploy.sh


deploy.sh as below:



#!/bin/bash
deploy_path="/var/www/html"
cd $deploy_path
git pull origin master


auto deploy works fine,but owner and permission of files changed.For example:



before auto deploy:
drwxr-xr-x 2 apache webadmin 77 Nov 19 8:41 phpmailer



After auto deploy:
drwxrwxr-x 2 gitlab-runner gitlab-runner 77 Nov 19 10:11 phpmailer



I need auto deploy,I need to keep files permisson too.

How to keep files permission during auto deployment?Thanks in advance for any solution!










share|improve this question
























  • Do you want to preserve ownership (apache/webadmin user/group) or permissions (drwxr-xr-x)? Or both?
    – phd
    Nov 20 at 15:13










  • @phd,both ownership and permissions.
    – kittygirl
    Nov 20 at 15:15













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am trying auto deploy branch from gitlab 11.06 to a staging server.Both gitlab server and staging server are centos 7.4



Below is the .gitlab-ci.yml:



stages:
- deploy
deploy_staging:
stage: deploy
tags:
- php
script:
/home/gitlab-runner/.local/bin/deploy.sh


deploy.sh as below:



#!/bin/bash
deploy_path="/var/www/html"
cd $deploy_path
git pull origin master


auto deploy works fine,but owner and permission of files changed.For example:



before auto deploy:
drwxr-xr-x 2 apache webadmin 77 Nov 19 8:41 phpmailer



After auto deploy:
drwxrwxr-x 2 gitlab-runner gitlab-runner 77 Nov 19 10:11 phpmailer



I need auto deploy,I need to keep files permisson too.

How to keep files permission during auto deployment?Thanks in advance for any solution!










share|improve this question















I am trying auto deploy branch from gitlab 11.06 to a staging server.Both gitlab server and staging server are centos 7.4



Below is the .gitlab-ci.yml:



stages:
- deploy
deploy_staging:
stage: deploy
tags:
- php
script:
/home/gitlab-runner/.local/bin/deploy.sh


deploy.sh as below:



#!/bin/bash
deploy_path="/var/www/html"
cd $deploy_path
git pull origin master


auto deploy works fine,but owner and permission of files changed.For example:



before auto deploy:
drwxr-xr-x 2 apache webadmin 77 Nov 19 8:41 phpmailer



After auto deploy:
drwxrwxr-x 2 gitlab-runner gitlab-runner 77 Nov 19 10:11 phpmailer



I need auto deploy,I need to keep files permisson too.

How to keep files permission during auto deployment?Thanks in advance for any solution!







git gitlab gitlab-ci gitlab-ci-runner






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 0:57

























asked Nov 19 at 17:01









kittygirl

270315




270315












  • Do you want to preserve ownership (apache/webadmin user/group) or permissions (drwxr-xr-x)? Or both?
    – phd
    Nov 20 at 15:13










  • @phd,both ownership and permissions.
    – kittygirl
    Nov 20 at 15:15


















  • Do you want to preserve ownership (apache/webadmin user/group) or permissions (drwxr-xr-x)? Or both?
    – phd
    Nov 20 at 15:13










  • @phd,both ownership and permissions.
    – kittygirl
    Nov 20 at 15:15
















Do you want to preserve ownership (apache/webadmin user/group) or permissions (drwxr-xr-x)? Or both?
– phd
Nov 20 at 15:13




Do you want to preserve ownership (apache/webadmin user/group) or permissions (drwxr-xr-x)? Or both?
– phd
Nov 20 at 15:13












@phd,both ownership and permissions.
– kittygirl
Nov 20 at 15:15




@phd,both ownership and permissions.
– kittygirl
Nov 20 at 15:15












1 Answer
1






active

oldest

votes

















up vote
0
down vote













git pull seems to replace files (it creates a new file and move it) instead of writing to existing files. Hence there is no way for it to preserve ownership — newly created files are created with the process ownership, gitlab-runner/gitlab-runner user/group. To fix that run git pull under different user using e.g., sudo. Either



sudo -u apache /home/gitlab-runner/.local/bin/deploy.sh


in the gitlab-ci.yml or



sudo -u apache git pull origin master


in the deploy.sh. Please don't forget that sudo asks for password so you have to configure it to run the command(s) without password.



To retain permissions try to set umask 055 in deploy.sh before running git pull.






share|improve this answer





















  • Ownership and permission are critical when I deploy to production server.Is there any solution to maintain complicated ownership and permission after auto deployment?
    – kittygirl
    Nov 20 at 15:42










  • Run sudo chown user.group file1 file2… to change ownership if you have complex ownership requirements.
    – phd
    Nov 20 at 15:45










  • ,sudo chown user.group file1 file2 in gitlab-ci.yml or in /home/gitlab-runner/.local/bin/deploy.sh?How can use gitlab-runner sudo root?
    – kittygirl
    Nov 22 at 13:18












  • ps.can I run setfacl in this post after git pull?
    – kittygirl
    Nov 22 at 14:07











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',
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%2f53379446%2fhow-to-keep-files-permission-during-gitlab-auto-deployment%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








up vote
0
down vote













git pull seems to replace files (it creates a new file and move it) instead of writing to existing files. Hence there is no way for it to preserve ownership — newly created files are created with the process ownership, gitlab-runner/gitlab-runner user/group. To fix that run git pull under different user using e.g., sudo. Either



sudo -u apache /home/gitlab-runner/.local/bin/deploy.sh


in the gitlab-ci.yml or



sudo -u apache git pull origin master


in the deploy.sh. Please don't forget that sudo asks for password so you have to configure it to run the command(s) without password.



To retain permissions try to set umask 055 in deploy.sh before running git pull.






share|improve this answer





















  • Ownership and permission are critical when I deploy to production server.Is there any solution to maintain complicated ownership and permission after auto deployment?
    – kittygirl
    Nov 20 at 15:42










  • Run sudo chown user.group file1 file2… to change ownership if you have complex ownership requirements.
    – phd
    Nov 20 at 15:45










  • ,sudo chown user.group file1 file2 in gitlab-ci.yml or in /home/gitlab-runner/.local/bin/deploy.sh?How can use gitlab-runner sudo root?
    – kittygirl
    Nov 22 at 13:18












  • ps.can I run setfacl in this post after git pull?
    – kittygirl
    Nov 22 at 14:07















up vote
0
down vote













git pull seems to replace files (it creates a new file and move it) instead of writing to existing files. Hence there is no way for it to preserve ownership — newly created files are created with the process ownership, gitlab-runner/gitlab-runner user/group. To fix that run git pull under different user using e.g., sudo. Either



sudo -u apache /home/gitlab-runner/.local/bin/deploy.sh


in the gitlab-ci.yml or



sudo -u apache git pull origin master


in the deploy.sh. Please don't forget that sudo asks for password so you have to configure it to run the command(s) without password.



To retain permissions try to set umask 055 in deploy.sh before running git pull.






share|improve this answer





















  • Ownership and permission are critical when I deploy to production server.Is there any solution to maintain complicated ownership and permission after auto deployment?
    – kittygirl
    Nov 20 at 15:42










  • Run sudo chown user.group file1 file2… to change ownership if you have complex ownership requirements.
    – phd
    Nov 20 at 15:45










  • ,sudo chown user.group file1 file2 in gitlab-ci.yml or in /home/gitlab-runner/.local/bin/deploy.sh?How can use gitlab-runner sudo root?
    – kittygirl
    Nov 22 at 13:18












  • ps.can I run setfacl in this post after git pull?
    – kittygirl
    Nov 22 at 14:07













up vote
0
down vote










up vote
0
down vote









git pull seems to replace files (it creates a new file and move it) instead of writing to existing files. Hence there is no way for it to preserve ownership — newly created files are created with the process ownership, gitlab-runner/gitlab-runner user/group. To fix that run git pull under different user using e.g., sudo. Either



sudo -u apache /home/gitlab-runner/.local/bin/deploy.sh


in the gitlab-ci.yml or



sudo -u apache git pull origin master


in the deploy.sh. Please don't forget that sudo asks for password so you have to configure it to run the command(s) without password.



To retain permissions try to set umask 055 in deploy.sh before running git pull.






share|improve this answer












git pull seems to replace files (it creates a new file and move it) instead of writing to existing files. Hence there is no way for it to preserve ownership — newly created files are created with the process ownership, gitlab-runner/gitlab-runner user/group. To fix that run git pull under different user using e.g., sudo. Either



sudo -u apache /home/gitlab-runner/.local/bin/deploy.sh


in the gitlab-ci.yml or



sudo -u apache git pull origin master


in the deploy.sh. Please don't forget that sudo asks for password so you have to configure it to run the command(s) without password.



To retain permissions try to set umask 055 in deploy.sh before running git pull.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 at 15:26









phd

19.6k42441




19.6k42441












  • Ownership and permission are critical when I deploy to production server.Is there any solution to maintain complicated ownership and permission after auto deployment?
    – kittygirl
    Nov 20 at 15:42










  • Run sudo chown user.group file1 file2… to change ownership if you have complex ownership requirements.
    – phd
    Nov 20 at 15:45










  • ,sudo chown user.group file1 file2 in gitlab-ci.yml or in /home/gitlab-runner/.local/bin/deploy.sh?How can use gitlab-runner sudo root?
    – kittygirl
    Nov 22 at 13:18












  • ps.can I run setfacl in this post after git pull?
    – kittygirl
    Nov 22 at 14:07


















  • Ownership and permission are critical when I deploy to production server.Is there any solution to maintain complicated ownership and permission after auto deployment?
    – kittygirl
    Nov 20 at 15:42










  • Run sudo chown user.group file1 file2… to change ownership if you have complex ownership requirements.
    – phd
    Nov 20 at 15:45










  • ,sudo chown user.group file1 file2 in gitlab-ci.yml or in /home/gitlab-runner/.local/bin/deploy.sh?How can use gitlab-runner sudo root?
    – kittygirl
    Nov 22 at 13:18












  • ps.can I run setfacl in this post after git pull?
    – kittygirl
    Nov 22 at 14:07
















Ownership and permission are critical when I deploy to production server.Is there any solution to maintain complicated ownership and permission after auto deployment?
– kittygirl
Nov 20 at 15:42




Ownership and permission are critical when I deploy to production server.Is there any solution to maintain complicated ownership and permission after auto deployment?
– kittygirl
Nov 20 at 15:42












Run sudo chown user.group file1 file2… to change ownership if you have complex ownership requirements.
– phd
Nov 20 at 15:45




Run sudo chown user.group file1 file2… to change ownership if you have complex ownership requirements.
– phd
Nov 20 at 15:45












,sudo chown user.group file1 file2 in gitlab-ci.yml or in /home/gitlab-runner/.local/bin/deploy.sh?How can use gitlab-runner sudo root?
– kittygirl
Nov 22 at 13:18






,sudo chown user.group file1 file2 in gitlab-ci.yml or in /home/gitlab-runner/.local/bin/deploy.sh?How can use gitlab-runner sudo root?
– kittygirl
Nov 22 at 13:18














ps.can I run setfacl in this post after git pull?
– kittygirl
Nov 22 at 14:07




ps.can I run setfacl in this post after git pull?
– kittygirl
Nov 22 at 14:07


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379446%2fhow-to-keep-files-permission-during-gitlab-auto-deployment%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

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python