准备一台服务器
下载gitlab-runner并注册,我前面博客有讲,请关注我博客
安装nginx
安装node,就用root用户安装node就可以了,有的博主说用root用户安装不可以
其实是应为使用root用户安装以后设置的淘宝镜像,在自动部署时,gitlab-runner执行npm的时候还是用的默认的,编译非常慢,导致超时,这时候直接切换用户为gitlab-runner, 执行:
[gitlab-runner@localhost ~]# npm config set registry https://registry.npm.taobao.org
以上步骤都做好了的话,在vue项目根目录下添加.gitlab-ci.yml
stages:
- build
cache:
key: ${CI_BUILD_REF_NAME}
paths:
- node_modules/
build:
stage: build
only:
- master
script:
- cd ${CI_PROJECT_DIR}
- npm install
- npm run build
- cp -r dist/* /usr/myproject/www/ #将打包好的文件复制到其他地方
tags:
- shell
nginx.conf配置
server {
listen 80;
server_name 192.168.74.203; #你自己的项目地址
location / {
root /usr/myproject/www; #项目所在目录
index index.html index.htm;
}
}
提交代码
访问