Cloning Source Code

The repos block of our recipe specification is used to clone code. This will use the permissions of the GitHub application you have connected with DevZero.

To clone one or multiple repos:

dev:
    repos:
    - https://github.com/vercel/next.js
    - https://github.com/my-org/my-repo
Advanced Methods of Code Cloning

This usually applies to cases where you need to use secrets to clone code. To learn more about how to save and use secrets: https://github.com/devzero-inc/product-docs/blob/main/recipes/broken-reference/README.md

You can use a command block to clone code directly:

dev:
    commands:
    - command: |-
        git clone https://github.com/vercel/next.js
      directory: /home/devzero
      name: clone public repo

    - command: |-
        # MY_PERSONAL_TOKEN is the key for a secret/environment variable saved at https://www.devzero.io/dashboard/settings/environment-variables#team
        git clone https://$MY_PERSONAL_TOKEN@github.com/vercel/next.js
      directory: /home/devzero
      name: clone private repo using PAT
    
     - command: |-
        # MY_PRIVATE_KEY is the key for secret/environment variable saved at https://www.devzero.io/dashboard/settings/environment-variables#team
        # The value for that should be the private key part of what you saved as a deploy key: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/managing-deploy-keys
        
        mkdir -p .ssh
        echo "-----BEGIN OPENSSH PRIVATE KEY-----" >> .ssh/devzero_id25519
        echo $MY_PRIVATE_KEY >> .ssh/devzero_id25519
        echo "-----END OPENSSH PRIVATE KEY-----" >> .ssh/devzero_id25519
        chmod 400 .ssh/devzero_id25519

        GIT_SSH_COMMAND='ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new -i /home/devzero/.ssh/devzero_id25519' git clone git@github.com:my-org/my-repo.git
      directory: /home/devzero
      name: clone private repo over ssh using a deploy key

Some of the use cases where this is applicable:

  • You're not using GitHub for source control

  • You cannot authorize the GitHub app due to access control issues

  • You need to use deploy keys, personal access tokens, etc.

  • You need to use some other authentication methods than the DevZero default

  • You want to clone your repo to a custom directory

  • If there's something else you don't see supported, please drop us a note at support@devzero.io

Accessing Code From Bitbucket

Step 1. Go to your repo page on the Bitbucket website

Step 2. Go to the Access Keys section

Step 3(a). Generate keys

ssh-keygen -t ed25519 -C "devzero-user@my-website.com" -f devzero_id25519 -P '' -q

Step 3(b). Add the public key to your Bitbucket repo's access keys

First, copy the public key

cat ~/.ssh/devzero_id25519.pub | pbcopy

Then, paste it in the Key section in the pop-up box.

Step 3(c). Add the private key to DevZero

Check the private key

Copy it

cat ~/.ssh/devzero_id25519 | pbcopy

Then paste it into your team's secrets section at https://www.devzero.io/dashboard/settings/environment-variables#team

Call it BITBUCKET_PVT_KEY (or whatever you please, but this is referenced in Step 4)

Step 4. Build a recipe

Create a recipe and add a block that looks like the one below (check line 5 to ensure naming).

dev:
  commands:
    - command: |-
        mkdir -p .ssh
        printf "%s" "$BITBUCKET_PVT_KEY" >> .ssh/devzero_id25519
        sed -i 's/^"//; s/"$//' .ssh/devzero_id25519
        chmod 400 .ssh/devzero_id25519
        GIT_SSH_COMMAND='ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new -i /home/devzero/.ssh/devzero_id25519' git clone git@bitbucket.org:devzero-inc/demo-repo-pvt.git
      dir: .
      name: clone_from_bitbucket

Step 5. Launch a workspace from that recipe

Visit your recipes pages here https://www.devzero.io/dashboard/recipes, and launch a workspace from that new recipe!

Last updated