博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
笔记:Gitlab-CI部署流程
阅读量:7126 次
发布时间:2019-06-28

本文共 4738 字,大约阅读时间需要 15 分钟。

Gitlab-CI部署流程

  • ssh连接服务器

    • 触发条件

      当用户推送最新代码至master分支时,trigger gitlab-ci

    • 原理

      利用gitlab自动化在gitlab打包

      打包后的文件利用ssh推送至服务器

      • 读取gitlab-ci.yml文件

      • .gitlab-ci.yml配置文件详解

        image: node:8 # 拉取node version:8 的docker镜像cache: # 缓存文件夹 or 文件  paths:    - node_modules/before_script: # 执行脚本前的工作 - apt-get update -qq && apt-get install -y -qq sshpass # 更新apt-get工具并安装sshpassdeploy_stage: # deploy_stage脚本  stage: deploy  environment: Staging  only:    - master # 配置触发条件  script:    - npm install # 步骤1: 安装前端依赖包    - npm run build # 步骤2: 打包前端文件夹    - export SSHPASS=$USER_PASS # 步骤3: 导出 USER_PASS环境变量供sshpass使用    - sshpass -e scp -o stricthostkeychecking=no -r dist/ $USER_NAME@$SERVER_IP:$SERVER_PATH # 步骤4: ssh连接服务器并推送dist/文件夹至SERVER_PATH下复制代码

        $USER_NAME: ssh连接服务器的用户名

        $USER_PASS: ssh连接服务器的密码

        $SERVER_IP: 服务器IP地址

        $SERVER_PATH: 推送服务器绝对路径

        以上变量皆在Gitlab项目 setting => CI => Environment Variables里配置

  • 推送完成后Gitlab=> CI => Pipeline查看日志

    日志详解 (带蓝标的为gitlab中配置好的script步骤)

    Running with gitlab-runner 11.9.0-rc2 (227934c0)  on docker-auto-scale 0277ea0fUsing Docker executor with image node:8 ...Pulling docker image node:8 ...Using docker image sha256:8c51cec97ebfc94d85daf702377acb73afcfc6cfd5a85e4fe2816732e25ec229 for node:8 ...Running on runner-0277ea0f-project-11375217-concurrent-0 via runner-0277ea0f-srm-1553699604-3058a32d...Initialized empty Git repository in /builds/xxx/doer/.git/Fetching changes...Created fresh repository.From https://gitlab.com/xxx/doer * [new branch]      develop    -> origin/develop * [new branch]      master     -> origin/masterChecking out 017588b7 as master...Skipping Git submodules setupChecking cache for default-2...Downloading cache.zip from https://storage.googleapis.com/gitlab-com-runners-cache/project/11375217/default-2 Successfully extracted cache$ apt-get update -qq && apt-get install -y -qq sshpassdebconf: delaying package configuration, since apt-utils is not installedSelecting previously unselected package sshpass.(Reading database ... (Reading database ... 5%(Reading database ... 10%(Reading database ... 15%(Reading database ... 20%(Reading database ... 25%(Reading database ... 30%(Reading database ... 35%(Reading database ... 40%(Reading database ... 45%(Reading database ... 50%(Reading database ... 55%(Reading database ... 60%(Reading database ... 65%(Reading database ... 70%(Reading database ... 75%(Reading database ... 80%(Reading database ... 85%(Reading database ... 90%(Reading database ... 95%(Reading database ... 100%(Reading database ... 29978 files and directories currently installed.)Preparing to unpack .../sshpass_1.06-1_amd64.deb ...Unpacking sshpass (1.06-1) ...Setting up sshpass (1.06-1) ...$ npm installnpm notice created a lockfile as package-lock.json. You should commit this file.npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.7 (node_modules/fsevents):npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.7: wanted {
    "os":"darwin","arch":"any"} (current: {
    "os":"linux","arch":"x64"})audited 27888 packages in 10.616sfound 0 vulnerabilities$ npm run build> doer@0.1.0 build /builds/xxx/doer> vue-cli-service build- Building for production...Starting type checking and linting service...Using 1 worker with 2048MB memory limit WARNING Compiled with 2 warnings15:15:42 warning entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). This can impact web performance.Entrypoints: app (247 KiB) js/chunk-vendors.419d8636.js css/app.20dafc28.css js/app.40b96980.js warning webpack performance recommendations: You can limit the size of your bundles by using import() or require.ensure to lazy load some parts of your application.For more info visit https://webpack.js.org/guides/code-splitting/ File Size Gzipped dist/js/chunk-vendors.419d8636.js 240.07 KiB 82.82 KiB dist/js/app.40b96980.js 6.46 KiB 2.51 KiB dist/css/app.20dafc28.css 0.35 KiB 0.24 KiB Images and other types of assets omitted. DONE Build complete. The dist directory is ready to be deployed. INFO Check out deployment instructions at https://cli.vuejs.org/guide/deployment.html $ export SSHPASS=$USER_PASS$ sshpass -e scp -o stricthostkeychecking=no -r dist/ $USER_NAME@$SERVER_IP:$SERVER_PATHWarning: Permanently added '139.196.98.25' (ECDSA) to the list of known hosts.Creating cache default-2...node_modules/: found 25362 matching files Uploading cache.zip to https://storage.googleapis.com/gitlab-com-runners-cache/project/11375217/default-2 Created cacheJob succeeded复制代码
  • ssh登录服务器查看文件,成功~

这样就完成自动部署的流程啦

后续有待使用docker去操作~

转载于:https://juejin.im/post/5c9c34726fb9a070f23788e8

你可能感兴趣的文章
Netmask v. Address Prefix Length
查看>>
我的友情链接
查看>>
Unity3D教程:iTween插件的介绍和用法
查看>>
zabbix监控磁盘IO
查看>>
Linux inode分析
查看>>
ospf 区域类型详细
查看>>
Linux下Bash编程之條件判斷详解(二)
查看>>
模板引擎缓存
查看>>
php 5.6.11添加模块
查看>>
手动切换和自动切换图片 js代码
查看>>
matlab-线性代数 根据二次型写矩阵
查看>>
flutter 环境搭建
查看>>
Win 7 deskhelp
查看>>
移动端固定底部-ios中钉钉解决方法
查看>>
textbox设置样式为空背景色透明
查看>>
Sybase SQL Anywhere 7 数据库修复成功
查看>>
发展到1Gbps及其以上的速度
查看>>
TurboMail智慧协同通讯平台
查看>>
TurboMail为企业提供海量投递邮件群发系统
查看>>
Linux系统命令Cut使用
查看>>