使用github的CI/CD自动部署项目

2022年7月12日 17:18 by wst

服务部署

现在(2022-07-12)DevOps的概念炒的很火,现实中有很多企业和个人都在使用。

但自己搭建一套基础设施又太麻烦,这里可以借助GitHub自动的工作流来完成自动部署。

下面是踩坑记录及解决方案:

踩坑记录

1. 刚开始从B站上看到一个视频,讲到了github代码的自动部署,于是照着做了一遍,奈何就是不成功。

2. 中间经历了好几天,每天思考这个问题,为什么不成功,怎么解决。

3. 具体的方法和思路如下:

    i. 看看是什么原理:原来GitHub是通过docker的方式实现的,也就是说你的部署步骤都是在容器里做的。

    ii. 尝试很多网上搜到的结果,没有一个凑效,因为文章都是旧版本的GitHub。

    iii. 解决问题最好的方法莫过于看官方文档,通过文档,设置完环境变量后。在yml文件中还要指定环境的名字。

解决方案

为了照顾到对这方面知识不懂的小白,这里从最基本的步骤开始。

前置:

了解并使用过GitHub,会创建、打包、部署vue项目。

步骤:

1. 在本地创建一个vue项目hello-world. 如果不会创建vue环境,参考这里

vue create hello-world

2. 打开github.com,创建一个项目hello-world.

假定创建好的项目的git地址为:git@github.com:movingheart/hello-world.git

3. 关联本地项目和GitHub项目。进入本地项目目录后,执行如下命令:

git remote add origin git@github.com:movingheart/hello-world.git
git push -u origin master

4. 进入GitHub项目页(我的是:https://github.com/movingheart/hello-world),点击“Actions”,然后在新页面中点击“New workflow”按钮。

5. 在打开的页面中,点击“Node.js”卡片的"Configure"来创建对应的workflow配置。如果所示:

6. 在弹出的页面中,把配置文件内容替换为如下:

name: Node.js CI

on:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]

jobs:
  build:

    runs-on: ubuntu-latest
    environment: auto-deploy-test
    steps:
    - uses: actions/checkout@master
    - name: Use Node.js 16.x
      uses: actions/setup-node@v3
      with:
        node-version: 16.16.0
        cache: 'npm'
    - run: npm install
    - name: build project
      run: npm run build --if-present
    - name: Deploy to Server
      uses: easingthemes/ssh-deploy@main
      env:
          SSH_PRIVATE_KEY: ${{ secrets.SERVER_SSH_KEY }}
          ARGS: "-rltgoDzvO --delete"
          SOURCE: "dist/"
          REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
          REMOTE_USER: ${{ secrets.REMOTE_USER }}
          TARGET: ${{ secrets.REMOTE_TARGET }}
          EXCLUDE: "/node_modules/"

7. 注意里面的配置项:secrets.SERVER_SSH_KEY 这样的有四个变量,需要在settings中配置。在当前页面,右键点击“Settings”在新标签页打开。

8. 设置下这四个变量--把build后的文件拷贝到服务器时会用的配置。

在新标签页中,点击左边的“Security->Secrets->Actions”, 然后在右侧点击“Manage your environments and add environment secrets”,如图所示:

然后再点击“New environment”, 取个名字(可以构建几个环境:测试的、生产的、开发的),比如叫“auto-deploy-test”。

设置完后,在页面的最下方找到“Add Secrets”前面有个+号的按钮。点击它把需要的变量分别添加下。

1) SERVER_SSH_KEY -- 认证用的秘钥(github的docker和服务器通信时用. 想省劲可用本地的秘钥~/.ssh/id_rsa拷过去,同时也记得把本地公钥拷~/.ssh/id_rsa.pub贝到服务器的~/.ssh/authorized_keys文件中)

2) REMOTE_HOST -- 服务器地址,一般为外网IP

3) REMOTE_USER -- 登录服务器的用户

4) REMOTE_TARGET -- 把build后的文件拷贝服务器的哪个目录

9. 回到工作流配置页面,点击右上角的“Start commit”按钮提交本次修改。

10. 然后点击“Actions”按钮可以看到工作流的状态,点进去可以看详情。

 

总结

看到这里,不知读者是否明白了原理,可以想想,答案在下面

 

 

 

原理:提交代码后,GitHub把代码拉取到自己的docker容器中,然后执行相应的命令,比如安装环境、构建代码。然后把构建好的代码通过ssh的方式拷贝的你的服务器上。我的测试域名为:http://test.wanshitao.com/


Comments(126) Add Your Comment

Uvamuj
atorvastatin buy online <a href="https://lipiws.top/">lipitor for sale</a> buy atorvastatin 20mg generic
Vkedfy
ciprofloxacin order - <a href="https://cipropro.top/augmentin500/">cheap amoxiclav</a> buy clavulanate pills
Jkgobx
buy cipro 1000mg - <a href="https://metroagyl.top/">how to buy baycip</a> buy generic amoxiclav
Kzaifl
purchase ciplox pill - <a href="https://septrim.top/trimox/">amoxicillin 250mg tablet</a> order erythromycin 500mg without prescription
Gtpbzz
purchase flagyl online - <a href="https://metroagyl.top/oxytetracycline/">order oxytetracycline 250 mg online</a> buy cheap zithromax
Hjjkav
buy stromectol online - <a href="https://keflexin.top/amoxiclav/">co-amoxiclav order online</a> buy sumycin 500mg without prescription
Odkoqq
ivermectin 2mg online - <a href="https://keflexin.top/aczone/">aczone gel</a> order sumycin 250mg generic
Euviyf
purchase valtrex generic - <a href="https://gnantiviralp.com/starlix/">generic nateglinide</a> order zovirax online
Gonkqo
acillin generic <a href="https://ampiacil.top/amoxil500/">cheap amoxil</a> buy generic amoxil online
Ymuryy
flagyl 200mg uk - <a href="https://metroagyl.top/cefaclor/">buy cefaclor 250mg sale</a> purchase azithromycin sale
Pmsves
lasix brand - <a href="https://antipathogenc.com/capoten/">buy capoten 25mg online</a> captopril 25mg canada
Iqmbnx
buy generic glycomet for sale - <a href="https://gnantiacidity.com/septra/">order bactrim</a> cheap lincomycin 500 mg
Nvnydl
buy retrovir 300mg online pill - <a href="https://canadiangnp.com/zyloprim/"></a> allopurinol 300mg drug
Fipfjy
purchase clozaril - <a href="https://genonlinep.com/frumil/">order frumil online cheap</a> pepcid 20mg price
Mlhebq
order generic quetiapine 100mg - <a href="https://gnkantdepres.com/zoloft/">how to buy sertraline</a> eskalith generic
Szyfos
buy anafranil 25mg sale - <a href="https://antdeponline.com/abilify/">aripiprazole 20mg over the counter</a> cheap sinequan
Wnnsfh
atarax 25mg generic - <a href="https://antdepls.com/prozac/">oral fluoxetine</a> endep price
Toadgq
buy augmentin 375mg - <a href="https://atbioinfo.com/ethambutol/">buy myambutol 1000mg generic</a> order cipro generic
Yisatw
amoxicillin medication - <a href="https://atbioxotc.com/">cost amoxicillin</a> ciprofloxacin 500mg uk
Tniqmb
generic zithromax 250mg - <a href="https://gncatbp.com/btetracycline/">buy tetracycline without prescription</a> cost ciplox 500 mg
Lcplpa
cleocin 300mg usa - <a href="https://cadbiot.com/doxycycline/">acticlate price</a> buy generic chloromycetin over the counter
Uuhgep
price of stromectol - <a href="https://antibpl.com/">ivermectine</a> cefaclor 250mg tablet
Lkcjmp
albuterol online - <a href="https://antxallergic.com/dftheo-24/">how to buy theo-24 Cr</a> brand theo-24 Cr 400 mg
Ckaceg
buy depo-medrol us - <a href="https://ntallegpl.com/getcetirizine/">cetirizine online order</a> buy generic astelin over the counter
Hlwaws
desloratadine brand - <a href="https://rxtallerg.com/beclomethasone/">beclomethasone without prescription</a> ventolin inhalator generic
Yqsrph
where can i buy glucophage - <a href="https://arxdepress.com/sitagliptin50/">order januvia without prescription</a> precose 25mg over the counter
Snnuku
glyburide uk - <a href="https://prodeprpl.com/pioglitazone30/">actos 30mg generic</a> forxiga online
Sywwsw
order prandin 1mg online - <a href="https://depressinfo.com/">repaglinide online buy</a> order jardiance online
Wlrhkh
order rybelsus pills - <a href="https://infodeppl.com/ddavpspray/">buy cheap generic DDAVP</a> desmopressin spray
Ppdywf
lamisil price - <a href="https://treatfungusx.com/fulvicin250mg/">order griseofulvin 250mg generic</a> purchase griseofulvin pills
Thdgfe
buy ketoconazole 200mg sale - <a href="https://antifungusrp.com/butenafinecream/">how to get mentax without a prescription</a> buy itraconazole generic
Fogdqs
buy famciclovir 250mg generic - <a href="https://amvinherpes.com/acyclovircream/">buy acyclovir paypal</a> buy valaciclovir 500mg online
Ikobvp
brand lanoxin 250mg - <a href="https://blpressureok.com/avalidemed/">irbesartan 150mg oral</a> furosemide 100mg sale
Bkkptp
order lopressor 100mg online cheap - <a href="https://bloodpresspl.com/telmisartan/">buy telmisartan pills</a> order adalat 30mg sale
Geqvje
buy microzide 25mg sale - <a href="https://norvapril.com/">buy hydrochlorothiazide sale</a> bisoprolol cost
Wxvnow
order nitroglycerin online - <a href="https://nitroproxl.com/catapres/">clonidine 0.1mg brand</a> cost valsartan 80mg
Olwunx
simvastatin affection - <a href="https://canescholest.com/atorvastatin/">lipitor pill</a> atorvastatin experience
Ogubsu
rosuvastatin pills torment - <a href="https://antcholesterol.com/ezetimibe/">zetia leave</a> caduet fling
Ltjphr
viagra professional online able - <a href="https://edsildps.com/superavana/">avana weight</a> levitra oral jelly online enemy
Jaxvwz
dapoxetine daylight - <a href="https://promedprili.com/viagraplus/">viagra plus rot</a> cialis with dapoxetine needle
Fwvxag
cenforce universe - <a href="https://xcenforcem.com/zenegrasildenafil/">zenegra free</a> brand viagra pills write
Mwyefy
brand cialis assume - <a href="https://probrandtad.com/tadorapills/">tadora conscious</a> penisole twitch
Rltcum
brand cialis southward - <a href="https://probrandtad.com/">brand cialis exhaust</a> penisole john
Ionnsf
cialis soft tabs online jet - <a href="https://supervalip.com/viagraoraljelly/">viagra oral jelly party</a> viagra oral jelly online mission
Nxoqbz
cialis soft tabs online copy - <a href="https://supervalip.com/cialissuperactive/">cialis super active treat</a>1 viagra oral jelly online strike
Wgjcbo
priligy dollar - <a href="https://promedprili.com/suhagra/">suhagra lane</a> cialis with dapoxetine successful
Kuotfy
cenforce poet - <a href="https://xcenforcem.com/cialistadalafil/">cialis coupon</a> brand viagra pills wish
Cixmym
inhalers for asthma able - <a href="https://bsasthmaps.com/">asthma treatment image</a> asthma medication servant
Gicpxw
acne treatment painful - <a href="https://placnemedx.com/">acne medication code</a> acne medication explosion
Yytszo
prostatitis pills alone - <a href="https://xprosttreat.com/">prostatitis medications themself</a> pills for treat prostatitis mess
Jvkiws
uti antibiotics board - <a href="https://amenahealthp.com/">uti antibiotics creak</a> treatment for uti straight
Qhuxvz
loratadine medication near - <a href="https://clatadine.top/">claritin counter</a> loratadine although
Mehxxk
valtrex pills plate - <a href="https://gnantiviralp.com/">valacyclovir place</a> valtrex toward
Wdtnkj
dapoxetine awaken - <a href="https://prilixgn.top/">priligy stack</a> priligy sam
Aafjcb
claritin torture - <a href="https://clatadine.top/">loratadine medication branch</a> loratadine medication box
Zfcada
ascorbic acid filch - <a href="https://ascxacid.com/">ascorbic acid lamp</a> ascorbic acid hunter
Thvnmc
promethazine calm - <a href="https://prohnrg.com/">promethazine hate</a> promethazine tangle
Umjseh
clarithromycin acknowledge - <a href="https://gastropls.com/ranitidineonline/">zantac pills professional</a> cytotec pills between
Xpgwhg
fludrocortisone pills elbow - <a href="https://gastroplusp.com/omepprilosec/">prilosec finish</a> prevacid pills mass
Harcww
rabeprazole 10mg canada - <a href="https://gastrointesl.com/">aciphex where to buy</a> buy generic domperidone for sale
Xwscdw
buy generic dulcolax 5 mg - <a href="https://gastroinfop.com/liv52/">cost liv52 20mg</a> liv52 ca
Lgpnfv
eukroma cost - <a href="https://danaterone.shop/">eukroma buy online</a> duphaston over the counter
Aitfeu
bactrim price - <a href="https://tobmycin.com/">order tobra 10mg online cheap</a> buy tobra drops
Fqsiou
buy generic griseofulvin for sale - <a href="https://fulviseoful.com/">pill griseofulvin</a> pill lopid 300mg
Tkkgjk
dapagliflozin over the counter - <a href="https://sineqpin.com/">buy cheap doxepin</a> buy acarbose 25mg online cheap
Qvltou
buy dramamine 50mg sale - <a href="https://bisacolax.com/">purchase dimenhydrinate generic</a> actonel pill
Klxeoq
vasotec pills - <a href="https://vasolapril.com/">enalapril 10mg canada</a> xalatan drug
Gmjkvl
buy etodolac - <a href="https://etodograph.com/">buy etodolac 600mg online</a> generic cilostazol
Cqqilz
buy piroxicam 20 mg online - <a href="https://feldexicam.com/">order piroxicam 20mg for sale</a> exelon brand
Esgjlh
order piracetam - <a href="https://nootquin.com/praziquantel/">praziquantel medication</a> sinemet over the counter
Vuvzyc
buy hydroxyurea - <a href="https://hydroydrinfo.com/trecatorsc/">buy trecator sc tablets</a> methocarbamol 500mg cheap
Ithydg
order depakote - <a href="https://adepamox.com/">order divalproex 250mg sale</a> topamax 100mg for sale
Ezqmeq
buy norpace online - <a href="https://anorpica.com/lamivudine/">buy epivir generic</a> buy thorazine 50 mg pills
Pbxtth
buy aldactone cheap - <a href="https://aldantinep.com/dosulepin/">buy prothiaden</a> cost revia 50mg
Laflea
cyclophosphamide online buy - <a href="https://cycloxalp.com/dimenhydrinate/">order dimenhydrinate 50 mg pills</a> buy vastarel generic
Sacxin
buy flexeril 15mg pills - <a href="https://abflequine.com/primaquine/">primaquine tablets</a> vasotec 10mg sale
Zgmguc
buy ondansetron generic - <a href="https://azofarininfo.com/oxybutynin/">oxytrol cheap</a> oral ropinirole
Bkihve
ascorbic acid order - <a href="https://mdacidinfo.com/lopinavirritonavir/">lopinavir ritonavir price</a> buy prochlorperazine medication
Dwvurp
order durex gel cheap - <a href="https://xalaplinfo.com/">purchase durex gel</a> buy latanoprost eye drops
Okkvrk
rogaine for sale online - <a href="https://hairlossmedinfo.com/finasteridefinp/">finpecia canada</a> proscar 5mg over the counter
Fzffqs
buy arava 10mg - <a href="https://infohealthybones.com/alfacalcidol/">cheap alfacip pills</a> cartidin oral
Mvqqeq
order calan 120mg generic - <a href="https://infoheartdisea.com/cardizem/">order diltiazem online</a> buy generic tenoretic over the counter
Smpluz
generic atenolol 100mg - <a href="https://heartmedinfox.com/clopidogrel/">buy clopidogrel 75mg generic</a> order carvedilol 6.25mg online
Inrkjr
purchase atorvastatin without prescription - <a href="https://infoxheartmed.com/enalapril/">vasotec 10mg pill</a> nebivolol us
Bsftea
buy gasex generic - <a href="https://herbalinfomez.com/diabecon/">buy diabecon pill</a> diabecon buy online
Mvrrom
lasuna tablets - <a href="https://infoherbalmz.com/">buy generic lasuna</a> purchase himcolin pills
Ujyker
cheap noroxin pills - <a href="https://gmenshth.com/flutamide/">buy eulexin generic</a> buy confido cheap
Iualku
speman pill - <a href="https://spmensht.com/finasteride/">fincar pills</a> buy fincar without a prescription
Xsiepy
buy finasteride generic - <a href="https://finmenura.com/doxazosin/">buy cardura paypal</a> uroxatral online
Arpcos
terazosin 1mg cheap - <a href="https://hymenmax.com/">buy generic terazosin 1mg</a> priligy 90mg cheap
Wnvjqf
oxcarbazepine 300mg us - <a href="https://trileoxine.com/">buy oxcarbazepine 300mg pill</a> generic synthroid 75mcg
Iwisms
cyclosporine us - <a href="https://asimusxate.com/gloperba/">gloperba brand</a> colcrys 0.5mg us
Mgoekw
duphalac canada - <a href="https://duphalinfo.com/betahistine/">buy betahistine 16 mg online cheap</a> buy betahistine cheap
Ahejfu
calcort tablets - <a href="https://lazacort.com/brimonidine/">purchase alphagan generic</a> purchase brimonidine sale
Rhuabq
besivance buy online - <a href="https://besifxcist.com/carbocysteine/">carbocysteine pill</a> buy sildamax tablets
Lthoxs
neurontin 800mg pill - <a href="https://aneutrin.com/">purchase neurontin for sale</a> azulfidine order online
Dpgyor
probenecid without prescription - <a href="https://bendoltol.com/monograph/">order monograph pills</a> carbamazepine sale
Vdgaoi
celebrex 200mg cheap - <a href="https://celespas.com/indomethacin/">indocin capsule</a> indocin 50mg pills
Beutpp
order colospa for sale - <a href="https://coloxia.com/pletal/">buy cilostazol 100 mg generic</a> cilostazol 100 mg usa
Wtdshb
voltaren online - <a href="https://dicloltarin.com/aspirin/">aspirin 75mg tablet</a> order aspirin 75mg pill
Uhkezs
cost rumalaya - <a href="https://rumaxtol.com/shallaki/">buy shallaki generic</a> buy generic endep
Pxcpnn
mestinon pills - <a href="https://mestonsx.com/">mestinon 60 mg ca</a> purchase imuran online
Yfcgco
buy generic voveran - <a href="https://vovetosa.com/animodipine/">nimotop price</a> order nimodipine online cheap
Bjufsn
cost baclofen 10mg - <a href="https://baclion.com/">order lioresal sale</a> piroxicam 20mg for sale
Ulbded
order generic meloxicam - <a href="https://meloxiptan.com/rtrizatriptan/">buy ketorolac pill</a> buy generic toradol
Mmhotx
cyproheptadine canada - <a href="https://periheptadn.com/aszanaflex/">buy tizanidine 2mg online cheap</a> tizanidine buy online
Gxwexv
buy artane for sale - <a href="https://voltapll.com/diclofenacgel/">emulgel order online</a> purchase voltaren gel
Qcyqhl
purchase omnicef without prescription - <a href="https://omnixcin.com/">buy generic cefdinir 300mg</a> cost clindamycin
Cclkvs
buy generic isotretinoin 10mg - <a href="https://aisotane.com/asavlosulfon/">avlosulfon where to buy</a> deltasone 40mg price
Rvkllt
order deltasone pills - <a href="https://apreplson.com/">deltasone brand</a> buy zovirax generic
Brufca
buy cheap permethrin - <a href="https://actizacs.com/tretinoin/">buy tretinoin gel online</a> tretinoin gel sale
Clnbye
purchase betamethasone generic - <a href="https://betnoson.com/awdifferin/">buy adapalene cream</a> buy benoquin paypal
Eietfj
metronidazole 200mg canada - <a href="https://cenforcevs.com/">brand cenforce</a> cenforce 50mg canada
Ghauul
cost augmentin - <a href="https://baugipro.com/">buy augmentin pill</a> buy levothyroxine without a prescription
Gbxcrj
order cleocin 150mg pills - <a href="https://clinycinpl.com/">purchase cleocin online cheap</a> cheap indocin
Srxteq
buy hyzaar without prescription - <a href="https://acephacrsa.com/">cephalexin 250mg pill</a> how to get cephalexin without a prescription
Virvqe
crotamiton generic - <a href="https://aeuracream.com/abactroban/">where to buy bactroban ointment without a prescription</a> order aczone sale
Sfqexi
order provigil 100mg sale - <a href="https://sleepagil.com/phenergan/">buy generic promethazine 25mg</a> melatonin order online
Umrukj
order xeloda generic - <a href="https://xelocap.com/danocrine/">order danazol online</a> cost danazol 100 mg
Plcxdn
purchase progesterone online - <a href="https://apromid.com/clomipheneferto/">where can i buy clomiphene</a> purchase clomiphene generic
Iepocd
buy alendronate 35mg online cheap - <a href="https://pilaxmax.com/tamoxifen/">tamoxifen 10mg usa</a> order medroxyprogesterone 5mg
Odlgyp
buy aygestin 5mg online cheap - <a href="https://norethgep.com/">buy aygestin no prescription</a> purchase yasmin sale
Mktxdg
cabergoline 0.5mg cost - <a href="https://adostilin.com/cabgolin/">cheap cabgolin for sale</a> order alesse
Tpsluv
正規品シルデナフィル錠の正しい処方 - <a href="https://jpedpharm.com/">タダラフィル通販おすすめ</a> タダラフィル通販 安全
Ovvtwi
プレドニンジェネリック 通販 - <a href="https://jpaonlinep.com/">正規品プレドニン錠の正しい処方</a> アジスロマイシン 飲み方
Bssewr
プレドニンジェネリック 通販 - <a href="https://jpanfarap.com/jpadoxycycline/">ドキシサイクリンジェネリック 通販</a> イソトレチノイン 市販 おすすめ