标签:add 链接 修改权限 logs share pid pre 设置 doc
FROM jenkins USER root ADD sources.list /etc/apt/sources.list RUN apt-get update && apt-get install -y rsync RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ADD rsync.password /etc/rsync.password RUN chmod 600 /etc/rsync.password && chown jenkins:jenkins /etc/rsync.password ADD timezone /etc/timezone USER jenkins
注:sources.list 为国内的debian源。
rsync.password 为rsync远程同步的密码文件。
timezone 为时区文件否则,jenkins会差8个小时。内容Asia/Shanghai。
docker build -t jenkins:jenkins-chao .
docker run --name myjenkins -uroot -p 8081:8080 -p 50000:50000 -v /srv/jenkins_home:/var/jenkins_home -d jenkins:jenkins-chao
注:-u 表示使用root权限。
vi /etc/rsyncd.conf #Rsync server uid = rsync gid = rsync use chroot = no maxconnections = 2000 timeout = 600 pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock log file = /var/run/rsyncd.log ignore errors read only = false list = false hosts allow = 10.211.55.0/24 hosts deny = 0.0.0.0/32 auth users = rsync_backup secrets file = /etc/rsync.password [backup] comment = www by oldboy 2016.09.23 path = /backup
useradd rsync -s /sbin/nologin -M
mkdir /backup chown -R rsync /backup echo "rsync_backup:oldboy" >/etc/rsync.password chmod 600 /etc/rsync.password
rsync --daemon
#切换到项目目录 JobName=‘xiangmu‘ JobDir=‘/var/jenkins_home/www‘ cd $JobDir #如果有项目目录则删除 if [ -d $JobName ]: then rm -rf $JobName fi #克隆远程项目链接 git clone ssh://git@***/"$JobName".git cd $JobName #删除git目录 rm -rf .git #项目初始化 rsync -az $JobDir"/xiangmu-dev/dev/" $JobDir"/xiangmu" #目录设置权限 chmod -R 777 $JobDir"/xiangmu/backend/runtime" && chmod -R 777 $JobDir"/xiangmu/backend/web/assets" #远程copy cd $JobDir"/"$JobName #同步 rsync -avz --delete $JobDir"/"$JobName --exclude-from=$JobDir"/xiangmu-dev/xiangmu_exclude.list" rsync_backup@*.*.*.*::backup --password-file=/etc/rsync.password
注:jenkins脚本为yii2的自动化部署。如果jenkins为root,最好rsync同步时也为root
标签:add 链接 修改权限 logs share pid pre 设置 doc
原文地址:http://www.cnblogs.com/xuezhigu/p/6690783.html