您的位置:首页 > 运维架构 > Linux

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

2017-05-29 21:19 811 查看

概述

在 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.git cd nvm/; ./install.sh
source /root/.bash_profile


查看版本

nvm list-remote


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

travis
生成密钥

ssh-keygen -f travis


为 vps 添加
travis
的公钥

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


加密
travis
私钥

# 切换到项目目录
cd /opt/www/kdb/

yum install gem
yum install ruby-devel
gem install travis

travis 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 -A
git commit -m 'travis'
git push


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



.travis.yml
完整内容

language: node_js
node_js:
- 6.10.3
script:
- ssh -i .travis/travis root@kylin-ux.com cd /opt/www/kdb/; git pull; npm build
branches:
only:
- master
before_install: - openssl aes-256-cbc -K $encrypted_9d6a078f2a50_key -iv $encrypted_9d6a078f2a50_iv -in travis.enc -out .travis/travis -d
- chmod 600 .travis/travis
addons:
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_PASS
sshpass -e ssh $DEPLOY_USER@kylin-ux.com
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: