====================================================
Connecting to an external version control repository
====================================================

Data Science & AI Workbench supports the use of an external version control repository for user-created projects. Anaconda recommends connecting to this external version control repository *at time of installation*, however you are also able to migrate from one version control repository to another after installation is complete.

* To provide permission granularity and maintain parity with your external version control repository, Workbench grants individual platform users access to individual repositories. *To prevent default permissions being applied to all users within a group, users cannot belong to the given organization or group.*

* Platform users are prompted for their access token *before they create their first project* in Workbench. Anaconda recommends you *advise users to create an ever-lasting token*, to retain permanent access to their files from within Workbench. For more information about auth token permissions, see :doc:`Configuring user access to external version control <../../data-science-workflows/external-repo-user>`.  

.. tip:: 
   
   Anaconda recommends that you collect the following information before you begin: 

      * If necessary, the fully qualified domain name (FQDN) of your version control server. 
      * The organization, team, or group name associated with your service account.
      * The username of the administrator for the organization, team, or group.
      * The personal access token or password required to connect to your version control repository.

Supported external git versions
===============================

Workbench supports integration with the following external repositories:

.. csv-table:: 
   :file: ../../csv/external-git-version-support.csv
   :widths: 50, 50
   :header-rows: 1

GitHub
======

.. tab-set::

   .. tab-item:: GitHub Enterprise Server

      #. Create a backup copy of the ``anaconda-enterprise-anaconda-platform.yml`` configmap.
      #. Open the ``anaconda-enterprise-anaconda-platform.yml`` configmap for editing.
      #. Locate the ``git:`` section of the file.
      #. *Uncomment* (remove the ``#`` from the start of lines in) the ``Example external repo configuration`` section.
      #. *Comment out* (add a ``#`` to the start of) the remaining lines in the ``git:`` section.
      #. Configure the ``Example external repo configuration`` values as follows: 

         .. csv-table:: 
            :file: ../../csv/external-github-server.csv
            :widths: 20, 80
            :header-rows: 1

         .. caution:: 

            The ``url`` and ``credential-url`` attributes *must* contain all lowercase characters.

         .. dropdown:: Example Github Enterprise Server configuration 
            :color: primary
            :animate: fade-in

            .. code-block:: none

               git:
                  ## Example external repo configuration
                  name: github-server
                  type: github-v3-api
                  url: https://<FQDN>/api/v3/
                  http-timeout: 60
                  credential-url: https://<FQDN>/api/v3/
                  disable-tls-verification: false
                  repository: '{owner}-{id}'
                  organization: <GitHub_organization>
                  username: <admin_username>
                  auth-token: <username_token>
                  # type: internal
                  # http-timeout: 60
                  # repository: '{owner}-{id}'
                  # The maximum size of a commit in the git repository max-commit-file-size: 50000000

      #. Save your changes.
      #. Delete and restart system pods by running the following command:

         .. code-block:: none

            # Replace <NAMESPACE> with your Workbench cluster namespace
            kubectl delete -n <NAMESPACE> --wait=false $(kubectl get pods -o name|grep ap-) 

      Once all pods have returned to a running state, users are prompted to add their personal access token after logging into the platform.

   .. tab-item:: GitHub Enterprise Cloud

      #. Create a backup copy of the ``anaconda-enterprise-anaconda-platform.yml`` configmap.
      #. Open the ``anaconda-enterprise-anaconda-platform.yml`` configmap for editing.
      #. Locate the ``git:`` section of the file.
      #. *Uncomment* (remove the ``#`` from the start of lines in) the ``Example external repo configuration`` section.
      #. *Comment out* (add a ``#`` to the start of) the remaining lines in the ``git:`` section.
      #. Configure the ``Example external repo configuration`` values as follows:

         .. csv-table:: 
            :file: ../../csv/external-github-cloud.csv
            :widths: 20, 80
            :header-rows: 1 

         .. caution:: 

            The ``url`` and ``credential-url`` attributes *must* contain all lowercase characters. 

         .. dropdown:: Example Github Enterprise Cloud configuration 
            :color: primary
            :animate: fade-in

            .. code-block:: none

               git:
                  ## Example external repo configuration
                  name: github-cloud
                  type: github-v3-api
                  url: https://api.github.com/
                  http-timeout: 60
                  credential-url: https://github.com/<github-organization>
                  repository: '{owner}-{id}'
                  organization: <GitHub_organization>
                  username: <admin_username>
                  auth-token: <username_token>
                  # type: internal
                  # http-timeout: 60
                  # repository: '{owner}-{id}'
                  # The maximum size of a commit in the git repository max-commit-file-size: 50000000

      #. Save your changes.
      #. Restart system pods with the following command for changes to take effect:

         .. code-block:: none

            # Replace <NAMESPACE> with your Workbench cluster namespace
            kubectl delete -n <NAMESPACE> --wait=false $(kubectl get pods -o name|grep ap-) 

      Once all pods have returned to a running state, users should now be prompted to add their personal access token after logging into the platform.

GitLab
======

.. tab-set::

   .. tab-item:: GitLab Enterprise (Self-Managed)

      #. Create a backup copy of the ``anaconda-enterprise-anaconda-platform.yml`` configmap.
      #. Open the ``anaconda-enterprise-anaconda-platform.yml`` configmap for editing.
      #. Locate the ``git:`` section of the file.
      #. *Uncomment* (remove the ``#`` from the start of lines in) the ``Example external repo configuration`` section.
      #. *Comment out* (add a ``#`` to the start of) the remaining lines in the ``git:`` section.
      #. Configure the ``Example external repo configuration`` values as follows:

         .. csv-table:: 
            :file: ../../csv/external-gitlab-server.csv
            :widths: 20, 80
            :header-rows: 1 

         .. caution:: 

            The ``url`` and ``credential-url`` attributes *must* contain all lowercase characters. 

         .. dropdown:: Example GitLab Enterprise (Self-Managed) configuration 
            :color: primary
            :animate: fade-in

            .. code-block:: none

               git:
                  ## Example external repo configuration
                  name: gitlab-server
                  type: gitlab-v4-api
                  url: https://<FQDN>.com
                  http-timeout: 60
                  credential-url: https://<FQDN>.com
                  repository: '{owner}-{id}'
                  organization: <GitLab_group>
                  username: <admin_username>
                  auth-token: <username_token>
                  # type: internal
                  # http-timeout: 60
                  # repository: '{owner}-{id}'
                  # The maximum size of a commit in the git repository max-commit-file-size: 50000000

      #. Save your changes.
      #. Restart system pods with the following command for changes to take effect:

         .. code-block:: none

            # Replace <NAMESPACE> with your Workbench cluster namespace
            kubectl delete -n <NAMESPACE> --wait=false $(kubectl get pods -o name|grep ap-) 

      Once all pods have returned to a running state, users should now be prompted to add their personal access token after logging into the platform.

   .. tab-item:: GitLab Enterprise (Cloud)

      .. note::
         
         Gitlab.com does not support versioning of archive downloads and app deployments. In other words, the latest revision will always be downloaded or deployed.

      #. Create a backup copy of the ``anaconda-enterprise-anaconda-platform.yml`` configmap.
      #. Open the ``anaconda-enterprise-anaconda-platform.yml`` configmap for editing.
      #. Locate the ``git:`` section of the file.
      #. *Uncomment* (remove the ``#`` from the start of lines in) the ``Example external repo configuration`` section.
      #. *Comment out* (add a ``#`` to the start of) the remaining lines in the ``git:`` section.
      #. Configure the ``Example external repo configuration`` values as follows:

         .. csv-table:: 
            :file: ../../csv/external-gitlab-cloud.csv
            :widths: 20, 80
            :header-rows: 1 

         .. caution:: 

            The ``url`` and ``credential-url`` attributes *must* contain all lowercase characters. 

         .. dropdown:: Example GitLab Enterprise Cloud configuration 
            :color: primary
            :animate: fade-in

            .. code-block:: none

               git:
                  ## Example external repo configuration
                  name: gitlab-cloud
                  type: gitlab-v4-api
                  url: https://gitlab.com
                  http-timeout: 60
                  credential-url: https://gitlab.com
                  repository: '{owner}-{id}'
                  organization: <GitLab_group>
                  username: <admin_username>
                  auth-token: <username_token>
                  # type: internal
                  # http-timeout: 60
                  # repository: '{owner}-{id}'
                  # The maximum size of a commit in the git repository max-commit-file-size: 50000000

      #. Save your changes.
      #. Restart system pods with the following command for changes to take effect:

         .. code-block:: none

            # Replace <NAMESPACE> with your Workbench cluster namespace
            kubectl delete -n <NAMESPACE> --wait=false $(kubectl get pods -o name|grep ap-) 

      Once all pods have returned to a running state, users should now be prompted to add their personal access token after logging into the platform.

Bitbucket
=========

.. caution:: 
   
   By default, Bitbucket uses ``master`` as its default Git branch. Workbench uses ``main`` as its default Git branch. You must `update the system-wide default branch name <https://confluence.atlassian.com/bitbucketserver/setting-a-system-wide-default-branch-name-1021220665.html>`_ in Bitbucket to target ``main``. If you do not, your deployments will fail. 

.. tab-set::

   .. tab-item:: Bitbucket Server/Data Center

      #. Create a backup copy of the ``anaconda-enterprise-anaconda-platform.yml`` configmap.
      #. Open the ``anaconda-enterprise-anaconda-platform.yml`` configmap for editing.
      #. Locate the ``git:`` section of the file.
      #. *Uncomment* (remove the ``#`` from the start of lines in) the ``Example external repo configuration`` section.
      #. *Comment out* (add a ``#`` to the start of) the remaining lines in the ``git:`` section.
      #. Configure the ``Example external repo configuration`` values as follows:

         .. csv-table:: 
            :file: ../../csv/external-bitbucket-server.csv
            :widths: 20, 80
            :header-rows: 1 

         .. caution:: 

            The ``url`` and ``credential-url`` attributes *must* contain all lowercase characters. 

         .. dropdown:: Example Bitbucket Server/Data Center configuration 
            :color: primary
            :animate: fade-in

            .. code-block:: none

               git:
                  ## Example external repo configuration
                  name: bitbucket-server
                  type: bitbucket-v1-api
                  url: https://<FQDN>:7990
                  http-timeout: 60
                  credential-url: https://<FQDN>:7990
                  repository: '{owner}-{id}'
                  organization: <Bitbucket_team>
                  username: <Bitbucket_admin>
                  auth-token: <admin_password>
                  # type: internal
                  # http-timeout: 60
                  # repository: '{owner}-{id}'
                  # The maximum size of a commit in the git repository max-commit-file-size: 50000000

      #. Save your changes.
      #. Restart system pods with the following command for changes to take effect:

         .. code-block:: none

            # Replace <NAMESPACE> with your Workbench cluster namespace
            kubectl delete -n <NAMESPACE> --wait=false $(kubectl get pods -o name|grep ap-) 

      Once all pods have returned to a running state, users should now be prompted to add their personal access token after logging into the platform.

   .. tab-item:: Bitbucket Cloud

      .. note::
         
         Bitbucket.com does not support versioning of archive downloads and app deployments. In other words, the latest revision will always be downloaded or deployed.

      #. Create a backup copy of the ``anaconda-enterprise-anaconda-platform.yml`` configmap.
      #. Open the ``anaconda-enterprise-anaconda-platform.yml`` configmap for editing.
      #. Locate the ``git:`` section of the file.
      #. *Uncomment* (remove the ``#`` from the start of lines in) the ``Example external repo configuration`` section.
      #. *Comment out* (add a ``#`` to the start of) the remaining lines in the ``git:`` section.
      #. Configure the ``Example external repo configuration`` values as follows:

         .. csv-table:: 
            :file: ../../csv/external-bitbucket-cloud.csv
            :widths: 20, 80
            :header-rows: 1 

         .. caution:: 

            The ``url`` and ``credential-url`` attributes *must* contain all lowercase characters. 

         .. dropdown:: Example Bitbucket Cloud configuration 
            :color: primary
            :animate: fade-in

            .. code-block:: none

               git:
                  ## Example external repo configuration
                  name: bitbucket-cloud
                  type: bitbucket-v2-api
                  url: https://api.bitbucket.org
                  http-timeout: 60
                  credential-url: https://bitbucket.org/
                  repository: '{owner}-{id}'
                  organization: <Bitbucket_team>
                  username: <Bitbucket_admin>
                  auth-token: <admin_password>
                  # type: internal
                  # http-timeout: 60
                  # repository: '{owner}-{id}'
                  # The maximum size of a commit in the git repository max-commit-file-size: 50000000

      #. Save your changes.
      #. Restart system pods with the following command for changes to take effect:

         .. code-block:: none

            # Replace <NAMESPACE> with your Workbench cluster namespace
            kubectl delete -n <NAMESPACE> --wait=false $(kubectl get pods -o name|grep ap-) 

      Once all pods have returned to a running state, users should now be prompted to add their personal access token after logging into the platform.
