Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Open
juangugit opened this issue Oct 25, 2023 · 2 comments
Open

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

juangugit opened this issue Oct 25, 2023 · 2 comments

Comments

@juangugit
Copy link

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
Copy link
Collaborator

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
Copy link
Collaborator

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants