GCP Cloud构建Docker是否删除了Dockerfile执行期间创建的文件?

发布于 2025-01-31 17:54:10 字数 1640 浏览 4 评论 0原文

我在Docker文件中有一个生成某些文件的构建步骤。由于我还需要本地(测试时)这些文件,因此我的生成不是在云构建中,而是在dockerfile中(通过NPX执行的简单节点脚本)。本地的工作非常好,我的docker映像确实包含那些生成的文件。但是,每当我将此Dockerfile插入云构建中时,它都会执行脚本,但不会将生成的文件保留在生成的图像中。我还扫描了日志等等,但没有发现错误(例如,掩盖错误或类似的内容)。

我这里是否有任何标志或我缺少的标志可以防止我的dockerfile生成这些文件并将其存储到图像中?

编辑:

部署管道是对运行云构建的github拉动请求的触发。之后,将图像推到工件注册表并运行云。在云运行本身上,文件消失了。我无法检查之间的步骤,但是当在本地构建文件时,这些文件将生成,并且图像在图像中持续存在。

dockerfile

FROM node:16

ARG ENVIRONMENT
ARG GOOGLE_APPLICATION_CREDENTIALS
ARG DISABLE_CLOUD_LOGGING
ARG DISABLE_CONSOLE_LOGGING
ARG GIT_ACCESS_TOKEN

WORKDIR /usr/src/app

COPY ./*.json ./
COPY ./src ./src
COPY ./build ./build

ENV ENVIRONMENT="${ENVIRONMENT}"
ENV GOOGLE_APPLICATION_CREDENTIALS="${GOOGLE_APPLICATION_CREDENTIALS}"
ENV DISABLE_CLOUD_LOGGING="${DISABLE_CLOUD_LOGGING}"
ENV DISABLE_CONSOLE_LOGGING="${DISABLE_CONSOLE_LOGGING}"

ENV PORT=8080

RUN git config --global url."https://${GIT_ACCESS_TOKEN}@github.com".insteadOf "ssh://[email protected]"
RUN npm install

RUN node ./build/generate-files.js
RUN rm -rf ./build

EXPOSE 8080

ENTRYPOINT  [ "node", "./src/index.js" ]

云构建(在正常部署云运行的东西之前和之后的东西)

...
- name: 'gcr.io/cloud-builders/docker'
  entrypoint: 'bash'
  args: [ '-c', 'docker build --build-arg ENVIRONMENT=${_ENVIRONMENT} --build-arg  DISABLE_CONSOLE_LOGGING=true --build-arg GIT_ACCESS_TOKEN=$$GIT_ACCESS_TOKEN -t location-docker.pkg.dev/$PROJECT_ID/atrifact-registry/docker-image:${_ENVIRONMENT} ./' ]
  secretEnv: ['GIT_ACCESS_TOKEN']
...

I have a build step in the docker file that generates some files. Since I also need those files locally (when testing) I have the generation of them not in Cloud Build itself but in the Dockerfile (simple node script that executes via npx). Locally this works perfectly fine and my Docker image does contain those generated files. But whenever I throw this Dockerfile into Cloud Build it executes the script but it does not keep the generated files in the resulting image. I also scanned the logs and so on but found no error (such as a persission error or something similar).

Is there any flag or something I am missing here that prevents my Dockerfile from generating those files and storing them into the image?

Edit:

Deployment pipeline is a trigger onto a GitHub pull request that runs the cloud build.yaml in which the docker build command is located. Afterwards the image is getting pushed to the Artifact Registry and to Cloud Run. On Cloud Run itself the files are gone. Steps in-between I can't check but when building locally the files are getting generated and they are persistent in the image.

Dockerfile

FROM node:16

ARG ENVIRONMENT
ARG GOOGLE_APPLICATION_CREDENTIALS
ARG DISABLE_CLOUD_LOGGING
ARG DISABLE_CONSOLE_LOGGING
ARG GIT_ACCESS_TOKEN

WORKDIR /usr/src/app

COPY ./*.json ./
COPY ./src ./src
COPY ./build ./build

ENV ENVIRONMENT="${ENVIRONMENT}"
ENV GOOGLE_APPLICATION_CREDENTIALS="${GOOGLE_APPLICATION_CREDENTIALS}"
ENV DISABLE_CLOUD_LOGGING="${DISABLE_CLOUD_LOGGING}"
ENV DISABLE_CONSOLE_LOGGING="${DISABLE_CONSOLE_LOGGING}"

ENV PORT=8080

RUN git config --global url."https://${GIT_ACCESS_TOKEN}@github.com".insteadOf "ssh://[email protected]"
RUN npm install

RUN node ./build/generate-files.js
RUN rm -rf ./build

EXPOSE 8080

ENTRYPOINT  [ "node", "./src/index.js" ]

Cloud Build (stuff before and after is just normal deployment to Cloud Run stuff)

...
- name: 'gcr.io/cloud-builders/docker'
  entrypoint: 'bash'
  args: [ '-c', 'docker build --build-arg ENVIRONMENT=${_ENVIRONMENT} --build-arg  DISABLE_CONSOLE_LOGGING=true --build-arg GIT_ACCESS_TOKEN=$GIT_ACCESS_TOKEN -t location-docker.pkg.dev/$PROJECT_ID/atrifact-registry/docker-image:${_ENVIRONMENT} ./' ]
  secretEnv: ['GIT_ACCESS_TOKEN']
...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丿*梦醉红颜 2025-02-07 17:54:10

我发现了。以某种方式,构建过程崩溃运行语句时不会失败。这导致我认为没有问题,而实际上它无法授权我的一代脚本。将添加到docker build命令命令修复了授权问题。

I figured it out. Somehow the build process does not fail when crashing a RUN statement. This lead to me thinking there are no problem, when in fact it could not authorize my generation script. Adding --network=cloudbuild to the docker build command fixed the authorization problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文