简体   繁体   中英

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

      - 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

ADD file1 .
ADD file2 .
ADD file3 .

the structure of github is:

-.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 . 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 . . So how do I add path or change directory from the GitHub Action part using docker/build-push-action@v1 ?

Instead of using docker/build-push-action@v1 use docker/build-push-action@v2 as v1 is an older version. Modify the GitHub action as below

  - 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. Context is available only with v2 verison.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM