ʹÓà GitOps ³¹µ×¸Ä±äÄúµÄ MuleSoft °²ÅÅ
ÕªÒªmulesoft ×÷Ϊ¼¯³Éƽ̨£¬Í¨¹ýʹÓà gitops ÔÔò£¬×éÖ¯¿ÉÒÔʵÏÖ¸ü¿ì¡¢¸ü¿É¿¿µÄ mulesoft °²ÅÅ¡£gitops ÊÇÒ»ÖÖͨ¹ýÒÀÀµ git ´æ´¢¿âÀ´¿ØÖÆ»ù´¡¼Ü¹¹ºÍÓ¦ÓóÌÐòµÄ°²ÅÅÒªÁì¡£ÔÚ mulesoft ÖÐʵÑé gitops ÌṩÁËÐí¶àÓÅÊÆ£¬°üÀ¨Ò»ÖÂÐÔ¡¢×Ô¶¯»¯¡¢¿É×·ËÝÐԺ͸ü¿ìµÄ°²ÅÅ¡£±¾Ö¸ÄϸÅÊöÁËʹÓà gitops ʵÏÖ mulesoft °²Åŵķֲ½Á÷³Ì£¬°üÀ¨½ç˵ÉèÖá¢ÔÚ git ÖоÙÐа汾¿ØÖÆ¡¢×Ô¶¯»¯°²ÅÅÒÔ¼°¼àÊÓºÍÑéÖ¤¡£Í¨¹ý½ÓÄÉ gitops£¬×éÖ¯¿ÉÒÔÌá¸ß mulesoft °²ÅŵÄЧÂʺͿɿ¿ÐÔ£¬´Ó¶øÔÚÒ»Ö±Éú³¤µÄ¼¯³ÉÁìÓòÖÐÈ¡µÃÀֳɡ£
ÔÚ¶¯Ì¬¼¯³ÉÌìÏÂÖУ¬MuleSoft×÷Ϊһ¸öÇ¿Ê¢µÄƽ̨ÍÑÓ±¶ø³ö£¬Ëü²»µ«Äܹ»½âËø¹Å°åϵͳ¡¢ÔÆÓ¦ÓóÌÐòºÍ×°±¸Ö®¼äµÄÊý¾Ý£¬»¹ÄÜ×ö³ö¸üÖÇÄÜ¡¢¸ü¿ìËٵľöÒ飬²¢Îª×îÖÕÓû§Ìṩ¸ß¶È»¥ÁªµÄÌåÑé¡£Ëæ×Å×éÖ¯Æð¾¢ÊµÏÖ¸ü¿ì¡¢¸ü¿É¿¿µÄ°²ÅÅ£¬GitOps µÄ½ÓÄÉÕýÔڸıäÎÒÃÇÖÎÀíºÍ×Ô¶¯»¯ MuleSoft °²Åŵķ½·¨¡£ÔÚÕâƪ²©ÎÄÖУ¬ÎÒÃǽ«Ì½ÌÖÔõÑù½«GitOpsµÄÔÔòÓ¦ÓÃÓÚÎÒÃÇµÄ MuleSoft °²ÅÅÁ÷³Ì¡£
ʲôÊÇ GitOps£¿
GitOps ÊÇÒ»ÖÖͨ¹ýÒÀÀµ Git ´æ´¢¿â×÷ΪÖ÷ÒªÐÅϢȪԴÀ´¿ØÖÆ»ù´¡¼Ü¹¹ºÍÓ¦ÓóÌÐò°²ÅŵÄÐÂÒªÁ졣ͨ¹ý½«ÉèÖÃÎļþ´æ´¢ÔÚ Git ´æ´¢¿âÖУ¬ÍŶӿÉÒÔ¸üºÃµØ¼àÊÓ¡¢Í¸Ã÷ºÍ¸ú×ÙÆä°²ÅÅÁ÷³Ì¡£GitOps ÔÔòÓÅÏÈ˼Á¿ÉùÃ÷ÐÔÉèÖúÍ×Ô¶¯»¯ÊÂÇéÁ÷³Ì£¬ÒÔʵÏÖÒ»ÖÂÇÒ¿É¿¿µÄ°²ÅÅ¡£
MuleSoft µÄÇ¿Ê¢¹¦Ð§
MuleSoft ÊÇÁìÏȵļ¯³Éƽ̨£¬Ìṩ¹¤¾ßºÍЧÀÍ£¬ÓÃÓÚ¿çÍâµØºÍÔÆÇéÐÎÅþÁ¬Ó¦ÓóÌÐò¡¢Êý¾ÝºÍ×°±¸¡£MuleSoft ÌṩÖÚ¶àÆóÒµ½â¾ö¼Æ»®£¬Ê¹ÆóÒµÄܹ»³ä·ÖʹÓÃ×Ô¶¯»¯ºÍ¼¯³É¡£ÒÀ¸½ÆäÇ¿Ê¢µÄAPI Ö÷µ¼ÅþÁ¬ÒªÁ죬MuleSoft ʹ×éÖ¯Äܹ»¹¹½¨¿ÉÀ©Õ¹ÇÒÎÞаµÄ¼¯³É½â¾ö¼Æ»®£¬²¢ÇÒ£¬Ëæ×ÅÆóÒµÔ½À´Ô½¶àµØ½ÓÄÉÏÖ´úÊÖÒÕ£¬²¢ÇÒ IT ËùÐèµÄ½»¸¶ËÙÂÊÒ»Ö±Ìá¸ß£¬¶Ô¸ßЧ°²ÅÅÕ½ÂÔµÄÐèÇó±äµÃÖÁ¹ØÖ÷Òª¡£
Ϊʲô MuleSoft ÐèÒª GitOps£¿
ÔÚ MuleSoft ³ÌÐòÖÐʵÑé GitOps ÒªÁìÓм¸¸öÒýÈËעĿµÄÓÅÊÆ£º
Ò»ÖÂÐÔ£ºGitOps ¿ÉÈ·±£ÄúµÄ°²ÅÅÉèÖÃÔÚËùÓÐÇéÐÎÖмá³ÖÒ»Ö¡£Í¨¹ýÔÚ Git ÖÐά»¤¼òµ¥ÊÂʵȪԴ£¬Äú¿ÉÒÔ×èÖ¹²î±ð²¢È·±£Í³Ò»ÐÔ¡£
×Ô¶¯»¯£ºGitOps ʹÓÃ×Ô¶¯»¯À´¼ò»¯°²ÅÅÁ÷³Ì¡£×Ô¶¯»¯¹ÜµÀ¿ÉÒÔƾ֤ Git ´æ´¢¿âÖеĸü¸Ä´¥·¢°²ÅÅ£¬´Ó¶øïÔÌÈ˹¤¸ÉÔ¤²¢×î´óÏ޶ȵØïÔ̹ýʧ¡£
¿É¼ûÐԺͿÉ×·ËÝÐÔ£º°²ÅÅÉèÖõÄÿ´Î¸ü¸Ä¶¼»áÔÚ Git ÖоÙÐа汾¿ØÖÆ£¬´Ó¶øÌṩÍêÕûµÄÐÞ¸ÄÀúÊ·¼Í¼¡£ÕâÖֿɼûÐÔ¿ÉÔöÇ¿ÍŶÓÄÚ²¿µÄÐ×÷ºÍÔðÈθС£
¸ü¿ìµÄ°²ÅÅ£ºÍ¨¹ý×Ô¶¯Ö´ÐÐÖظ´Ê¹Ãü²¢Ïû³ýÊÖ¶¯°ì·¨£¬GitOps ¼ÓËÙÁË°²ÅÅÀú³Ì£¬´Ó¶øÄܹ»¸ü¿ìµØ½»¸¶Ð¹¦Ð§ºÍ¸üС£
¸ÄÉÆÐ×÷£ºÍ¨¹ýʹÓà Git ×÷ΪΨһÊÂʵȪԴ£¬ÍŶӿÉÒÔ¸üÓÐÓõØÐ×÷£¬²¢ÇåÎúµØÏàʶ˾ÙÐÐÁ˸ü¸ÄÒÔ¼°ÎªÊ²Ã´¾ÙÐиü¸Ä¡£
ÔöÇ¿µÄÇå¾²ÐÔ£º°æ±¾¿ØÖƺÍ×Ô¶¯»¯°²ÅſɽµµÍÊÖ¶¯¹ýʧºÍδ¾ÊÚȨµÄ¸ü¸ÄµÄΣº¦£¬´Ó¶øÔöÇ¿°²ÅÅÀú³ÌµÄÕûÌåÇå¾²ÐÔ¡£
¿ÉÀ©Õ¹ÐÔ£ºGitOps ʹÄúÄܹ»ÖÎÀí¿ç¶à¸öÇéÐκÍÓ¦ÓóÌÐòµÄ°²ÅźÍÍŶӣ¬´Ó¶ø¸üÇáËɵØÀ©Õ¹ÄúµÄ¼¯³É½â¾ö¼Æ»®¡£
µ¯ÐÔ£º×Ô¶¯»Ø¹öºÍ»Ö¸´Àú³ÌÈ·±£ÄúÔÚ·ºÆðÎÊÌâʱ¿ÉÒÔ¿ìËÙ»Ö¸´µ½ÒÔÇ°µÄ״̬£¬´Ó¶øÌá¸ß°²Åŵĵ¯ÐÔ¡£
ʹÓà MuleSoft ʵÏÖ GitOps
ÒÔÏÂÊÇÕë¶ÔÄúµÄ MuleSoft °²ÅÅʵÑé GitOps ÒªÁìµÄ·Ö²½Ö¸ÄÏ¡£
½¨ÒéµÄ½â¾ö¼Æ»®»ùÓÚgbartolonifcg/mule-deployer-cliµÄʹÓã¬ÕâÊÇÒ»¸ö Docker Ó³Ïñ´ò°üµÄÏÂÁîÐй¤¾ß£¬Ö¼ÔÚ¼ò»¯½« MuleSoft Ó¦ÓóÌÐò°²Åŵ½ Anypoint Platform Runtime Plane£¨°üÀ¨ CloudHub 2.0£©µÄÀú³Ì¡£ËüʹÓÃmule-maven-pluginºÍDataWeave ÓïÑÔÀ´×Ô¶¯»¯ºÍе÷°²ÅÅÀú³Ì£¬Ê¹¿ª·¢Ö°Ô±Äܹ»ÇáËÉ°²ÅÅËûÃǵÄÓ¦ÓóÌÐò¡£
ÒÔÏÂÊÇʵÑé½â¾ö¼Æ»®µÄ×î»ù±¾°ì·¨¡£
1. ½ç˵ÄúµÄÉèÖÃ
½¨ÉèÒ»¸ö YAML Çåµ¥Îļþ£¬Ö¸¶¨ MuleSoft °²ÅŵÄÉèÖᣴËÎļþ±ØÐè°üÀ¨¹¤¼þ×ø±ê¡¢°²ÅÅÀàÐͺÍÌض¨ÓÚÇéÐεIJÎÊýµÈÏêϸÐÅÏ¢¡£
ÒÔÏÂÊÇ CloudHub 2.0 °²ÅŵÄʾÀýÇåµ¥£º
artifact: artifactId: example-mulesoft-app groupId: "com.example" version: 1.0.0deploymentType: cloudhub2Deploymentconfiguration: uri: https://eu1.anypoint.mulesoft.com/ muleVersion: "4.5.1" applicationName: example-mulesoft-app target: "your-target" provider: "your-provider" environment: Dev replicas: "1" vCores: "0.2" businessGroupId: "your-business-group-id" properties: env: dev anypoint.platform.base_uri: https://eu1.anypoint.mulesoft.com/ anypoint.platform.client_id: "your-client-id" secureProperties: anypoint.platform.client_secret: "your-client-secret" connectedAppClientId: "your-app-client-id" connectedAppClientSecret: "your-app-client-secret" connectedAppGrantType: "client_credentials" integrations: services: objectStoreV2: enabled: true deploymentSettings: generateDefaultPublicUrl: true http: inbound: publicURL: https://api-dev.example.com/example-mulesoft-app
µÇ¼ºó¸´ÖÆ
2. ÔÚ Git ÖжÔÉèÖþÙÐа汾¿ØÖÆ
½«ÄúµÄ YAML Çåµ¥ÎļþÌá½»µ½ Git ´æ´¢¿â¡£´Ë´æ´¢¿â½«×÷ΪÄúµÄ°²ÅÅÉèÖõÄΨһÕæʵȪԴ¡£
git add example-mulesoft-app.yamlgit commit -m "Add deployment manifest for example-mulesoft-app"git push origin main
µÇ¼ºó¸´ÖÆ
3.×Ô¶¯»¯°²ÅÅ
ÉèÖÃ×Ô¶¯»¯¹ÜµÀ£¬Æ¾Ö¤ Git ´æ´¢¿âÖеĸü¸Ä´¥·¢°²ÅÅ¡£¿ÉÒÔʹÓÃJenkins¡¢GitLab CI/CD»òGitHub ActionsµÈ¹¤¾ß½¨ÉèÊÂÇéÁ÷³Ì£¬ÔÚ¼ì²âµ½¸ü¸Äʱ°²ÅÅ MuleSoft Ó¦ÓóÌÐò¡£
ÏÂÃæÊÇÔõÑùÉèÖà GitHub Action À´´¥·¢°²ÅŵÄʾÀý¡£
# Example GitHub Actions workflowname: Deploy MuleSoft Applicationon: push: branches: - mainjobs: deploy: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Deploy to CloudHub 2.0 run: | docker run --rm -v $(pwd)/example-mulesoft-app.yaml:/deployment.yaml -it gbartolonifcg/mule-deployer-cli runtime-deploy
µÇ¼ºó¸´ÖÆ
4. ¼à¿ØºÍÑéÖ¤
°²Åźó£¬ÔÚ Anypoint Platform ÖмàÊÓÓ¦ÓóÌÐòÒÔÈ·±£Æä°´Ô¤ÆÚÔËÐС£ÑéÖ¤ÉèÖÃÊÇ·ñ׼ȷӦÓÃÒÔ¼°Ó¦ÓóÌÐòÊÇ·ñÕý³£ÔËÐС£
½áÂÛ
ʹÓà GitOps ÒªÁìÖÎÀí MuleSoft °²ÅÅ¿É´ó·ùÌá¸ßÔËӪЧÂÊ¡¢Ò»ÖÂÐÔºÍÇå¾²ÐÔ¡£Í¨¹ýʹÓà Git µÄÇ¿Ê¢¹¦Ð§¾ÙÐа汾¿ØÖƺÍʹÓÃÏÖ´ú CI/CD ¹¤¾ßµÄ×Ô¶¯»¯¹¦Ð§£¬Äú¿ÉÒÔʵÏÖ¸ü¿ì¡¢¸ü¿É¿¿¡¢¸üÇå¾²µÄ°²ÅÅ¡£½ÓÄÉÕâÖÖÁ¢ÒìÒªÁì¿ÉÒÔ³¹µ×¸Ä±äÄúµÄ MuleSoft °²ÅÅ£¬²¢ÔÚ¿ìËÙÉú³¤µÄ¼¯³ÉÁìÓò¼á³ÖÁìÏÈְλ¡£
ÒÔÉϾÍÊÇʹÓà GitOps ³¹µ×¸Ä±äÄúµÄ MuleSoft °²ÅŵÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡