简体   繁体   English

gitlab,接收后,部署

[英]gitlab, post-receive, deploy

Is should be simple but perhaps I don't understand the big picture here. 应该很简单,但也许我不了解这里的全局。 I have setup a GitLab (omnibus) that is working wonderful on Ubuntu 16.04/Apache. 我已经安装了一个在Ubuntu 16.04 / Apache上运行良好的GitLab(综合)。 On the same machine (the same Apache) I have the www that is supposed to be updated through GitLab. 在同一台机器(相同的Apache)上,我有应该通过GitLab更新的www。

Since I am on the same machine, it's useless to use webhooks or other complicated mechanisms. 由于我在同一台机器上,因此使用webhook或其他复杂机制毫无用处。 I just want to copy "on commit to master" to www folder so I choose custom_hooks as explained here http://docs.gitlab.com/ce/administration/custom_hooks.html 我只想将“提交到母版”复制到www文件夹,所以我选择了custom_hooks,如此处所述http://docs.gitlab.com/ce/administration/custom_hooks.html

I created a file post-receive, gave git rights (and folder too) and trigger is working 我创建了一个文件接收后,赋予git权限(还有文件夹),并且触发器正在工作

#!/bin/bash
mkdir testdir

The directory is created on commits. 该目录是在提交时创建的。

May be a stupid question but where are the GIT repo files to be copied? 可能是一个愚蠢的问题,但是要将GIT回购文件复制到哪里?

I saw a lot of tutorials that are creating hooks on client side, should I make another GIT client in www folder and use it's hooks? 我看到了很多在客户端上创建钩子的教程,我应该在www文件夹中创建另一个GIT客户端并使用它的钩子吗?

This can't be done on GIT server side in gitlab master folder? 这不能在gitlab主文件夹的GIT服务器端完成吗?

Thanks in advance for guidance, 预先感谢您的指导,

Ok, I figured out myself. 好吧,我想通了自己。 In case anyone needs, first I found a excellent tutorial here: https://www.digitalocean.com/community/tutorials/how-to-use-git-hooks-to-automate-development-and-deployment-tasks 万一有人需要,首先我在这里找到了一个很好的教程: https : //www.digitalocean.com/community/tutorials/how-to-use-git-hooks-to-automate-development-and-deployment-tasks

What I've completely missed, is that installation of GitLab doesn't install the git itself :) Just creates a user+group 'git'. 我完全想念的是,安装GitLab不会安装git本身:)仅创建一个用户+组'git'。 So all GitLab projects folders with git structure in: 因此,所有GitLab项目的文件夹都具有git结构:

/var/opt/gitlab/git-data/repositories/<GROUP>/<PROJECT>

are just (git) folders, pushed by clients like I tried and successfully pushed from another machine in my network (from windows) 只是(git)文件夹,由客户端推送,就像我尝试并成功从网络中的另一台计算机推送(从Windows)

Now the problem resumes to install git of course on server machine, where GitLab resides: 现在问题恢复了,当然可以在GitLab所在的服务器机器上安装git了:

sudo apt-get install git

Then, test that you can checkout some branch and copy to /www/ folder (folder must have permissions for user so for future, git) 然后,测试您是否可以签出某个分支并将其复制到/ www /文件夹(文件夹必须具有用户权限,以便日后使用git)

git --work-tree=/var/www/html/<MY_WWW_DEPLOY_FOLDER> --git-dir=/var/opt/gitlab/git-data/repositories/<MY_GITLAB_PROJECT_REPO> checkout -f

Success. 成功。 All the files appeared in deploy folder now. 现在所有文件都出现在deploy文件夹中。

Further, the problem resumes to trigger automatic deploy when someone is pushing the repo and for this, you MUST create a folder named custom_hooks inside GitLab project folder 此外,当有人推送存储库时,问题会继续触发自动部署,为此,您必须在GitLab项目文件夹中创建一个名为custom_hooks的文件夹

/var/opt/gitlab/git-data/repositories/<MY_GITLAB_PROJECT_REPO>/custom_hooks/

Inside, create a new file called post-receive and give +x rights for git user I haven't complete this part yet since I haven't decide what language to use for post-receive. 在内部,创建一个名为post-receive的新文件,并为git用户赋予+ x权限。我还没有完成这一部分,因为我还没有决定使用哪种语言进行post-receive。 Seems that can be any type, even a C compiled executable as long as have +x rights and is ready to accept some (poor doccumented) GIT callback arguments. 似乎可以是任何类型,甚至可以是C编译的可执行文件,只要具有+ x权限,并且可以接受一些(记录不足的)GIT回调参数即可。

Cheers, 干杯,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM