Failed to build when dockerfile pulls containers from github container repository

I am trying to use a docker build that pulls in containers from the GitHub container repository and adds them to the built docker image. This works on my MacBook from the command shell but when I try to run it in CodeFresh, the build fails. The failure logs show that a username cannot be found. My build shell command is

docker build --build-arg GIT_USERNAME=$GIT_USERNAME --build-arg GIT_PERSONAL_ACCESS_TOKEN=$GIT_PERSONAL_ACCESS_TOKEN .

The CodeFresh documentation states that the equivalent of --build-arg is accomplished in CF by defining them in the yaml file as build_arguments. Here is how I am doing this in my yaml file:

`build:
    title: "Building Docker image"
    type: "build"
    image_name: “<“my image name>
    working_directory: "${{clone}}"
    tag: "ThisTag"
    #tag: "${{CF_BRANCH_TAG_NORMALIZED}}"
    dockerfile: "Dockerfile"
    build_arguments:
      - GIT_USERNAME=${{GIT_USERNAME}}
      - GIT_PERSONAL_ACCESS_TOKEN=${{GIT_PERSONAL_ACCESS_TOKEN}}
    stage: "build”`

With GIT_USERNAME and GIT_PERSONAL_ACCESS_TOKEN defined in the Variables section of the workflow.

My actual docker file looks a little like this:

`FROM ghcr.io/<my build environment container> AS build

WORKDIR /app
COPY . ./

ARG GIT_USERNAME
ARG GIT_PERSONAL_ACCESS_TOKEN
ENV GIT_USERNAME=$GIT_USERNAME
ENV GIT_PERSONAL_ACCESS_TOKEN=$GIT_PERSONAL_ACCESS_TOKEN

RUN <my test to ensure the environment is working correctly>

FROM ghcr.io/<my build and deploy container> as deploy-node

WORKDIR /app
COPY --from=build /app/out .
ENTRYPOINT [“<mytool>“, “<myexecutablefile>“]`

I am a loss as to why this works in my command shell but not here. Anything I’m overlooking? Is there a problem with GitHub containers?

Hello Bill!
I’ve performed some tests with a configuration close to yours and wasn’t able to reproduce the error.
In my test I added RUN env directive right after

ENV GIT_PERSONAL_ACCESS_TOKEN=$GIT_PERSONAL_ACCESS_TOKEN

Please try doing the same to be sure that the variables defined in the variables section were passed into the build context. And please double check the pipeline variables contain correct username and token.
Best Regards,
Alex

Thanks, Alex!

I made the modification that you suggested and those variables are not being populated.

Step 8/18 : RUN env                                                                                                                                     
 ---> Running in e3749b2aa0d0                                                                                                                           
GIT_USERNAME=                                                                                                                                           
HOSTNAME=e3749b2aa0d0                                                                                                                                   
DOTNET_USE_POLLING_FILE_WATCHER=true                                                                                                                    
HOME=/root                                                                                                                                              
DOTNET_RUNNING_IN_CONTAINER=true                                                                                                                        
POWERSHELL_DISTRIBUTION_CHANNEL=PSDocker-DotnetCoreSDK-Debian-10                                                                                        
DOTNET_GENERATE_ASPNET_CERTIFICATE=false                                                                                                                
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin                                                                                       
PWD=/app                                                                                                                                                
NUGET_XMLDOC_MODE=skip                                                                                                                                  
GIT_PERSONAL_ACCESS_TOKEN=                                                                                                                              
Removing intermediate container e3749b2aa0d0 

The values for those variables are in a shared configuration file that fills in GIT_USERNAME and GIT_PERSONAL_ACCESS_TOKEN that are used in the same workflow that currently passes on master. The only difference between passing code and my branch is pulling from the containers to create the dockerfile to use.

Bill

Hello William!
Sorry for late response, I think we might need more details to understand the issue,
Would it be possible to open a ticket for us to communicate sensitive information like example build IDs?
We’d like to review both passing code and your builds to see the full picture and provide you valuable help.
Thanks, Alex