google / copybara

Copybara: A tool for transforming and moving code between repositories.
Apache License 2.0
2.13k stars 258 forks source link

Passing a Variable to copybara.sky in Dockerized Copybara #264

Open juangugit opened 11 months ago

juangugit commented 11 months ago

Hello,

I'm currently working on synchronizing two repositories (from repoA to repoB) using Copybara running in a Docker container. Below is the command I'm using to initiate the sync process:

docker_cmd = [
    "docker run", "-v ~/.ssh:/root/.ssh", "-v ~/mongodb-bot.gitconfig:/root/.gitconfig",
    f'-v "{current_dir}/copybara.sky":/usr/src/app/copy.bara.sky',
    "-e COPYBARA_CONFIG='copy.bara.sky'", "-e COPYBARA_SUBCOMMAND='migrate'",
    "-e COPYBARA_OPTIONS='-v'", "copybara copybara"
]

I've noticed that the name and email from ~/mongodb-bot.gitconfig are being utilized correctly during the sync to repoB. However, now I need to pass a GitHub Apps token to the destinationUrl in my copybara.sky configuration file.

I have tried hardcoding the token directly in the URL like this:

python destinationUrl = "https://x-access-token:<token>@github.com/xxx/xx.git" And it works as expected. However, for security and flexibility reasons, I'd like to pass the token from my Python script to the copybara.sky file instead of hardcoding it.

I have tried to add it to my .gitconfig file like below, but it does not work.

    [http]
        extraheader = x-access-token:{token}

Is there a way to pass a variable (in this case, the GitHub Apps token) from my Python environment to the copybara.sky file? If so, could you please guide me on how to achieve this?

mikelalcon commented 11 months ago

Are you setting the .gitconfig inside the docker image? Copybara should honor reading $HOME/.gitconfig. Another option would be to set the authentication mode in the .gitconfig of the cached repo Copybara creates.

mikelalcon commented 11 months ago

You can also use --git-credential-helper-store-file flag (format: https://git-scm.com/docs/git-credential-store)