有没有办法用github动作插件docker/build-push-action@v1来设置docker构建的路径

eqqqjvef  于 2022-11-03  发布在  Docker
关注(0)|答案(3)|浏览(175)

我有一个码头建造行动如下

- 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

dockerfile包含将几个文件添加到docker映像的说明,如下所示

ADD file1 .
ADD file2 .
ADD file3 .

github的结构是:

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

问题是GitHub操作无法找到file 1file 2file 3,因为它正在folder 1级别中查找。生成的错误为

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

我不想把dockerfile中的路径修改为ADD ./folder1/folder2/file1 .。那么我该如何使用docker/build-push-action@v1从GitHub Action部分添加路径或更改目录呢?

goucqfw6

goucqfw61#

不要使用docker/build-push-action@v1,而是使用docker/build-push-action@v2,因为v1是一个较旧的版本。

- 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@v2
        with:
          context: ./folder1/folder2/docker/
          tags: tag
          push: true
          dockerfile: ./<path-to-dockerfile>/Dockerfile

在github操作中使用context可以解决这个问题。Context仅在v2版本中可用。

kx1ctssn

kx1ctssn2#

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

nbnkbykc3#

context: "{{defaultContext}}:subdirectory"

https://github.com/docker/build-push-action#git-context

相关问题