This repository contains the codehub CLI used to deploy the CodeHub
platform to Kubernetes. This README file summarizes installing, using and
developing the codehub CLI. More detailed information can be found in
the repository's Wiki pages.
Installing and using the codehub CLI requires the following:
- git
- conda (or other python environment manager)
- kubectl
- helm
- gcloud CLI
- gke-gcloud-auth-plugin
- opentofu
-
Clone the repository using Git.
-
Inside the repository's root folder, create a Conda environment with the required development requirements installed with the following command:
conda env create -f dev_environment.yml
-
Activate the newly created Conda environment by running:
conda activate codehub
-
Install the
codehubCLI with:pip install -e .
Alternatively, you can create a virtual environment with virtualenv using the following instructions
pyenv install 3.9.10
pyenv local 3.9.10
pip install virtualenv
python -m venv .codehub
source .codehub/bin/activate
pip install --upgrade pip
pip install --upgrade setuptools
pip install -r dev_requirements.txt
pip install -e .The dockerized version requires Docker only, and the rest of the tools will be installed into the container automatically. Do the initial secrets setup from the Usage parts 1—4 of the document, then you can use:
./dep.shRun it without any parameters to build (if necessary), start, and connect to the container. After you terminate the initial instance, the container will automatically shut down. If the container is already running, the script will connect you to it.
To perform force rebuild the image, use:
./dep.sh --rebuildAfter building the proper image, it will connect you to the container, and all of the environment will be set up.
Before you can use the CLI to deploy the CodeHub platform you need to set up a number of secrets to grant you and the deployment access to the necessary resources.
-
Go to GCP Console Service accounts and select the correct project. Ensure that a Service Account with sufficient permissions exists, go to the Keys tab -> Add key -> Create new key -> JSON.
Store the JSON key-file as
service-account.jsonin thesecrets/gcpdirectory. Authenticate yourgcloudCLI with the key by running:gcloud auth activate-service-account --key-file secrets/gcp/service-account.json
- A sufficient list of permissions is
Artifact Registry Administrator,Cloud Filestore Editor,Cloud Filestore Viewer,Compute Admin,Create Service Accounts,Delete Service Accounts,Kubernetes Engine Admin,Service Account Key Admin,Service Account User,Storage Admin
- A sufficient list of permissions is
-
Set the correct project in your
gcloudCLI by running:gcloud config set project <your-project-id>
-
Test the setup by creating and then deleting a new cluster (optional). The process can take ~10 minutes, check progress on the Kubernetes clusters page. Run the following commands:
codehub createcluster --name mytestcluster -r europe-north1 && \ codehub deletecluster --name mytestcluster
The main entrypoint for the CLI is the command codehub. For some more
information on this command as well as the available subcommands you can run
codehub --helpAvailable subcommands are the following:
-
createcluster: Used for creating a new CodeHub deployment and its associated cloud resources. Requires a cluster name using the option-n <name>or--name <name>(up to 14 alphanumeric symbols) and accepts the name of an admin user for CodeHub using the option-a <admin>or--admin <admin>. The--adminoption can be supplied multiple times to create multiple admin users. For more information about this subcommand run:codehub createcluster --help
-
deletecluster: Used for deleting a CodeHub deployment and its associated cloud resources. Requires a cluster name using the option-n <name>or--name <name>. For more information about this subcommand run:codehub deletecluster --help
-
getip: Used for getting the IP of the entrypoint for a CodeHub deployment. Requires a cluster name using the option-n <name>or--name <name>. For more information about this subcommand run:codehub getip --help
-
scalecluster: Used for manually changing the node pool size and the down scaling behaviour of the autoscaler. Requires a cluster name using the option-n <name>or--name <name>and a number of nodes using the option--nodes <num of nodes>. Also accepts the--downflag to specify that the autoscaler should be able to scale down to 0. For more information about this subcommand run:codehub scalecluster --help
-
upgradecluster: Used to change the cluster and Kubernetes configuration of a CodeHub deployment. Requires a cluster name using the option-n <name>or--name <name>. Also accepts the option--https <hostname>to set up https for hostname<hostname>,--client-id <client id>and--client-secret <client secret>to enable GitHub OAuth2 authentication,-a <admin>or--admin <admin>to set new admins. For more information about this subcommand run:codehub upgradecluster --help
Further configuration is done by modifying the YAML files in the
dscampus/templates folder.
Create a cluster named examplecluster with admin users admin1 and admin2
using the command
codehub createcluster --name examplecluster --admin admin1 --admin admin2Once the deployment is complete the IP of the entrypoint will be printed to
terminal. At this point you can go to that IP and login as either admin1 or
admin2 without a password to test the deployment.
To add https support to the deployment use
codehub upgradecluster --name examplecluster \
--admin admin1 \
--admin admin2 \
--https example.hostname.comThis will deploy a Let's Encrypt tls certificate valid for the hostname
example.hostname.com.
To add GitHub OAuth2 authentication using a GitHub OAuth app with client id
<client id> and client secret <client secret> use the command
codehub upgradecluster --name examplecluster \
--admin admin1 \
--admin admin2 \
--https example.hostname.com \
--client-id <client id> \
--client-secret <client secret>Delete the deployment and associated resources using the command
codehub deletecluster --name exampleclusterThere is a script for checking if a list of GitHub usernames exist and report the ones that do not.
To use it, a GitHub access token is required and there is a limit of 6000 requests per hour. The user list needs to be separated by commas.
./check_github_users.sh <GITHUB_ACCESS_TOKEN> "user1, user2, ..."Sometimes the SSL certificate does not generate properly, this can usually be
fixed by restarting the load balancer: kubectl -n jhub delete pod autohttps-<id>
GitHub Issues are used to create and track issues and feature requests for the repository.
There are two main branches:
develop: Development branch. Changes to the repository are frequently merged into thedevelopbranch by pull requests from temporary branches after review.acceptance: Branch for accepting features to be merged into master. Changes in the develop branch are merged into theacceptancebranch by pull requests in order to thoroughly check features and feature changes.master: The current release of the repository. Can only be changes by merging a pull request from theacceptancebranch after review.
Temporary branches conform to the following naming convention:
bugfix/XYZ: Designated for bugfixes.feature/XYZ: Designated for addition of new features.refactor/XYZ: Designated for refactoring work.docs/XYZ: Designated for updates to the documentation.
XYZ should be descriptive enough to identify what the changes relate to.
Use the following workflow when solving an issue:
-
Make sure you are on the
developbranch and that you have pulled all the latest changes to your local git repository. -
Create a new temporary branch from the
developbranch following the above naming convention using e.g.git switch -c feature/XYZ
-
Make and commit your changes to the temporary branch.
-
Push your temporary branch to the GitHub repository.
-
Open a pull request to merge the changes from your temporary branch into the
developbranch. Make sure to request at least one reviewer and mention which issue will be closed by this pull request. -
After the changes have been accepted by the reviewer, merge the changes and delete the temporary branch after merging.
When preparing for a release use the following workflow:
- Make sure all intended changes are merged into
develop. - Create a pull request to merge changes from
developintoacceptancewith all current developers as reviewers. - Merge the changes after the review is accepted.
- Test the current state of the repository thoroughly to make sure everything
works as intended. If any issues are found make the changes to the
developbranch and repeat step 2. - Create a pull request to merge
acceptanceintomasterwith all current developers as reviewers. - Merge the changes after the review is accepted.
- Create a release on GitHub named
vX.Y.Zaccording to semantic versioning and tag the corresponding commit with the release tag. - Merge the release tag back into
developfor continued development.