我知道有几个这样的帖子/问题,但没有回答。
我正在使用cloudbuild.yaml并从秘密管理器读取一个秘密值,并像这样传递它。
YAML文件
entrypoint: /bin/sh
args: ['-c', 'docker build -t gcr.io/$PROJECT_ID/portal:$SHORT_SHA-${_TARGET} --build-arg token=$$TOKEN . ']
...码头文件
ARG target=production
ARG token
COPY package*.json ./
COPY .npmrc .npmrc
RUN npm i -g @angular/cli
RUN npm i && mkdir /ng-app && cp -R ./node_modules ./ng-app
RUN rm -f .npmrc
WORKDIR /ng-app
COPY src ./src
COPY angular.json .
COPY tsconfig.json .
COPY tslint.json .
COPY protractor.conf.js .
RUN node --max_old_space_size=8192 $(npm --global bin)/ng build --configuration $target --source-map=true
....npmrc文件
@test:registry=https://packages.test.com/npm/js-licensed/
//packages.test.com/npm/js-licensed/:_auth=$token
...我的问题是,它从google秘密管理器获取值,当我从dockerfile中回送它时,它会填充到docker文件中,但是.npmrc永远不会得到值,因此$token是无效的。我做错了什么?
发布于 2021-04-15 17:12:58
仅仅复制文件并不能替换文件中的环境变量。如果这是自动发生的,那么您将永远无法正确地获得任何shell脚本,因为环境变量将被计算。
您将对Dockerfile所做的更改如下
ARG target=production
ARG token
COPY package*.json ./
ENV token=$token
COPY .npmrc .npmrc.env
RUN envsubst < .npmrc.env > .npmrc && cat .npmrc
RUN npm i -g @angular/cli
RUN npm i && mkdir /ng-app && cp -R ./node_modules ./ng-app
RUN rm -f .npmrc
WORKDIR /ng-app
COPY src ./src
COPY angular.json .
COPY tsconfig.json .
COPY tslint.json .
COPY protractor.conf.js .
RUN node --max_old_space_size=8192 $(npm --global bin)/ng build --configuration $target --source-map=truehttps://stackoverflow.com/questions/67068162
复制相似问题