用 travis-ci 自动部署 github 上的 angular2 项目到 centos7 的 vps

来源:互联网 发布:lol支持mac系统吗 编辑:程序博客网 时间:2024/06/18 01:25

概述

在 vps 上, 为运行着 travis 的系统生成公钥和私钥, 公钥放在 vps 上, 私钥放到项目目录中, 然后被 travis 拉到系统, 这样, 在 travis 访问 vps 时就可以免密码了

以下所有操作均在 vps 上执行

环境

vps: kylin-ux.com
vps 操作系统: CentOS Linux release 7.3.1611 (Core)
github: https://github.com/shuhm-gh/kdb
本地对应项目目录: /opt/www/kdb

确定 nodejs 最新版本

安装 nvm

git clone https://github.com/creationix/nvm.gitcd nvm/; ./install.shsource /root/.bash_profile

查看版本

nvm list-remote

6.10.3 为最新版本, 作为 .travis.ymlnode_js: 的值

travis 生成密钥

ssh-keygen -f travis

为 vps 添加 travis 的公钥

cat travis.pub >> ~/.ssh/authorized_keys

加密 travis 私钥

# 切换到项目目录cd /opt/www/kdb/yum install gemyum install ruby-develgem install travistravis login # github 帐号和密码cp /root/travis .travis/travis encrypt-file .travis/travis --add # --add 会将解密命令添加到 .travis.yml

--add 修改的内容

before_install:- openssl aes-256-cbc -K $encrypted_9d6a078f2a50_key -iv $encrypted_9d6a078f2a50_iv -in travis.enc -out .travis/travis -d

提交到 github

git add -Agit commit -m 'travis'git push

查看 https://www.travis-ci.org/

这里写图片描述

.travis.yml 完整内容

language: node_jsnode_js:- 6.10.3script:- ssh -i .travis/travis root@kylin-ux.com cd /opt/www/kdb/; git pull; npm buildbranches:  only:  - masterbefore_install:- openssl aes-256-cbc -K $encrypted_9d6a078f2a50_key -iv $encrypted_9d6a078f2a50_iv -in travis.enc -out .travis/travis -d- chmod 600 .travis/travisaddons:  ssh_known_hosts: kylin-ux.com

补充

Q: The authenticity of host ‘192.168.0.110 (192.168.0.110)’ can’t be established. RSA key fingerprint is a3:ca:ad:95:a1:45:d2:57:3a:e9:e7:75:a8:4c:1f:9f. Are you sure you want to continue connecting (yes/no)?
A: echo -e "Host 102.201.64.94\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
ssh 加选项 -o stricthostkeychecking=no

Q: 免密
A:

travis encrypt DEPLOY_USER=<csun-username> travis encrypt DEPLOY_PASS=<csun-password>export SSHPASS=$DEPLOY_PASSsshpass -e ssh $DEPLOY_USER@kylin-ux.com
阅读全文
0 0
原创粉丝点击