From c77294df86f90b618960de8c02bc215a6c29692f Mon Sep 17 00:00:00 2001 From: Tung Bui Date: Sun, 12 Jul 2026 22:03:59 +0700 Subject: [PATCH] feat: add GitHub CLI (gh) Installed the same way as terraform/kubectl/helm: a pinned version downloaded directly from GitHub releases, no extra apt repo needed. - toolkit_info.json / README / docs wired into the existing version-check and version-sync automation (check_latest_version.py, update_latest_version.py, check_version_in_toolkit.sh) - `gh --version` needs no auth, so it's added as a real smoke test in samples/run_sample.sh (same treatment as kubectl/helm), unlike awscli/azurecli which stay documentation-only since they need live credentials to do anything meaningful - New docs/usage/githubcli_usage.md follows the existing per-tool usage doc pattern --- Dockerfile | 9 ++++ README.md | 3 +- docs/usage/README.md | 4 ++ docs/usage/githubcli_usage.md | 66 +++++++++++++++++++++++++++++ samples/README.md | 7 +++ samples/run_sample.sh | 6 +++ scripts/check_latest_version.py | 4 ++ scripts/check_version_in_toolkit.sh | 3 ++ scripts/update_latest_version.py | 1 + toolkit_info.json | 1 + 10 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 docs/usage/githubcli_usage.md diff --git a/Dockerfile b/Dockerfile index d650ac7..e6ea127 100644 --- a/Dockerfile +++ b/Dockerfile @@ -83,6 +83,15 @@ RUN mkdir /tmp/helm_env/ && \ mv linux-amd64/helm /usr/local/bin/helm && \ rm -rf /tmp/helm_env/ +# Install GitHub CLI +ARG GH_VERSION=2.96.0 +RUN mkdir /tmp/gh_env/ && \ + cd /tmp/gh_env/ && \ + wget https://github.com/cli/cli/releases/download/v${GH_VERSION}/gh_${GH_VERSION}_linux_amd64.tar.gz && \ + tar -xvzf gh_${GH_VERSION}_linux_amd64.tar.gz && \ + cp gh_${GH_VERSION}_linux_amd64/bin/gh /usr/local/bin/gh && \ + rm -rf /tmp/gh_env/ + # Install AwsCLI ARG AWSCLI_VERSION=2.35.21 RUN mkdir /tmp/awscli_env/ && \ diff --git a/README.md b/README.md index a54da50..4587855 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ ## Key Features -- **Comprehensive Toolset**: Pre-installed with tools like Git, Python, Ansible, Terraform, kubectl, Helm, AWS CLI, Azure CLI, and more. +- **Comprehensive Toolset**: Pre-installed with tools like Git, Python, Ansible, Terraform, kubectl, Helm, GitHub CLI, AWS CLI, Azure CLI, and more. - **Easy Integration**: Use it directly or customize it with your preferred versions. - **Efficient Updates**: Weekly updates ensure the latest versions and security patches. - **Configuration Reusability**: Mounts host config folders for seamless reuse across sessions. @@ -113,6 +113,7 @@ Built on `ubuntu:24.04` base image | Terraform | TERRAFORM_VERSION=1.15.8 | [Check](https://releases.hashicorp.com/terraform/) | [terraform_usage](./docs/usage/terraform_usage.md) | | Kubectl | KUBECTL_VERSION=1.36.2 | [Check](https://dl.k8s.io/release/stable.txt) | [kubectl_usage](./docs/usage/kubectl_usage.md) | | Helm | HELM_VERSION=3.21.3 | [Check](https://github.com/helm/helm/releases) | [helm_usage](./docs/usage/helm_usage.md) | +| GitHub CLI | GH_VERSION=2.96.0 | [Check](https://github.com/cli/cli/releases) | [githubcli_usage](./docs/usage/githubcli_usage.md) | | AwsCLI | AWSCLI_VERSION=2.35.21 | [Check](https://raw.githubusercontent.com/aws/aws-cli/v2/CHANGELOG.rst) | [awscli_usage](./docs/usage/awscli_usage.md) | | AzureCLI | AZURECLI_VERSION=2.88.0 | [Check](https://learn.microsoft.com/en-us/cli/azure/release-notes-azure-cli) | [azurecli_usage](./docs/usage/azurecli_usage.md) | | PowerShell | PS_VERSION=7.6.3 | [Check](https://github.com/PowerShell/PowerShell/releases) | [powershell_usage](./docs/usage/powershell_usage.md) | diff --git a/docs/usage/README.md b/docs/usage/README.md index 664c25b..8f88516 100644 --- a/docs/usage/README.md +++ b/docs/usage/README.md @@ -22,6 +22,10 @@ This guide us how to use the `devops-toolkit` with serveral usecases - Check [**helm_usage**](./helm_usage.md) +## GitHub CLI + +- Check [**githubcli_usage**](./githubcli_usage.md) + ## AwsCLI - Check [**awscli_usage**](./awscli_usage.md) diff --git a/docs/usage/githubcli_usage.md b/docs/usage/githubcli_usage.md new file mode 100644 index 0000000..bfc0611 --- /dev/null +++ b/docs/usage/githubcli_usage.md @@ -0,0 +1,66 @@ +# Use GitHub CLI in the devops-toolkit + +## Prerequisite + +A GitHub account + +## GitHub CLI document + +Some document to help you start with GitHub CLI (`gh`) + +- +- + +## Run with Docker command + +### Note + +To use the existing container instead of creating one, use `docker exec` command instead of `docker run` + +```bash +docker exec -it my_devops_toolkit /bin/bash +``` + +### Common Run Modes + +For instructions on common run modes, visit [**DevOps Toolkit Common Run Mode**](../usage/run_mode.md). + +### Use case 1: Authenticate and list your repositories + +```bash +docker run --rm --network host -it -v ~/.dtc:/dtc tungbq/devops-toolkit:latest +############################################### +# Now we are in the docker container terminal # +############################################### +# Log in (follow the device-code flow in your browser) +gh auth login +# List your repositories +gh repo list +``` + +Sample Result + +```bash +root@docker-desktop:~# gh auth login +? What account do you want to log into? GitHub.com +? What is your preferred protocol for Git operations on this host? HTTPS +? How would you like to authenticate GitHub CLI? Login with a web browser + +! First copy your one-time code: XXXX-XXXX +Press Enter to open github.com in your browser... +✓ Authentication complete. +✓ Logged in as octocat +``` + +### Use case 2: Work with pull requests and issues + +```bash +# From inside an existing git repository +gh pr list +gh pr create --title "My change" --body "Description" +gh issue list +``` + +### Troubleshooting + +- For any issues, check [this reference](../troubleshooting/TROUBLESHOOTING.md) diff --git a/samples/README.md b/samples/README.md index 974a488..2a14444 100644 --- a/samples/README.md +++ b/samples/README.md @@ -56,6 +56,13 @@ helm repo add bitnami https://charts.bitnami.com/bitnami helm search repo bitnami | grep jenkins ``` +## GitHub CLI + +```bash +# Check GitHub CLI version +gh --version +``` + ## AwsCLI - TODO diff --git a/samples/run_sample.sh b/samples/run_sample.sh index 5202ce5..1dc0d16 100644 --- a/samples/run_sample.sh +++ b/samples/run_sample.sh @@ -45,3 +45,9 @@ console_log "Running Helm sample: add and search" helm repo add bitnami https://charts.bitnami.com/bitnami helm search repo bitnami | grep jenkins +########### +# GitHub CLI +########### +console_log "Running GitHub CLI sample: check version" +gh --version + diff --git a/scripts/check_latest_version.py b/scripts/check_latest_version.py index 761ee01..0b71c1c 100644 --- a/scripts/check_latest_version.py +++ b/scripts/check_latest_version.py @@ -87,6 +87,10 @@ def main(output_file): helm_version = version_parser.check_github_release_version("Helm", "helm/helm") versions["helm"] = helm_version + # GitHub CLI + githubcli_version = version_parser.check_github_release_version("GitHub CLI", "cli/cli") + versions["githubcli"] = githubcli_version + # Awscli awscli_version = version_parser.check_awscli_version() versions["awscli"] = awscli_version diff --git a/scripts/check_version_in_toolkit.sh b/scripts/check_version_in_toolkit.sh index b150a59..f9b77ef 100644 --- a/scripts/check_version_in_toolkit.sh +++ b/scripts/check_version_in_toolkit.sh @@ -9,6 +9,7 @@ ansible_version=$(cat "$toolkit_info_path" | jq -r '.ansible') terraform_version=$(cat "$toolkit_info_path" | jq -r '.terraform') kubectl_version=$(cat "$toolkit_info_path" | jq -r '.kubectl') helm_version=$(cat "$toolkit_info_path" | jq -r '.helm') +githubcli_version=$(cat "$toolkit_info_path" | jq -r '.githubcli') awscli_version=$(cat "$toolkit_info_path" | jq -r '.awscli') azurecli_version=$(cat "$toolkit_info_path" | jq -r '.azurecli') pwsh_version=$(cat "$toolkit_info_path" | jq -r '.pwsh') @@ -20,6 +21,7 @@ echo "ansible_version=$ansible_version" echo "terraform_version=$terraform_version" echo "kubectl_version=$kubectl_version" echo "helm_version=$helm_version" +echo "githubcli_version=$githubcli_version" echo "awscli_version=$awscli_version" echo "azurecli_version=$azurecli_version" echo "pwsh_version=$pwsh_version" @@ -31,6 +33,7 @@ declare -A tools=( [terraform]="$terraform_version" [kubectl]="$kubectl_version" [helm]="$helm_version" + [gh]="$githubcli_version" [aws]="$awscli_version" [az]="$azurecli_version" [pwsh]="$pwsh_version" diff --git a/scripts/update_latest_version.py b/scripts/update_latest_version.py index 8dbbf91..02b91d3 100644 --- a/scripts/update_latest_version.py +++ b/scripts/update_latest_version.py @@ -58,6 +58,7 @@ def update_readme(readme_path, version_arg, new_version): {"name": "terraform", "version_arg": "TERRAFORM_VERSION"}, {"name": "kubectl", "version_arg": "KUBECTL_VERSION"}, {"name": "helm", "version_arg": "HELM_VERSION"}, + {"name": "githubcli", "version_arg": "GH_VERSION"}, {"name": "awscli", "version_arg": "AWSCLI_VERSION"}, {"name": "azurecli", "version_arg": "AZURECLI_VERSION"}, {"name": "pwsh", "version_arg": "PS_VERSION"} diff --git a/toolkit_info.json b/toolkit_info.json index b6d0259..a7c5faa 100644 --- a/toolkit_info.json +++ b/toolkit_info.json @@ -4,6 +4,7 @@ "terraform": "1.15.8", "kubectl": "1.36.2", "helm": "3.21.3", + "githubcli": "2.96.0", "awscli": "2.35.21", "azurecli": "2.88.0", "pwsh": "7.6.3"