在 Jenkins 上安装 zf2 项目的步骤
mkdir /path/to/your/project
1. 安装作曲家
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
注意:如果上述由于权限而失败,请使用 sudo 再次运行 mv 行。
包含 sudo 的快速复制粘贴版本:
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
-
在项目根目录下创建composer.json文件
添加所有你需要的包
{
“名称”:“amarjitsingh”,
“描述”:“amarjitsingh”,
"license": "BSD-3-Clause",
“关键词”:[
“框架”,
“zf2”
],
"主页": "http://domain.com/",
“要求”: {
"php": ">=5.5",
"zendframework/zendframework": "~2.5",
“phpoffice/phpword”:“开发大师”,
“教义/教义-orm模块”:“0.7.0”,
“想象/想象”:“0.5.*”,
“zf-commons/zfc-user”:“开发-master”
},
“自动加载”:{
“psr.0”:“/模块”
}
}
运行“composer install”来安装这些包。
-
在你的机器上设置 git
如果您使用的是 ubuntu,则可以使用以下命令设置 GIT
sudo apt-get 更新
sudo apt-get install git
设置 Git
git config --global user.name "Your Name"
git config --global user.email "youremail@domain.com"
检查配置列表
git config --list
一旦你设置了 GIT 然后 c
cd /path/to/your/project
。一旦你安装了包,在文件中创建一个“.gitignore”文件
root 并在其中添加 'vendor'。
git init
git remote add origin https://username@bitbucket.org/username/zf2ci.git
应用以下命令来添加、提交和推送文件
git add .
git commit -m 'Initial commit with contributors'
git push -u origin master
git pull
使用云,您可以使用 AWS。我正在使用数字海洋
1 创建一个droplet
2.根据需要命名,在我的情况下是zf2ci
3.选择套餐
4. 选择操作系统 my cas eis Ubuntu 14.04
5. 在应用程序选项卡中选择 LAMP
6 完成后,您将获得 IP 地址、用户名 root 和密码。
7.使用putty登录ip
8.用户root
9.密码pass
10.一旦你进入它会提示你更改密码
11. 转到网络根目录,例如/var/www/html
12.安装GIT
13.apt-get install git
14. 克隆仓库
15.git clone https://username@bitbucket.org/username/zf2ci.git
16. 在这台机器上安装composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
注意:如果上述由于权限而失败,请使用 sudo 再次运行 mv 行。
包含 sudo 的快速复制粘贴版本:
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
- 转到应用程序路径
/var/ww/html/zf2ci
- 运行 '
composer install --no-dev' 我们安装它时没有开发选项,因为我们只在应用服务器上安装经过良好测试的代码
第三步
创建 Jenkins 服务器
1.为Jenkins设置另一个Droplet
2.镜像ubuntu
3.安装灯
安装 Jenkins
安装詹金斯
在我们可以安装 Jenkins 之前,我们必须将密钥和源列表添加到 apt。这分两步完成,首先我们将添加密钥。
1.1
wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | apt-key add -
其次,我们将为 Jenkins 创建一个来源列表。
1.2
echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list
1.3
现在,我们只需要在安装 Jenkins 之前更新 apt 的缓存。
apt-get update
1.4
由于缓存已更新,我们可以继续安装 Jenkins。请注意,Jenkins 有大量依赖项,因此安装它们可能需要一些时间。
apt-get install jenkins
1.5 打开8080端口的ip
例如http://127.0.0.1:8080
1.6 在jenkins服务器上安装git
sudo apt-get update
sudo apt-get install git
1.7 安装作曲家
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
1.8 开启用户认证
1.9
enable bitbucket plugin 詹金斯
1.9.1
Manage Jenkins->Manage Plugins->Bitbucket Plugin->download 并安装
1.9.2
创造工作
创建工作->
项目名称(例如 zf2ci)->
源码管理(git)提供ssh url(git@bitbucket.org:username/zf2ci.git)->
分支到 build (*/master) 这是每次任何用户提交并将代码与 Master 分支合并时的分支 - Jenkins 被调用
1.9.3
构建触发器
选择选项(在推送 chnage 时构建)这将在我们在位桶上创建 POST 挂钩时工作
1.9.4
构建->执行shell
composer install
./vendor/bin/phpunit ./tests
我们的测试位于 intests 目录
1.9.5
设置ssh key pair
通过putty登录jenkins Serevr
su jenkins
cd
ls -la( check what is in the jenkins home directory)
ssh-kegen -t rsa (dsa by default but choose rsa key ,it is faster)
press enter(on path)
press enter(leave the pass phrase empty , the whole point here is to avoid passwords in the automated jobs)
pres enter
cd .ssh
ls -la(您会在此处找到id_rsa.pub)文件
cat id_rsa.pub
(全选并复制文件内容)
1.9.6
转到位桶
切换到 repo zf2ci
前往设置
单击部署密钥->添加密钥
添加标签(詹金斯)
key*(粘贴 id_rsa.pub 的内容)文件在这里
保存密钥
summary
`zf2ci->settings->deployment keys->add key->type` label and paste id_rsa.pub key->save
1.9.7
为 repo 注册 POST 钩子
Settings->
Integrations->
Hooks->
POST(search for POST Hook)->
Add the url /IP of the Jenkins Server) (`172.62.235.100:8080/bitbucket-hook/`)
(the body of the post contanis information about the repository, branch, list of recent commits, user)
1.9.8
登录 Jenkins 服务器
su jenkinks
cd
cd .ssh
git ls-remote -h ssh://git@bitbucket.org:username/zf2ci.git HEAD
1.9.9
save Jenkins 上的项目
1.9.10
将以下命令添加到
执行外壳->命令
[rsync -y -vrzhe "ssh -o StrictMostKeyChecking=no" --exclude vendor/ . root@ipaddress:/var/www/html/zf2ci(应用服务器)]
ssh root@ipaddress<<EOF
cd /var/www/html/zf2ci
composer install --no-dev
EOF