在Azure DevOps(Angular+ API)中交换插槽,如何更改目标插槽的角配置?

发布于 2025-01-26 20:37:39 字数 1362 浏览 3 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明月松间行 2025-02-02 20:37:39

编辑(17/05/2022):我将原始提案保留为参考(下图),但我必须警告说,如果使用替换文件,它将默默失败。这可能大部分时间发生。

由于这个问题,我们已经改变了策略:

  1. 我们通过分期变量部署分期来进行适当的测试(自动化E2E)。
  2. 在我们对结果感到满意之后,我们再次部署了分期,但是使用了产品变量。我们称此工作步骤:“预生产”。
  3. 准备就绪后,我们将其交换为产品。
- stage: STAGING
  jobs:
    - template: release-to.yml
      parameters:
        environment: staging
        variables: staging

- stage: Release_PRE_PROD
  dependsOn: Release_STAGING
  jobs:
    - template: release-to.yml
      parameters:
        environment: staging
        variables: production

- stage: Swap_PROD
  dependsOn: Release_PRE_PROD
  #Your swap steps

内部释放到yml,我们执行适当的变量负载和替换。

希望它有帮助!

在17/05/2022之前作为参考
在测试了不同的方法之后,我们找到了以下方法:

  1. 在构建阶段产生特定于产品的文件。该文件将被放置为单独的工件。例如,这个想法是要使“构建”和“ prod and ancular配置”工件,例如:
      - publish: $(Build.artifactstagingdirectory)/Config
        displayName: 'Publish config'
        artifact: ConfigPROD

      - publish: $(Build.artifactstagingdirectory)/Build
        displayName: 'Publish build'
        artifact: BUILD
  1. 将构建伪像分期用于分期后,下载configprod伪像使用FTP进行分期。这将覆盖现有的(分期)配置。
    - task: DownloadPipelineArtifact@2
      displayName: 'Download config artifact'
      inputs:
        buildType: 'specific'
        project: [your devops project name]
        definition: [your build definition name]
        artifactName: 'ConfigPROD'
        path: '$(Pipeline.Workspace)/config'

    - task: FtpUpload@2
      displayName: 'Deploy configPROD'
      inputs:
        credentialsOption: 'inputs'
        serverUrl: [your ftp server url]
        username: [your ftp username]
        password: [your ftp password]
        rootDirectory: '$(Pipeline.Workspace)/config'
        filePatterns: '**' 
        remoteDirectory: [your remote directory] 
        clean: false 
        cleanContents: false
  1. 交换阶段到prod
    - task: AzureAppServiceManage@0
      displayName: 'Swap STAGING and PROD'
      inputs:
        azureSubscription: [your azure subscription]
        Action: 'Swap Slots'
        WebAppName: [your app name]
        ResourceGroupName: [your rg name]
        SourceSlot: 'staging'
  • 如果您想知道如何在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:

  1. we deploy STAGING with STAGING variables to do a proper testing (automated E2E).
  2. After we are happy with the outcome, we deploy STAGING again, but with PROD variables. We call this Job step: "PRE-PROD".
  3. When PRE-PROD is ready, we swap it to PROD.
- stage: STAGING
  jobs:
    - template: release-to.yml
      parameters:
        environment: staging
        variables: staging

- stage: Release_PRE_PROD
  dependsOn: Release_STAGING
  jobs:
    - template: release-to.yml
      parameters:
        environment: staging
        variables: production

- stage: Swap_PROD
  dependsOn: Release_PRE_PROD
  #Your swap steps

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:

  1. Produce a PROD specific file during build stage. This file will be put as a separate artifact. The idea is to have the "build" and the "PROD angular configuration" artifacts, for example:
      - publish: $(Build.artifactstagingdirectory)/Config
        displayName: 'Publish config'
        artifact: ConfigPROD

      - publish: $(Build.artifactstagingdirectory)/Build
        displayName: 'Publish build'
        artifact: BUILD
  1. After the BUILD artifact is deployed in STAGING, download the ConfigPROD artifact to STAGING using FTP. This will overwrite the existing (STAGING) configuration.
    - task: DownloadPipelineArtifact@2
      displayName: 'Download config artifact'
      inputs:
        buildType: 'specific'
        project: [your devops project name]
        definition: [your build definition name]
        artifactName: 'ConfigPROD'
        path: '$(Pipeline.Workspace)/config'

    - task: FtpUpload@2
      displayName: 'Deploy configPROD'
      inputs:
        credentialsOption: 'inputs'
        serverUrl: [your ftp server url]
        username: [your ftp username]
        password: [your ftp password]
        rootDirectory: '$(Pipeline.Workspace)/config'
        filePatterns: '**' 
        remoteDirectory: [your remote directory] 
        clean: false 
        cleanContents: false
  1. Swap STAGING to PROD
    - task: AzureAppServiceManage@0
      displayName: 'Swap STAGING and PROD'
      inputs:
        azureSubscription: [your azure subscription]
        Action: 'Swap Slots'
        WebAppName: [your app name]
        ResourceGroupName: [your rg name]
        SourceSlot: 'staging'
  • 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文