简体   繁体   English

AWS CodePipline & Codebuild - 如何向 Docker-Image 添加环境变量?

[英]AWS CodePipline & Codebuild - How to add environment variables to the Docker-Image?

thx for any help.谢谢任何帮助。

I'm using AWS-CodePipline with AWS-CodeBuild(for my Dockerfile and save it in ECR).我将 AWS-CodePipline 与 AWS-CodeBuild 一起使用(对于我的 Dockerfile 并将其保存在 ECR 中)。 So far it is working.到目前为止,它正在工作。 But I don't get how I get my environment variables in the project.但我不明白如何在项目中获取环境变量。 So I connected my Github account with CodePipline and I didn't pushed my envs to Github for security.所以我将我的 Github 帐户与 CodePipline 连接起来,为了安全起见,我没有将我的环境推送到 Github。 So now I have on Github a env-file like:所以现在我在 Github 上有一个 env 文件,如:

config/prod.env

ACCESS_TOKEN_SECRET=
CSRF_TOKEN_SECRET=
ACCESS_TOKEN_PASSWORD=
REFRESH_TOKEN_SECRET=
CLUDINARY_API=
CLUDINARY_API_SECRET=
CLUDINARY_API_NAME=
GOOGLE_AUDIENCE=
ORIGIN=
GOOGLE_TOKEN=
DATABASE_URL=
NODE_ENV=
FORGOTTEN_PASSWORD=
YAHOO_PASSWORD=

Now on AWS-CodeBilder is a section for environment variables(Image from AWS-Doc).现在 AWS-CodeBilder 上有一个环境变量部分(图片来自 AWS-Doc)。 在此处输入图像描述

Now I have the feeling this is not the right place for env's.现在我觉得这不是 env 的正确位置。 Because if I put all my variables inside the fields I get the error:因为如果我将所有变量都放在字段中,我会收到错误消息:

ValidationException
1 validation error detected: Value at 'pipeline.stages.2.member.actions.1.member.configuration' failed to satisfy constraint: Map value must satisfy constraint: [Member must have length less than or equal to 1000, Member must have length greater than or equal to 1]

On Example:关于示例:

Name: ACCESS_TOKEN_SECRET
Value: My_SUPER_PASSWORD

If I'm using just a few variables I don't get an error but for all variables I get the error(dosen't matter of the env-combination).如果我只使用几个变量,我不会得到错误,但对于所有变量,我都会得到错误(与 env 组合无关)。 What I'm doing wrong?我做错了什么? How can I get my env-variables to my Docker-Image in ECR with CodeBuild & CodePipline?如何使用 CodeBuild 和 CodePipline 将我的环境变量添加到 ECR 中的 Docker-Image?

To pass variables from Code Build Project, you need to set env: section in buildspec.yml file, for example要从 Code Build Project 传递变量,您需要在 buildspec.yml 文件中设置 env: 部分,例如

env:
  variables:
    Execution_ID: $Execution_ID
    Commit_ID: $Commit_ID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM