简体   繁体   English

有没有办法使用 github 操作插件 docker/build-push-action@v1 为 docker build 设置路径

[英]Is there a way to set path for docker build with the github action plugin docker/build-push-action@v1

I have a docker build action as below我有一个 docker build 操作,如下所示

      - name: build-push
        uses: docker/build-push-action@v1
        with:
          username: ${{ DOCKER_USERNAME }}
          password: ${{ DOCKER_PASSWORD }}
          repository: <repo>
          tags: tag
          push: true
          dockerfile: ./<path-to-dockerfile>/Dockerfile

The dockerfile has instructions to ADD few files to the docker image as below dockerfile 有向 docker 镜像添加几个文件的说明,如下所示

ADD file1 .
ADD file2 .
ADD file3 .

the structure of github is: github的结构是:

-.github
-folder1------------
                   |
                   folder2-------------
                                       |
               -----------------------docker--------
               |             |           |          |
            file1          file2        file3      Dockerfile

The issue is that the GitHub action is unable to find file1 , file2 and file3 as it is looking in the level of folder1 .问题是 GitHub 操作无法找到file1file2file3 ,因为它在folder1级别中查找。 The error generated is产生的错误是

ADD failed: file not found in build context or excluded by .dockerignore: file1: file does not exist

I do not want to modify the path in dockerfile as ADD ./folder1/folder2/file1 .我不想将 dockerfile 中的路径修改为ADD ./folder1/folder2/file1 . . . So how do I add path or change directory from the GitHub Action part using docker/build-push-action@v1 ?那么如何使用 docker/build-push-action@v1 从 GitHub Action 部分添加路径或更改目录?

Instead of using docker/build-push-action@v1 use docker/build-push-action@v2 as v1 is an older version.不要使用 docker/build-push-action@v1 使用 docker/build-push-action@v2 因为 v1 是旧版本。 Modify the GitHub action as below修改GitHub动作如下

  - name: Login to Docker Hub
    uses: docker/login-action@v1
    with:
      username: ${{ secrets.DOCKER_USERNAME }
      password: ${{ secrets.DOCKER_PASSWORD }}
  - name: build-push
        uses: docker/build-push-action@v1
        with:
          context: ./folder1/folder2/docker/
          tags: tag
          push: true
          dockerfile: ./<path-to-dockerfile>/Dockerfile

using context with the github action will solve this issue.上下文与 github 操作一起使用将解决此问题。 Context is available only with v2 verison.上下文仅适用于 v2 版本。

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

相关问题 Github 操作:docker/build-push-action@v2 set network=host - Github action: docker/build-push-action@v2 set network=host 使用 docker/build-push-action@v3 github 操作,不会复制嵌套的隐藏文件夹 - Using docker/build-push-action@v3 github action, a nested hidden folder isn't copied Github 对 maven 构建的操作,然后是 Docker 构建推送 - Github Action to maven build followed by Docker build push GitHub 操作 - 使用 docker/build-push-action@v2 指定多个标签 - GitHub Actions - Specify Multiple Tags with docker/build-push-action@v2 使用 github-action 构建镜像并推送到 docker hub - Build image and push to docker hub using github-action 带有 docker/build-push-action 和 GitHub Actions 的生产环境文件 - Production ENV file with docker/build-push-action and GitHub Actions 使用 docker/build-push-action 在 GitHub Actions 中本地构建 docker 镜像 - Build docker image locally in GitHub Actions using docker/build-push-action Github 操作:构建和推送 docker 映像失败。 服务器消息:insufficient_scope:授权失败 - Github action: Build and push docker image fails. server message: insufficient_scope: authorization failed 如何缩短 docker build-push-action 映像名称 - How to shorten docker build-push-action image name 推送 docker 图像期间 Github 动作错误 - Github action error during push docker image
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM