From 2af2724371279a32b3269a9a22465db95ada5bab Mon Sep 17 00:00:00 2001 From: Venkata Mutyala Date: Mon, 18 Sep 2023 18:48:50 -0700 Subject: [PATCH] feat: update versions and add yolo auth command (#24) * feat: update versions * chore: bump codespace version to v0.30.0 * feat: adding create-ghcr-regcred --- .devcontainer/Dockerfile | 15 ++--- .devcontainer/tools/add-to-bashrc.sh | 85 +++++++++++++++++++++++++ .devcontainer/tools/glueops-fetch-repos | 7 -- .devcontainer/tools/run-gha | 4 -- 4 files changed, 91 insertions(+), 20 deletions(-) create mode 100755 .devcontainer/tools/add-to-bashrc.sh delete mode 100755 .devcontainer/tools/glueops-fetch-repos delete mode 100755 .devcontainer/tools/run-gha diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index dc78708..4aba7ae 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -10,29 +10,26 @@ FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT} # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ # && apt-get -y install --no-install-recommends -ENV GLUEOPS_CODESPACES_VERSION=v0.29.0 +ENV GLUEOPS_CODESPACES_VERSION=v0.30.0 ARG VERSION_KUBECTL=1.27.5 ARG VERSION_TERRAFORM=1.5.5 ARG VERSION_HELM=3.12.3 -ARG VERSION_GCLOUD_SDK=444.0.0 -ARG VERSION_TASKFILE=3.29.1 +ARG VERSION_GCLOUD_SDK=446.0.1 +ARG VERSION_TASKFILE=3.30.1 ARG VERSION_KIND=0.20.0 ARG VERSION_K9S=0.27.4 ARG VERSION_TERRAFORM_DOCS=0.16.0 ARG VERSION_KUBENT=0.7.0 ARG VERSION_HELM_DIFF=3.8.1 ARG VERSION_CHARM_GUM=0.11.0 -ARG VERSION_ARGO_CD_CLI=2.7.10 +ARG VERSION_ARGO_CD_CLI=2.8.3 # https://developer.hashicorp.com/vault/docs/commands#vault_skip_verify # https://github.com/GlueOps/terraform-module-kubernetes-hashicorp-vault-configuration/wiki ENV VAULT_SKIP_VERIFY true ENV CLOUDSDK_INSTALL_DIR /usr/local/gcloud/ -ADD ../tools/glueops-fetch-repos /usr/bin/glueops-repo-fetch -ADD ../tools/run-gha /usr/bin/run-gha -RUN chmod +x \ - /usr/bin/glueops-repo-fetch \ - /usr/bin/run-gha +ADD ../tools/add-to-bashrc.sh /tmp/add-to-bashrc.sh +RUN chmod +x /tmp/add-to-bashrc.sh && ./tmp/add-to-bashrc.sh RUN curl -Lo /usr/local/bin/kubectl https://dl.k8s.io/release/v${VERSION_KUBECTL}/bin/linux/amd64/kubectl \ && chmod +x /usr/local/bin/kubectl \ && curl -Lo terraform_${VERSION_TERRAFORM}_linux_amd64.zip https://releases.hashicorp.com/terraform/${VERSION_TERRAFORM}/terraform_${VERSION_TERRAFORM}_linux_amd64.zip \ diff --git a/.devcontainer/tools/add-to-bashrc.sh b/.devcontainer/tools/add-to-bashrc.sh new file mode 100755 index 0000000..07f610d --- /dev/null +++ b/.devcontainer/tools/add-to-bashrc.sh @@ -0,0 +1,85 @@ +#!/bin/bash + + +echo ' + +run-gha() { + #https://stackoverflow.com/questions/6245570/how-do-i-get-the-current-branch-name-in-git + gh workflow run --ref=$(git rev-parse --abbrev-ref HEAD) +} + +glueops-fetch-repos() { + #https://stackoverflow.com/a/68770988/4620962 + + gh repo list $(git remote get-url origin | cut -d/ -f4) --no-archived --limit 1000 | while read -r repo _; do + gh repo clone "$repo" "$repo" -- --depth=1 --recurse-submodules || { + git -C $repo pull + } & + done +} + +yolo() { + # Always unset GITHUB_TOKEN + unset GITHUB_TOKEN + + # If the file doesn'"'"'t exist or '"'"'gh auth status'"'"' returns an exit code of 1 + if [[ ! -f /home/vscode/.config/gh/hosts.yml ]] || ! gh auth status; then + # If the file doesn'"'"'t exist or '"'"'gh auth status'"'"' fails, then proceed with the rest of the script + + # Run the gh auth login command + yes Y | gh auth login -h github.com -p https -w -s repo,workflow,admin:org,write:packages,user,gist,notifications,admin:repo_hook,admin:public_key,admin:enterprise,audit_log,codespace,project,admin:gpg_key,admin:ssh_signing_key + + echo "Set up git with gh auth" + gh auth setup-git + fi +} + + +create-ghcr-regcred() { + gh_username="" + gh_token="" + + # Parse flags + while [[ $# -gt 0 ]]; do + key="$1" + case $key in + (-u|--github-username) + gh_username="$2" + shift + shift + ;; + (-t|--github-token) + gh_token="$2" + shift + shift + ;; + (--help) + echo "Usage: create-ghcr-regcred [options]" + echo "" + echo "Options:" + echo " -u, --github-username VALUE The github username associated with the token" + echo " -t, --github-token VALUE The github token that enables pull access to ghcr" + echo " --help Show this help message and exit" + return + ;; + (*) + echo "Unknown option: $key" + echo "Run 'create-ghcr-regcred --help' for usage information." + return + ;; + esac + done + + # Check if version arguments were provided + if [[ -z $gh_username || -z $gh_token ]]; then + echo "Both arguments are required." + echo "Run 'create-ghcr-regcred --help' for usage information." + return + fi + + set -e + b64_enc_regcred=$(echo -n "$gh_username:$gh_token" | base64) + + echo "{\"auths\":{\"ghcr.io\":{\"auth\":\"$b64_enc_regcred\"}}}" +} +' >> /home/vscode/.bashrc diff --git a/.devcontainer/tools/glueops-fetch-repos b/.devcontainer/tools/glueops-fetch-repos deleted file mode 100755 index ebd0963..0000000 --- a/.devcontainer/tools/glueops-fetch-repos +++ /dev/null @@ -1,7 +0,0 @@ -#https://stackoverflow.com/a/68770988/4620962 - -gh repo list $(git remote get-url origin | cut -d/ -f4) --no-archived --limit 1000 | while read -r repo _; do - gh repo clone "$repo" "$repo" -- --depth=1 --recurse-submodules || { - git -C $repo pull - } & -done diff --git a/.devcontainer/tools/run-gha b/.devcontainer/tools/run-gha deleted file mode 100755 index 69fb059..0000000 --- a/.devcontainer/tools/run-gha +++ /dev/null @@ -1,4 +0,0 @@ -#https://stackoverflow.com/questions/6245570/how-do-i-get-the-current-branch-name-in-git - -gh workflow run --ref=$(git rev-parse --abbrev-ref HEAD) -