Configure access to private repositories

Edit on GitHub

This document describes how to configure an environment to allow the Docker SDK access private repositories.

You need to configure access to private repositories in the following cases:

  • You have a private repository mentioned in composer.json:
{
    "require": {
        "my-repo": "dev-master"
    },
    "repositories": [
        {
            "type": "git",
            "url": "git@github.com:my-org/my-repo.git"
        }
    ]
}
  • Running docker/sdk up returns an error similar to the following:
Cloning into '/data/vendor/my-org/my-repo'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Configure an environment to access private repositories

  1. Add the .known_hosts file with the list of domains of VCS services into the project root. Example:
github.com
bitbucket.org
gitlab.my-org.com
  1. Configure authentication of Composer to VCS services using one of the following options:

Configure SSH agent authentication for Composer

  1. Remove the GITHUB_TOKEN and COMPOSER_AUTH environment variables:
unset GITHUB_TOKEN
unset COMPOSER_AUTH
  1. Prepare SSH agent by adding your private keys:
eval $(ssh-agent)
ssh-add -K ~/.ssh/id_rsa
  1. MacOS and Windows: For Docker Desktop to fetch the changes, restart the OS.

  2. Re-build the application:

docker/sdk up --build

Configure the Composer authentication environment variable

  1. Create access tokens in your VCS services.

  2. Prepare a COMPOSER_AUTH environment variable with the VCS tokens you’ve created in JSON:

    • GitHub:
    {
        "github-oauth": {
            "github.com": "{GITHUB_TOKEN}"
        }
    }
    
    • BitBucket:
    {
        "bitbucket-oauth": {
            "bitbucket.org": {
                "consumer-key": "{BITBUCKET_KEY}",
                "consumer-secret": "{BITBUCKET_SECRET}"
            }
        }
    }
    
    • GitLab
    {
        "gitlab-token": {
            "mysprykershop.com": "{GITLAB_TOKEN}"
        }
    }
    

To learn about Composer authentication variables, see COMPOSER_AUTH and Custom token authentication

  1. Enable the environment variable using one of the following options:
  • Export the environment variable taking Bash escaping rules into consideration:
export COMPOSER_AUTH="{\"github-oauth\":{\"github.com\":\"{GITHUB_TOKEN}\"},\"gitlab-oauth\":{\"gitlab.com\":\"{GITLAB_TOKEN}\"},\"bitbucket-oauth\":{\"bitbucket.org\": {\"consumer-key\": \"{BITBUCKET_KEY}\", \"consumer-secret\": \"{BITBUCKET_SECRET}\"}}}"
  • Add the environment variable to your development environment by editing ~/.bash_profile or ~/.zshenv:
export COMPOSER_AUTH="{\"github-oauth\":{\"github.com\":\"{GITHUB_TOKEN}\"},\"gitlab-oauth\":{\"gitlab.com\":\"{GITLAB_TOKEN}\"},\"bitbucket-oauth\":{\"bitbucket.org\": {\"consumer-key\": \"{BITBUCKET_KEY}\", \"consumer-secret\": \"{BITBUCKET_SECRET}\"}}}"
  1. Re-build the application:
docker/sdk up --build

You’ve configured authentication to your private repositories.