-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.travis.yml
46 lines (44 loc) · 1.46 KB
/
.travis.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# web前端项目 Travis CI 自动部署到服务器配置文件
# 项目使用的语言
language: node_js
# 语言的版本
node_js:
- '9'
directories:
- node_modules
# 1. 在 install 之前执行的脚本
before_install:
# 创建 .ssh 目录,在用户目录下
- mkdir -p ~/.ssh/
# 这里需要在开发机(本地)用 travis 的命令行工具登陆 github,创建解密钥用的 key
- openssl aes-256-cbc -K $encrypted_09c5eaff0959_key -iv $encrypted_09c5eaff0959_iv
-in id_rsa.enc -out ~/.ssh/id_rsa -d
# 降低目录权限
- chmod 600 ~/.ssh/id_rsa
# 将目标服务器(将要部署的服务器)的 ip 添加到 config 中,使其支持免密登陆
- echo -e "Host 123.207.252.230 \n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
# 2. 安装项目依赖
install:
- npm install
# 3. 在执行 script 中脚本之前执行
before_script:
# 4. 执行 script 中的脚本
script:
# 这里一般会进行 test 或者代码覆盖率什么的,但是暂时先不用
# 编译项目到 dist 文件夹
- npm run build --qiniu
# 5. 执行 script 脚本成功之后执行
# 6. 最后执行
after_success:
# 移动到打包好的目录中
- cd ./dist
# scp
- scp index.html ubuntu@123.207.252.230:~/
- ssh ubuntu@123.207.252.230 'mkdir -p /usr/share/nginx/html/votes && mv ~/index.html /usr/share/nginx/html/votes'
# - ssh ubuntu@123.207.252.230 'cd /usr/share/nginx/html/votes && tar -jxf index.html && rm -rf index.html'
after_script:
branches:
only:
- master
env:
global: