microsoft / pxt-microbit

A Blocks / JavaScript code editor for the micro:bit built on Microsoft MakeCode
https://makecode.microbit.org
Other
711 stars 586 forks source link

Can the pxt cli tool pass an environmental variables to the docker builder? #4945

Open microbit-carlos opened 1 year ago

microbit-carlos commented 1 year ago

To run pxt buildtarget --local Yotta needs to retrieve a bunch of GitHub repositories via GitHub API, and without a GitHub token it gets rate limited fairly quickly.

Using the PXT_NODOCKER=1 flag forces pxt use the local tooling, and we can pass a GitHub token to our local Yotta installation via environmental variable. So building like this works:

PXT_NODOCKER=1 YOTTA_GITHUB_AUTHTOKEN=xxxxxx pxt buildtarget --local

However, if we want to use the default Docker containers (as defined in pxtarget.json) to build the targets I cannot find a way to pass a GH token to Yotta inside the container from the command line. There are GITHUB_ACCESS_TOKEN/GITHUB_TOKEN environmental variables for the pxt tool, but they doesn't get passed to the docker container.

I found a way to pass additional flags to docker via pxtarget.json, but this is a bit cumbersome for CI workflows:

{
    "variants": {
        "mbdal": {
            "compileService": {
                "dockerArgs": [
                    "--env",
                    "YOTTA_GITHUB_AUTHTOKEN=xxxxxxxxxxxxxxxxxxxxx"
                ]
            }
        }
    }
}

Is there a way to do this that is a bit more cli friendly? Or a different way to configure Yotta to use a provided token?

(when running with the local tooling you can also create a ~/.yotta/config.json file with the token, but for the docker builds the file would have to be inside the container ~/ path, and there isn't a way to do that).

abchatra commented 1 year ago

@microbit-carlos feel free to do PR if posssible