Cov ntsiab lus-raws li tagging hauv werf builder: vim li cas thiab nws ua haujlwm li cas?

Cov ntsiab lus-raws li tagging hauv werf builder: vim li cas thiab nws ua haujlwm li cas?

werf yog peb qhov chaw qhib GitOps CLI kev siv hluav taws xob rau kev tsim thiab xa cov ntawv thov rau Kubernetes. IN tso tawm v1.1 ib tug tshiab feature tau qhia nyob rau hauv cov duab collector: tagging dluab los ntawm cov ntsiab lus los yog cov ntsiab lus raws li tagging. Txog tam sim no, cov txheej txheem tagging ib txwm nyob rau hauv werf koom nrog tagging Docker dluab los ntawm Git tag, Git ceg lossis Git cog lus. Tab sis tag nrho cov tswv yim no muaj qhov tsis zoo uas daws tau tag nrho los ntawm lub tswv yim tshiab tagging. Paub meej txog nws thiab yog vim li cas nws thiaj li zoo nyob rau hauv lub txiav.

Rolling tawm ib txheej ntawm microservices los ntawm ib qho chaw cia Git

Ib qho xwm txheej feem ntau tshwm sim thaum daim ntawv thov raug muab faib ua ntau dua lossis tsawg dua kev pabcuam ywj pheej. Kev tso tawm ntawm cov kev pabcuam no tuaj yeem tshwm sim ntawm nws tus kheej: ib lossis ntau qhov kev pabcuam tuaj yeem tso tawm ib zaug, thaum tus so yuav tsum ua haujlwm txuas ntxiv yam tsis muaj kev hloov pauv. Tab sis los ntawm qhov pom ntawm cov lej khaws cia thiab kev tswj xyuas qhov project, nws yooj yim dua los khaws cov kev pabcuam hauv ib qho chaw cia.

Muaj cov xwm txheej thaum cov kev pabcuam muaj kev ywj pheej tiag tiag thiab tsis cuam tshuam nrog ib daim ntawv thov. Nyob rau hauv cov ntaub ntawv no, lawv yuav nyob rau hauv nyias muaj nyias tej yaam num thiab lawv tso tawm yuav ua los ntawm cais cov txheej txheem CI / CD nyob rau hauv txhua qhov project.

Txawm li cas los xij, hauv kev muaj tiag, cov neeg tsim khoom feem ntau faib ib daim ntawv thov mus rau ntau lub microservices, tab sis tsim kom muaj ib qho chaw cia thiab qhov project rau txhua qhov ... yog qhov tseeb tshaj. Nws yog qhov xwm txheej no uas yuav tau tham ntxiv: ob peb lub microservices nyob rau hauv ib qhov project repository thiab tso tawm tshwm sim los ntawm ib tug txheej txheem nyob rau hauv CI / CD.

Tag los ntawm Git ceg thiab Git tag

Cia peb hais tias qhov zoo tshaj plaws tagging yog siv - tag-or- ceg. Rau cov ceg ntawm Git, cov duab tau sau nrog lub npe ntawm ceg, rau ib ceg ntawm ib lub sijhawm tsuas muaj ib daim duab luam tawm los ntawm lub npe ntawm ceg. Rau Git tags, dluab yog tagged raws li lub npe tag.

Thaum ib daim ntawv Git tshiab raug tsim - piv txwv li, thaum ib qho tshiab raug tso tawm - Docker tag yuav raug tsim rau txhua qhov project duab hauv Docker Registry:

  • myregistry.org/myproject/frontend:v1.1.10
  • myregistry.org/myproject/myservice1:v1.1.10
  • myregistry.org/myproject/myservice2:v1.1.10
  • myregistry.org/myproject/myservice3:v1.1.10
  • myregistry.org/myproject/myservice4:v1.1.10
  • myregistry.org/myproject/myservice5:v1.1.10
  • myregistry.org/myproject/database:v1.1.10

Cov npe duab tshiab no tau dhau los ntawm Helm templates rau Kubernetes configuration. Thaum pib qhov kev xa tawm nrog cov lus txib werf deploy teb tau kho tshiab image hauv Kubernetes cov peev txheej manifests thiab rov pib dua cov peev txheej sib xws vim hloov lub npe duab.

teeb meem: nyob rau hauv rooj plaub thaum, qhov tseeb, cov ntsiab lus ntawm daim duab tsis tau hloov txij li thaum yav dhau los rollout (Git tag), tab sis tsuas yog nws Docker tag, qhov no tshwm sim. ntxiv restarting daim ntawv thov no thiab, raws li, qee qhov downtime yog ua tau. Txawm hais tias tsis muaj laj thawj tiag los ua qhov kev rov pib dua no.

Yog li ntawd, nrog rau tam sim no tagging tswv yim nws yog tsim nyog rau laj kab ob peb cais Git repositories thiab cov teeb meem tshwm sim ntawm lub rollout ntawm ob peb repositories. Feem ntau, xws li ib tug tswvyim hloov mus rau overloaded thiab complex. Nws yog qhov zoo dua los muab ntau cov kev pabcuam rau hauv ib qho chaw cia khoom thiab tsim Docker tags kom tsis muaj qhov tsim nyog rov pib dua.

Tagging los ntawm Git commit

werf kuj tseem muaj lub tswv yim tagging txuam nrog Git commits.

Git-commit yog tus cim rau cov ntsiab lus ntawm Git repository thiab nyob ntawm qhov hloov kho keeb kwm ntawm cov ntaub ntawv hauv Git repository, yog li nws zoo nkaus li siv nws rau tagging dluab hauv Docker Registry.

Txawm li cas los xij, tagging los ntawm Git commit muaj qhov tsis zoo ib yam li tagging los ntawm Git ceg lossis Git tags:

  • Kev cog lus khoob tuaj yeem tsim uas tsis hloov cov ntaub ntawv, tab sis Docker tag ntawm daim duab yuav raug hloov.
  • Kev sib koom ua ke tuaj yeem tsim tau uas tsis hloov cov ntaub ntawv, tab sis Docker tag ntawm daim duab yuav raug hloov.
  • Kev cog lus tuaj yeem ua kom hloov cov ntaub ntawv hauv Git uas tsis tuaj yeem nkag rau hauv daim duab, thiab Docker lossis daim duab yuav raug hloov dua.

Tagging Git ceg npe tsis cuam tshuam cov duab version

Muaj lwm qhov teeb meem cuam tshuam nrog lub tswv yim tagging rau Git ceg.

Tag los ntawm ceg npe ua haujlwm ntev npaum li qhov kev cog lus ntawm ceg ntawd raug sau ua ntu zus raws sijhawm.

Yog hais tias nyob rau hauv lub tswv yim tam sim no tus neeg siv pib rov tsim dua ib qho kev cog lus qub uas cuam tshuam nrog qee ceg, ces werf yuav rov sau cov duab uas siv cov Docker tag nrog cov tshiab tsim cov duab rau cov qub kev cog lus. Kev xa tawm siv cov cim npe no txij li tam sim no mus khiav txoj kev pheej hmoo ntawm rub tawm cov duab sib txawv thaum rov pib dua cov pods, vim tias peb daim ntawv thov yuav poob kev sib txuas nrog CI system thiab ua desynchronized.

Tsis tas li ntawd, nrog kev sib tw ua tiav rau hauv ib ceg nrog lub sijhawm luv luv ntawm lawv, qhov kev cog lus qub tuaj yeem muab tso ua ke tom qab tshaj qhov tshiab: cov ntawv qub ntawm daim duab yuav hla tus tshiab siv Git ceg tag. Cov teeb meem zoo li no tuaj yeem daws tau los ntawm CI / CD system (piv txwv li, hauv GitLab CI cov kav dej tom qab tau pib ua haujlwm rau ntau qhov kev cog lus). Txawm li cas los xij, tsis yog txhua lub tshuab txhawb nqa qhov no thiab yuav tsum muaj txoj hauv kev txhim khu kev qha ntxiv los tiv thaiv qhov teeb meem tseem ceeb.

Cov ntsiab lus raws li tagging yog dab tsi?

Yog li, dab tsi yog cov ntsiab lus-raws li tagging - tagging dluab los ntawm cov ntsiab lus.

Txhawm rau tsim Docker tags, nws tsis yog Git primitives (Git ceg, Git tag ...) uas siv, tab sis ib qho kev txheeb xyuas cuam tshuam nrog:

  • cov ntsiab lus ntawm daim duab. Daim duab ID tag qhia txog nws cov ntsiab lus. Thaum tsim ib qho tshiab, tus cim no yuav tsis hloov yog tias cov ntaub ntawv hauv daim duab tsis tau hloov pauv;
  • keeb kwm ntawm kev tsim cov duab no hauv Git. Cov duab cuam tshuam nrog cov ceg sib txawv Git thiab sib txawv tsim keeb kwm ntawm werf yuav muaj cov cim ID sib txawv.

Xws li tus cim cim npe yog qhov hu ua duab theem kos npe.

Txhua daim duab muaj ib txheej ntawm theem: from, before-install, git-archive, install, imports-after-install, before-setup... git-latest-patch lwm. Txhua theem muaj tus cim uas qhia txog nws cov ntsiab lus - theem kos npe (theem kos npe).

Daim duab kawg, suav nrog cov theem no, yog tag nrog lub npe kos npe ntawm cov txheej txheem ntawm cov theem no - theem kos npe, - uas yog generalizing rau txhua theem ntawm daim duab.

Rau txhua daim duab los ntawm kev teeb tsa werf.yaml Hauv cov ntaub ntawv dav dav, yuav muaj nws tus kheej kos npe thiab, raws li, Docker tag.

The stage signature daws tag nrho cov teeb meem no:

  • Resistant rau khoob Git commits.
  • Resistant rau Git cog lus tias hloov cov ntaub ntawv uas tsis cuam tshuam rau daim duab.
  • Tsis ua rau muaj teeb meem ntawm kev kho dua tshiab ntawm daim duab tam sim no thaum rov pib ua dua tshiab rau Git qub ua haujlwm ntawm ib ceg.

Qhov no yog tam sim no qhov pom zoo tagging tswv yim thiab yog lub neej ntawd nyob rau hauv werf rau tag nrho cov CI systems.

Yuav ua li cas pab thiab siv hauv werf

Cov lus txib tam sim no muaj cov kev xaiv sib xws werf publish: --tag-by-stages-signature=true|false

Hauv CI system, tagging zoo yog teev los ntawm cov lus txib werf ci-env. Yav dhau los, tus parameter tau txhais rau nws werf ci-env --tagging-strategy=tag-or-branch. Tam sim no, yog tias koj qhia werf ci-env --tagging-strategy=stages-signature lossis tsis qhia qhov kev xaiv no, werf yuav siv lub tswv yim tagging los ntawm lub neej ntawd stages-signature. Koj werf ci-env yuav cia li teeb tsa tus chij tsim nyog rau cov lus txib werf build-and-publish (los yog werf publish), yog li tsis muaj kev xaiv ntxiv yuav tsum tau teev tseg rau cov lus txib no.

Piv txwv li, cov lus txib:

werf publish --stages-storage :local --images-repo registry.hello.com/web/core/system --tag-by-stages-signature

... tuaj yeem tsim cov duab hauv qab no:

  • registry.hello.com/web/core/system/backend:4ef339f84ca22247f01fb335bb19f46c4434014d8daa3d5d6f0e386d
  • registry.hello.com/web/core/system/frontend:f44206457e0a4c8a54655543f749799d10a9fe945896dab1c16996c6

nws yog 4ef339f84ca22247f01fb335bb19f46c4434014d8daa3d5d6f0e386d yog kos npe rau theem ntawm daim duab backendthiab f44206457e0a4c8a54655543f749799d10a9fe945896dab1c16996c6 - kos npe ntawm cov duab theem frontend.

Thaum siv cov haujlwm tshwj xeeb werf_container_image ΠΈ werf_container_env Tsis tas yuav hloov dab tsi hauv Helm templates: cov haujlwm no yuav cia li tsim cov duab kos npe raug.

Piv txwv configuration hauv CI system:

type multiwerf && source <(multiwerf use 1.1 beta)
type werf && source <(werf ci-env gitlab)
werf build-and-publish|deploy

Xav paub ntau ntxiv txog kev teeb tsa muaj nyob hauv cov ntaub ntawv:

Tag nrho

  • Kev xaiv tshiab werf publish --tag-by-stages-signature=true|false.
  • Tshiab xaiv tus nqi werf ci-env --tagging-strategy=stages-signature|tag-or-branch (yog tias tsis tau teev tseg, lub neej ntawd yuav yog stages-signature).
  • Yog tias koj yav tas los siv cov kev xaiv tagging rau Git commits (WERF_TAG_GIT_COMMIT los yog kev xaiv werf publish --tag-git-commit COMMIT), ces nco ntsoov hloov mus rau tagging zoo theem-kos npe.
  • Nws yog qhov zoo dua los hloov cov phiaj xwm tshiab tam sim rau qhov tshiab tagging tswv yim.
  • Thaum hloov mus rau werf 1.1, nws raug nquahu kom hloov cov haujlwm qub rau cov phiaj xwm tshiab tagging, tab sis cov qub. tag-or- ceg tseem txhawb nqa.

Cov ntsiab lus-raws li tagging daws txhua yam teeb meem hauv kab lus:

  • Docker tag lub npe tiv thaiv rau khoob Git ua txhaum.
  • Resilience ntawm Docker tag lub npe rau Git ua txhaum uas hloov cov ntaub ntawv tsis cuam tshuam rau daim duab.
  • Tsis ua rau muaj teeb meem ntawm kev kho dua tshiab ntawm cov duab tam sim no thaum rov pib tsim rau cov qub Git cog lus rau Git ceg.

Siv nws! Thiab tsis txhob hnov ​​qab mus xyuas peb ntawm GitHublos tsim ib qho teeb meem lossis nrhiav ib qho uas twb muaj lawm, ntxiv ib qho ntxiv, tsim PR lossis tsuas yog saib qhov kev txhim kho ntawm qhov project.

PS

Nyeem kuj ntawm peb blog:

Tau qhov twg los: www.hab.com

Ntxiv ib saib