【发布时间】:2020-01-14 06:49:51
【问题描述】:
您好,我正在 jenkins 工作以构建我的 AWS CDK 项目。我已经创建了我的 docker 文件,如下所示。
FROM python:3.7.4-alpine3.10
ENV CDK_VERSION='1.14.0'
RUN mkdir /cdk
COPY ./requirements.txt /cdk/
COPY ./entrypoint.sh /usr/local/bin/
COPY ./aws /cdk/
WORKDIR /cdk
RUN apk -uv add --no-cache groff jq less
RUN apk add --update nodejs npm
RUN apk add --update bash && rm -rf /var/cache/apk/*
RUN npm install -g aws-cdk
RUN pip3 install -r requirements.txt
RUN ls -la
ENTRYPOINT ["entrypoint.sh"]
RUN cdk synth
RUN cdk deploy
在 jenkins 中,我正在构建这个 Docker 映像,如下所示。
stages {
stage('Dev Code Deploy') {
when {
expression {
return BRANCH_NAME = 'Develop'
}
}
agent {
dockerfile {
additionalBuildArgs "--build-arg 'http_proxy=${env.http_proxy}' --build-arg 'https_proxy=${env.https_proxy}'"
filename 'Dockerfile'
args '-u root:root'
}
}
在上面的代码中我没有提供 AWS 凭证所以当 cdk synth 被执行时我得到错误Need to perform AWS calls for account 1234567 but no credentials found. Tried: default credentials.
在 jenkins 我有我的 AWS 凭证,我可以像这样访问它
steps {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding',credentialsId: "${env.PROJECT_ID}-aws-${env.ENVIRONMENT}"]]) {
sh 'ls -la'
sh "bash ./scripts/build.sh"
}
}
但是在构建 docker 映像时如何传递这些 credentialsId。有人可以帮我弄清楚。任何帮助,将不胜感激。谢谢
【问题讨论】:
-
请记住,您不应该将凭据存储在 Docker 映像中,因为每个人都可以在那里获取它们。凭据通常作为环境变量传递给 Docker 容器。
标签: python amazon-web-services docker jenkins aws-cdk