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

Deploying a next.js application, via the serverless framework, within an azure devops pipeline(YAML)

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

我可以通过 cli 使用包含 AWS 凭据的 .env 文件或没有 .env 文件但我的 AWS 凭据位于本地的 .aws 文件夹中来执行此操作。但是我不能将 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'

The challenge I'm facing is passing the AWS credentials to the serverless deployment without making it part of version control.

您可以尝试将凭据上传到 Azure Devops 作为 Secure file. Then you could directly use the Download secure file task 下载凭据。

在这种情况下,安全文件将不是 Repo 的一部分。

步骤如下:

第 1 步:将凭据上传到 Pipelines-> Library -> Secure files。

第 2 步:将 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)'

希望对您有所帮助。