在Azure DevOps(Angular+ API)中交换插槽,如何更改目标插槽的角配置?
Angular应用程序的配置是具有挑战性的部分。 在Azure YAML管道中的发布作业期间,我们执行“令牌”替换,以匹配令牌化攻击上此配置的目标环境。
稍后,我们将此令牌化的artifact(已替换为代币替换)将其部署到特定的环境中:
- task: AzureWebApp@1
inputs:
azureSubscription: 'xxxx'
appType: 'webApp'
appName: [depends on $(environment)]
package: '$(Pipeline.Workspace)/xxx'
这样,我们可以对开发,测试和分期进行特定的配置(分期是生产插槽)。
在某个时候,我们需要将分期交换为产品。 结果,我们在产品中具有Angular App,但具有值仍用于分期,这是不正确的,在这里我们坚持要做什么。 我想以一种很好的方式获得建议。
一些想法:
在分期部署期间,还使用不同的名称(即*。js.prod)生成产品文件。然后,在prod交换后,重命名文件,但是..
- 文件可能正在使用,因此无法重命名。
- 在重命名期间添加了一些停机时间(我什至不确定YAML是否有办法来重命名已部署的文件)。
触发部署到产品时,首先将其部署到使用prod变量的登台,然后执行交换,但是...
- 它将有更长的部署时间,因为即使已经部署了阶段,也必须首先部署。
- 它几乎没有利用插槽。
不要通过分期交换并进行完整的部署到prod,但是...
- 它将有最长的部署时间。
- 它不会利用插槽。
编辑:多亏了@prawin建议,我将添加另一个:
- 从服务器端提供配置
- 看起来很有希望,因为前端与服务器端共享主机。但是,在与后端部分脱钩的情况下,什么?这意味着也需要通过环境。 在某个地方配置后端URL
在阅读,反复试验和错误之后,我有更多:
仅使用FTP或Kudu API
部署更改文件生成并复制prod Config将prod Config划分,然后执行交换任务。 我最喜欢这个选项。<<<<<<<<, /p>
还有其他考虑吗?执行此操作的“标准”方法是什么?
The configuration of the Angular app is the challenging part.
During our publishing Job in Azure Yaml pipeline, we execute a "token" replacement to match the target environment on this configuration on a tokenized-artifact.
Later we deploy this tokenized-artifact (tokens already replaced) to the especific environment:
- task: AzureWebApp@1
inputs:
azureSubscription: 'xxxx'
appType: 'webApp'
appName: [depends on $(environment)]
package: '$(Pipeline.Workspace)/xxx'
This way, we can have specific configuration for DEV, TEST, and STAGING (staging is a Production slot).
At some point, we need to swap STAGING to PROD.
As result, we have the Angular app in PROD but with values are still for STAGING, which is incorrect, and here we are stuck on what to do.
I would like to get advice on a good way to continue.
Some ideas:
During the STAGING deployment, generate also the PROD files, using different name (i.e. main.*.js.PROD). Then, after PROD swap, rename the files, but..
- The files may be in use and, therefore, cannot be renamed.
- During rename a little downtime is added (I am not even sure if there is a way, for yaml, to rename the already deployed files).
When deploy to PROD is triggered, first deploy to STAGING with PROD variables, then execute the swap, but...
- It will have a longer deployment time, because STAGING will have to be deployed first, even if it is already deployed.
- It is taking little advantage of slots.
Do not swap from STAGING and do a complete deployment to PROD, but...
- It will have the longest deployment time.
- It will not take any advantage of slots.
Edit: Thanks to @prawin advice, I'll add another one:
- Provide configuration dinamically, from the server side
- Looks promising since the frontend shares a host with the server side. But still, what in the case of being decoupled from the backend part? This means that the backend url will also need to be configured somewhere, by environment.
After some reading, trial and error, I have some more:
Deploy only the changing file using FTP or Kudu API
Generate and copy PROD config to STAGING, then perform the swap task. I really like this option the most.
Is there anything else to consider? What is the "standard" way to perform this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑(17/05/2022):我将原始提案保留为参考(下图),但我必须警告说,如果使用替换文件,它将默默失败。这可能大部分时间发生。
由于这个问题,我们已经改变了策略:
内部释放到yml,我们执行适当的变量负载和替换。
希望它有帮助!
在17/05/2022之前作为参考
在测试了不同的方法之后,我们找到了以下方法:
如果您想知道如何在Azure中找到FTP凭据,这是:
[azureportal]/[appServICePage]/部署中心/部署凭证
[您的远程目录]可以使用kudu或“高级工具”中的控制台检查。在这种情况下,Angular wwwroot 在 site/wwwroot 内部,因此,我的远程目录是'/site/wwwroot/wwwroot/wwwroot '
'子弹,但正在工作100%,绝对没有额外的停机时间。
感谢您的兴趣
EDIT (17/05/2022): I keep the original proposal just as reference (below), but I must warn that it will fail silently if the file to replace is in use. This could happen most of the time.
Due to this problem, we have changed the strategy:
Inside release-to.yml, we perform the proper variable loads and replacements.
Hope it helps!
Before 17/05/2022 just as reference
After testing different approaches, we found the following way:
If you wonder how to find your ftp credentials in Azure, here is the path:
[AzurePortal]/[AppServicePage]/Deployment Center/Deployment Credentials
[your remote directory] can be checked using Kudu or the console in "Advanced Tools". In this case, the Angular wwwroot is inside site/wwwroot, therefore my remote directory is '/site/wwwroot/wwwroot'
Not a silver bullet, but is working 100% and there is absolutely not extra downtime.
Thanks for sugestions