Context error : Where does Azure CLI command run?

ghilas kasmi 41 Reputation points
2022-11-07T16:09:05.483+00:00

I'm actually setting up a devops environement using Github Actions and Microsoft Azure services. One of the steps i use in my pipeline is building a Docker image and pushing it to Azure Container Registry (ACR). To do that, i'm using the official action.

The problem is that when my Dockerfile is built , the server cannot find the path for the files i used in it.
To make it work, i tried to change the folder i passed to the action but with no result. Despite my Dockerfile is at the root of my project ( the default value in the action ), i get an error even when i'm explicitely giving the path.
I understood that the context of the server in which it runs is way different than mine. Knowing that in my workflow i build the project (to generate the JAR file) before trying to build the Docker image so the JAR file exists on the server which runs the workflow (Github server). I tried to debug the Build action, and the line which fails is 26 : az acr build ..., i'm actually 99% sure that all arguments are correct, but i still get the context error.

I tried to understand by myself and searched in the Azure CLI documentation but couldn't find the information. So now the question i'm asking myself is : does the az acr build run locally on the shell which called it (check scenario 1 image) ? or on an azure server which would explains why the server cannot find the JAR file (scenario 2) ?
And if it is scenario 2, is there a way to make pass the JAR file to az acr build and influence the server context ? Or should i ignore the official action and rewrite an action by myself which build the image locally not using the az acr build command ?

My Dockerfile (Spring Boot project) :

FROM openjdk:11  
  
COPY target/devOps-0.0.1-SNAPSHOT.jar devOps-0.0.1-SNAPSHOT.jar  
  
ENTRYPOINT ["java", "-jar", "/devOps-0.0.1-SNAPSHOT.jar"]   

The error i get :

Step 2/3 : COPY target/devOps-0.0.1-SNAPSHOT.jar devOps-0.0.1-SNAPSHOT.jar  
COPY failed: file not found in build context or excluded by .dockerignore: stat target/devOps-0.0.1-SNAPSHOT.jar: file does not exist  
2022/11/02 08:16:14 Container failed during run: build. No retries remaining.  
failed to run step ID: build: exit status 1  

Scenario 1 :

257948-azure-acrdrawio-1.png

Scenario 2 :

257869-azure-acrdrawio.png

Azure Container Registry
Azure Container Registry
An Azure service that provides a registry of Docker and Open Container Initiative images.
428 questions
0 comments No comments
{count} votes

Accepted answer
  1. Roderick Bant 2,051 Reputation points
    2022-11-07T18:58:29.773+00:00

    Hi, looking at the code behind the for the ACR build task you supplied, it seems that the ACR build is actually run with the link to your github repo as the context for the build. That will mean that the JAR resulting from your actual build will not be available within the context ACR is using at build time. (See here for an example of the command)

    This documentation here describes that you can see the result of the context being uploaded when you run the command (in that example case without a github link as the source).

    So i think your best option is to use a github azure cli action and run the acr build command with options to use the local directory as context.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful