通过无服务器框架在azure devops管道(YAML)内部署next.js应用程序

问题描述 投票:0回答:1

我已经创建了next.js应用程序,并安装了无服务器框架,以便可以部署该应用程序。

我可以通过cli使用包含AWS凭证的.env文件或不使用.env文件但将我的AWS凭证位于本地.aws文件夹中的cli进行此操作。但是我无法将AWS凭证永久地放在根文件夹中,因为这会带来安全风险。

我现在需要实现的是将应用程序部署为Azure devops管道(YAML)的一部分。

我面临的挑战是将AWS凭证传递到无服务器部署中而不使其成为版本控制的一部分。

这是我的Yaml管道的当前状态。

trigger: none

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '12.x'
  displayName: 'Install Node.js'

- script: |
    npm install
    npx next build
    npx serverless
  displayName: 'npm install, build and deploy'
amazon-web-services azure-devops next.js serverless-framework
1个回答
0
投票

我面临的挑战是将AWS凭证传递到无服务器部署中而不使其成为版本控制的一部分。

您可以尝试将凭据作为Secure file上载到Azure Devops。然后,您可以直接使用Download secure file task下载凭据。

在这种情况下,安全文件将不属于Repo。

以下是步骤:

Step1:将凭据上传到Pipelines->库->安全文件。

Secure files

Step2:将Download secure file任务添加到Yaml定义。

例如:

- task: DownloadSecureFile@1
  displayName: 'Download secure file'
  inputs:
    secureFile: 'file name'

注意:安全文件将下载到$(Agent.TempDirectory)。构建完成后,该文件将被自动删除。

此外,如果要保留此文件或将其放在其他位置,则可以添加Copy file task

例如:

- task: CopyFiles@2
  displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
  inputs:
    SourceFolder: '$(Agent.TempDirectory)'
    TargetFolder: '$(build.artifactstagingdirectory)'

希望这会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.