【问题标题】:How to keep files permission during gitlab auto deployment?gitlab自动部署期间如何保持文件权限?
【发布时间】:2018-11-19 17:01:50
【问题描述】:

我正在尝试将分支从 gitlab 11.06 自动部署到临时服务器。gitlab 服务器和临时服务器都是 centos 7.4

下面是.gitlab-ci.yml

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

deploy.sh如下:

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

自动部署工作正常,但文件的所有者和权限发生了变化。例如:

自动部署前:
drwxr-xr-x 2 apache webadmin 77 Nov 19 8:41 phpmailer

自动部署后:
drwxrwxr-x 2 gitlab-runner gitlab-runner 77 Nov 19 10:11 phpmailer

我需要自动部署,我也需要保留文件权限。
如何在自动部署期间保持文件权限?提前感谢任何解决方案!

【问题讨论】:

  • 您要保留所有权(apache/webadmin 用户/组)还是权限(drwxr-xr-x)?还是两者兼而有之?
  • @phd,所有权和权限。

标签: git gitlab gitlab-ci gitlab-ci-runner


【解决方案1】:

git pull 似乎替换文件(它创建一个新文件并移动它)而不是写入现有文件。因此,它无法保留所有权——新创建的文件是使用进程所有权创建的,gitlab-runner/gitlab-runner user/group。使用例如sudo 在不同的用户下修复运行git pull。要么

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

gitlab-ci.yml

sudo -u apache git pull origin master

deploy.sh。请不要忘记sudo 要求输入密码,因此您必须configure it 才能在没有密码的情况下运行命令。

要保留权限,请在运行git pull 之前尝试在deploy.sh 中设置umask 055

【讨论】:

  • 当我部署到生产服务器时,所有权和权限至关重要。有没有什么解决方案可以在自动部署后维护复杂的所有权和权限?
  • 如果您有复杂的所有权要求,请运行 sudo chown user.group file1 file2… 以更改所有权。
  • ,sudo chown user.group file1 file2 in gitlab-ci.yml or in /home/gitlab-runner/.local/bin/deploy.sh?如何使用gitlab-runner sudo root
  • ps.我可以在postgit pull 之后运行setfacl 吗?
猜你喜欢
  • 2011-01-23
  • 1970-01-01
  • 1970-01-01
  • 2010-09-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多