GitHub Action seeing dockerfile but no additional files or folders in the same location

Recently I was using the task docker/build-push-action@v2 to build and push docker image to Azure Container Registry, I encountered an error while using the task. The error specifically pointed to a failure referenced below:

buildx failed with: ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref a72cffd2-669d-40cb-bf47-1788485c85af::b218hbaww1e2zhk2gj5r3o10u: "/azure-vote": not found

Upon investigation, I discovered that the issue was rooted in the absence of the ‘azure-vote’ folder in the same location as my Dockerfile. The step in question looked like this:

    - name: Build the frontend image and push it to ACR
      uses: docker/build-push-action@v2
      with:
        push: true
        tags: acraksproduction.azurecr.io/votingappfrontend:${{ github.sha }}
        file: app/voting-app-frontend/Dockerfile

With reference to the above file is referencing the docker file, as below – it was evident that the ‘azurevote’ folder was indeed in the correct location.

What was missing

To address the issue and ensure that all the necessary files are included during the Docker image build, I needed to leverage the context parameter in the docker/build-push-action action. This parameter designates the build context – the directory containing the Dockerfile and any other essential files required during the build process.

Here’s an updated version of my GitHub Action that includes the context parameter:

- name: Build the frontend image and push it to ACR
  uses: docker/build-push-action@v2
  with:
    push: true
    tags: acraksproduction.azurecr.io/votingappbackend:${{ github.sha }}
    file: app/voting-app-frontend/Dockerfile
    context: app/voting-app-frontend

By setting the context parameter to app/voting-app-frontend, the action will include all the files in the app/voting-app-frontend directory when building the Docker image. Make sure that the necessary files are present in that directory before running the action.

Leave a Reply