浣跨敤GitLab CI/CD鐨勫熀鏈楠

  1. 鍒涘缓GitLab椤圭洰锛氬湪GitLab涓垱寤轰竴涓柊鐨勯」鐩傝椤圭洰灏嗗寘鍚偍鐨勪唬鐮佸拰CI/CD娴佹按绾裤

  2. 鍒涘缓.gitlab-ci.yml鏂囦欢锛氬湪椤圭洰鏍圭洰褰曚腑鍒涘缓.gitlab-ci.yml鏂囦欢銆傝鏂囦欢灏嗗畾涔塁I/CD娴佹按绾夸腑鐨勬瀯寤恒佹祴璇曞拰閮ㄧ讲姝ラ銆

  3. 瀹氫箟CI闃舵锛氬湪.gitlab-ci.yml鏂囦欢涓畾涔塁I闃舵銆侰I闃舵灏嗗畾涔夊浣曟瀯寤哄拰娴嬭瘯鎮ㄧ殑浠g爜銆備緥濡傦紝鎮ㄥ彲浠ヤ娇鐢―ocker瀹瑰櫒鏉ユ瀯寤哄拰娴嬭瘯浠g爜銆

image: docker:latest
services:
  - docker:dind
stages:
  - build
  - test
build:
  stage: build
  script:
    - docker build -t my-image:latest .
test:
  stage: test
  script:
    - docker run my-image:latest npm test
  1. 瀹氫箟CD闃舵锛氬湪.gitlab-ci.yml鏂囦欢涓畾涔塁D闃舵銆侰D闃舵灏嗗畾涔夊浣曞皢浠g爜閮ㄧ讲鍒伴鐢熶骇鐜鍜岀敓浜х幆澧冦
deploy:
  stage: deploy
  environment:
    name: production
    url: https://my-app.com
  script:
    - docker push my-image:latest
    - ssh deploy@my-server 'docker pull my-image:latest && docker-compose up -d'
  1. 杩愯CI/CD娴佹按绾匡細涓鏃︽偍瀹氫箟浜咰I/CD娴佹按绾匡紝鎮ㄥ彲浠ユ墜鍔ㄨ繍琛屾祦姘寸嚎浠ユ瀯寤恒佹祴璇曞拰閮ㄧ讲鎮ㄧ殑浠g爜銆傛偍涔熷彲浠ヨ缃嚜鍔ㄥ寲CI/CD娴佹按绾胯Е鍙戝櫒锛屼緥濡傚綋浠g爜鎻愪氦鍒癎itLab鏃惰嚜鍔ㄨ繍琛屾祦姘寸嚎銆
$ git add .gitlab-ci.yml
$ git commit -m "add gitlab-ci.yml"
$ git push origin main
  1. 鐩戣CI/CD娴佹按绾匡細鍦–I/CD娴佹按绾胯繍琛屾湡闂达紝鎮ㄥ彲浠ョ洃瑙嗘瀯寤恒佹祴璇曞拰閮ㄧ讲姝ラ鐨勮繘搴﹀拰缁撴灉銆傛偍鍙互鍦ㄦ祦姘寸嚎椤甸潰鏌ョ湅鏃ュ織鍜岄敊璇秷鎭

鍦 GitLab CI/CD 涓紝.gitlab-ci.yml 鏂囦欢鏄畾涔 CI/CD 娴佹按绾跨殑鏂囦欢銆傝繖涓枃浠剁敱澶氫釜閮ㄥ垎缁勬垚锛屽寘鎷 variables銆乻tages銆乯obs 绛夈

涓嬮潰鏄 variables 閮ㄥ垎鐨勪竴浜涘父鐢ㄥ彉閲忓強鍏跺惈涔夛細

杩欎簺鍙橀噺鍙互鍦 .gitlab-ci.yml 鏂囦欢涓娇鐢紝浠ヤ究鍦ㄦ瀯寤恒佹祴璇曞拰閮ㄧ讲杩囩▼涓紩鐢ㄥ畠浠備緥濡傦細

stages:
– build
– test
– deploy

build:
stage: build
script:
– docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA .

test:
stage: test
script:
– docker run $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA npm test

deploy:
stage: deploy
script:
– ssh $CI_DEPLOY_USER@$CI_DEPLOY_SERVER ‘docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA && docker-compose up -d’

鍦ㄤ笂闈㈢殑绀轰緥涓紝鎴戜滑浣跨敤浜 $CI_COMMIT_SHORT_SHA 鍙橀噺鏉ユ爣璁 Docker 闀滃儚鐨勭増鏈紝浣跨敤 $CI_REGISTRY_IMAGE 鍙橀噺鏉ユ寚瀹 Docker 闀滃儚鐨勫悕绉帮紝浣跨敤 $CI_DEPLOY_USER 鍜 $CI_DEPLOY_SERVER 鍙橀噺鏉ラ儴缃插簲鐢ㄧ▼搴忋

All posts

Other pages


Deprecated: 鏂囦欢 娌℃湁 comments.php 鐨勪富棰 鑷増鏈 3.0.0 璧峰凡寮冪敤锛屼笖娌℃湁鍙敤鐨勬浛浠c 璇峰湪鎮ㄧ殑涓婚涓寘鍚竴涓 comments.php 妯℃澘銆 in /www/wwwroot/liguoqi.site/wp-includes/functions.php on line 6078

鍙戣〃鍥炲

鎮ㄧ殑鐢靛瓙閭鍦板潃涓嶄細琚叕寮銆 蹇呭~椤瑰凡鐢 * 鏍囨敞