git前端工程实现ci_gitlab中vue前端项目CI/CD部署笔记
持續集成
略
Gitlab的持續集成
我們可以將整個運行機制,看作一個賞金獵人接任務,執行任務,并完成任務的過程。
GitLab-CI
簡單來說,這就是一個任務發布平臺。運行在gitlab服務器,監聽代碼狀態變化,并發布對應的任務。
GitLab-Runner
而每個runner就是一位賞金獵人,是任務的執行者。
.gitlab-ci.yml
任務的發布者,規定什么時候觸發任務,任務的具體內容。
配置流程
經過前面的解釋,整個思路就很清晰了。我們需要做的有三件事。編寫.gitlab-ci.yml文件,設置對應的任務
部署Runner,激活賞金獵人
配置ci,邀請賞金獵人加入系統
部署Runner
這一步需要一個服務器,能run起來賞金獵人。
安裝
請務必安裝最新版,不然會出現很多未知的問題下載二進制文件# Linux x86-64
sudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
# Linux x86
sudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-386
# Linux arm
sudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-arm
# Linux arm64
sudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-arm64授予執行權限sudo chmod +x /usr/local/bin/gitlab-runnerCreate a GitLab CI user:sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bashInstall and run as service:sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
sudo gitlab-runner start
加入任務系統
注冊sudo gitlab-runner register
然后就是一些簡單的配置,配置完成后就將該Runner注冊到任務發布平臺了,然后就可以接任務了。詳細見參考文獻【1】
編寫.gitlab-ci.yml任務
本機部署版本
.gitlab-ci.ymlstages:
- deploy
cache:
paths:
- node_modules/
- public/
deployJob:
stage: deploy
script:
- npm install
- npm run build
- rm -rf /home/data/three_miju_shopper_manager_system_front/*
- cp -rf ./dist/* /home/data/three_miju_shopper_manager_system_front/
- sh ./bot.sh ${CI_COMMIT_REF_SLUG} ${CI_COMMIT_SHA:0:8} ${CI_COMMIT_MESSAGE}
tags:
- shared_test_machine_runner
only:
- dev
這個版本具有企業微信群機器人推送功能,需要配置./bot.sh#!/usr/bin/env bash
curl '群機器人地址' \
-H 'Content-Type: application/json' \
-d '
{
"msgtype": "markdown",
"markdown": {
"content": "商戶端代碼已更新,分支:'$1' 提交:'$2'
更新:'$3'
已發布,[點擊測試](http://test.shop.gileey.cn)"
}
}'
遠程推送版本stages:
- deploy
cache:
paths:
- node_modules/
- public/
deployJob:
stage: deploy
script:
- mkdir -p ~/.ssh
- echo "$SSH_PRIVATE_KEY" >> ~/.ssh/id_dsa
- chmod 600 ~/.ssh/id_dsa
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
- rsync -avzu --progress ./dist/* root@thinkmoon.cn:/www/wwwroot/3ju.psyannabel.cn/
tags:
- shared_test_machine_runner
only:
- dev
該版本在gitlab-runner機器上執行編譯等工作,編譯完成后使用rsync同步到云服務器,需要配置私鑰變量$SSH_PRIVATE_KEY
遇到的問題
導入自定義組件時一直報錯:This dependency was not found:
出現背景:由于以前命名組件是"clickImg",后改成"ClickImg",由于linux的區分大小寫,所以會一直沒找到。
解決方案:換個名字???
參考文獻
總結
以上是生活随笔為你收集整理的git前端工程实现ci_gitlab中vue前端项目CI/CD部署笔记的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 十道经典面试算法真题详解
- 下一篇: html5倒计时秒杀怎么做,vue 设