Bootstrap FreeKB - ArgoCD - Add Repo using the CLI
ArgoCD - Add Repo using the CLI

Updated:   |  ArgoCD articles

This assumes:

The argocd repo list command can be used to list the repo's you have added to ArgoCD.

~]$ argocd repo list
TYPE  NAME       REPO                              INSECURE  OCI    LFS    CREDS  STATUS      MESSAGE  PROJECT
git   foo-bar    https://github.com/foo/bar.git    false     false  false  false  Successful           default

 

Assuming the repo you want to add has not already been added to ArgoCD, the argocd repo add command can be used to add the repo to ArgoCD. If the repo is a public repo, you should be able to add the repo without having to provide any sort of authentication, such as a username and password.

argocd repo add https://github.com/foo/bar.git

 

For private repos, you need to authenticate. If using the HTTPS URL for the private repo, it's pretty common to provide a username and password.

argocd repo add https://github.com/foo/bar.git --username john.doe --password itsasecret

 

Or you can use an Access Token, such as a GitHub Personal Access Token (PAT).

 

When using an Access Token, the username must be a non empty string such as a single whitespace and password will be the Access Token.

argocd repo add https://github.com/foo/bar.git --username ' '  --password 'ghp_ggEVZkS0N2mzlGABCK0pO3C123CSmS0oFNeX'

 

To add a repo using SSH, you will use an SSH private key. ArgoCD version 2.4 uses OpenSSH version 8.9. OpenSSH version 8.8 dropped support for ssh-rsa. The argocd --version command can be used to display the version of ArgoCD you are using.

~]$ argocd version
argocd: v2.13.2+dc43124

 

If you are using ArgoCD version 2.4 or higher, you must not create an RSA key. Instead, you will almost always go with an ed25519 SSH public/private keypair.

You may also need to ensure that the SSH key is an OpenSSH private key and has comment argocd (check out this article for more details on this). The ssh-keygen command can be used to create the OpenSSH public/private keypair.

ssh-keygen -t ed25519 -N '' -C argocd -f $HOME/.ssh/argocd

 

In this scenario, you would also need to add the SSH key in your GitHub account.

 

And then you can add the repo using the SSH private key.

argocd repo add git@github.com:foo/bar.git --ssh-private-key-path $HOME/.ssh/argocd

 

Or you can create a YAML file that will be used to create a Kubernetes or OpenShift secret. The secret will add the repo to ArgoCD. For example, here is what you could have in your YAML file to add a GitHub repo to ArgoCD using an SSH key for the authentication to the GitHub repo.

apiVersion: v1
stringData:
  name: my-repo
  project: my-project
  type: git
  url: https://github.com/foo/bar.git
  proxy: https://proxy.example.com # optional
  sshPrivateKey: |
    -----BEGIN OPENSSH PRIVATE KEY-----
    MIIJK.....xdi3fPx
    -----END OPENSSH PRIVATE KEY-----
kind: Secret
metadata:
  annotations:
    managed-by: argocd.argoproj.io
  labels:
    argocd.argoproj.io/secret-type: repository
  name: my-repo
  namespace: openshift-gitops
type: Opaque

 

And then the kubectl (Kubernetes) or oc (OpenShift) apply command can be used to create a secret from a YAML file.

~]$ oc apply -f repo.yml
secret/my-repo created

 

It's pretty common to give the repo a name and to map the repo to an ArgoCD project.

argocd repo add git@github.com:foo/bar.git \
--ssh-private-key-path ~/.ssh/id_rsa \
--name my-repo \
--project default

 

If you want ArgoCD to use a proxy to connect to the repo the --proxy option can be used.

argocd repo add git@github.com:foo/bar.git \
--ssh-private-key-path ~/.ssh/id_rsa \
--name my-repo \
--project default \
--proxy https://proxy.example.com

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter a11580 in the box below so that we can be sure you are a human.