EPC的CI/CD
1. 流程介绍
开发人员合并代码到gogs,触发钩子,drone根据git仓库中的.drone.yml进行工作,使用fpm进行rpm打包并更新本地yum仓库
2. .drone.yml
workspace:
base: /root/gogs
path: epc-c
pipeline:
build:
image: centos7.5:dev
environment:
- SSH_ARGS=-p 22 -o StrictHostKeyChecking=no
- SCP_ARGS=-P 22 -o StrictHostKeyChecking=no
- TEST_SERVER=root@192.168.9.105
- RUN_PATH=/root/df/caddy/filebrowser/files/EPC-VERSION
commands:
- git_rev=$(git rev-parse HEAD| cut -c1-10)
- git clone http://192.168.9.105:60080/dongfeng/pack-epc-c.git
- cd pack-epc-c
- ./pack-epc-c.sh
- rpm_name="baicells-epc-c-$(cat VERSION)-$(cat RELEASE).x86_64.rpm"
- rpm_rename=$(echo $rpm_name| awk -F .rpm '{print $1}')
- rpm_newname="$rpm_rename"_"$(date '+%Y%m%d')"_"$git_rev".rpm
- eval $(ssh-agent -s)
- ssh-add /root/.ssh/id_rsa
- scp $SCP_ARGS $rpm_name "$TEST_SERVER":"$RUN_PATH"/"$rpm_newname"
- ssh "$TEST_SERVER" > /dev/null 2>&1 << eeooff
- cd /root/df/caddy/yum.repo
- rm -rf rpms/baicells-epc-c-*.rpm
- cp -rf ../filebrowser/files/EPC-VERSION/"$rpm_newname" rpms/
- createrepo --update .
- exit
- eeooff
3. 打包脚本
#!/bin/bash
#安装依赖
rpm -qa | grep epel-release &>/dev/null
[[ $? == 1 ]] && yum install -y epel-release
rpm -qa | grep ^expect &>/dev/null
[[ $? == 1 ]] && yum install -y expect
if [[ ! $(which fpm) ]];then
yum -y install ruby rubygems ruby-devel
#gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
#gem sources -l
gem install fpm
fi
#设定分支
git branch --set-upstream-to=origin/master master
#git拉取最新配置
git pull
#git拉取子模块
git submodule init
git submodule update --remote
#if [ -z $1 ]; then
# echo "Usage: $0 1.1.1"
# exit 0
#fi
VERSION_INPUT=$(echo $1 | egrep "^[1-9][0-9]*\.[0-9]+\.[0-9]+$")
VERSION_BASE=$(cat epc-c/VERSION)
VERSION=${VERSION_INPUT:-"$VERSION_BASE"}
VERSION_TMP=$(cat VERSION)
RELEASE=$(cat RELEASE)
if [[ $VERSION == $VERSION_TMP ]];then
let RELEASE++
echo $RELEASE > RELEASE
else
let RELEASE=1
echo $VERSION > VERSION
echo $RELEASE > RELEASE
fi
git add VERSION RELEASE
git commit -m "mod version,release"
expect -c "set timeout 5;
spawn git push origin master;
expect \"Username\" {send \"dongfeng\r\"};
expect \"Password\" {send \"baicells\r\"};
send \"quit\n\";
expect eof"
if [ -z ${VERSION} ]; then
echo "Version $1 is incorrect"
echo "Syntax: ^[1-9][0-9]*\.[0-9]+\.[0-9]+$"
exit 0
fi
rm -rf *.rpm &>/dev/null
BASE_DIR=$(cd "$(dirname "$0")"; pwd); cd ${BASE_DIR}
#VERSION=${1:-"1.0.0"}
fpm -f -s dir -t rpm -n "baicells-epc-c" -v "$VERSION" --iteration "$RELEASE" -C "epc-c" -p . \
--rpm-rpmbuild-define "_build_id_links none" \
epc.service=/usr/lib/systemd/system/ \
HssFailover=/usr/local/epc/ \
conf=/usr/local/epc/ \
watchdog=/usr/local/epc/ \
cg_app=/usr/local/epc/ \
config.txt=/usr/local/epc/ \
epc_watchdog.sh=/usr/local/epc/ \
hss_app=/usr/local/epc/ \
mme_app_1=/usr/local/epc/ \
mme_app_2=/usr/local/epc/ \
nwconfig.sh=/usr/local/epc/ \
pcrf_app=/usr/local/epc/ \
pgw_app_1=/usr/local/epc/ \
pgw_app_2=/usr/local/epc/ \
pgw_app_3=/usr/local/epc/ \
pgw_app_4=/usr/local/epc/ \
register=/usr/local/epc/ \
sgw_gtpc_app=/usr/local/epc/ \
sgw_gtpu_app=/usr/local/epc/ \
startAll.sh=/usr/local/epc/ \
startEPC.sh=/usr/local/epc/ \
start_tomcat.sh=/usr/local/epc/ \
stopEPC.sh=/usr/local/epc/ \
stop_tomcat.sh=/usr/local/epc/ \
tomcat_watchdog.sh=usr/local/epc/