diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index d437553..aeed452 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -28,8 +28,8 @@ ARG VERSION_ARGO_CD_CLI=2.8.3 # 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/add-to-bashrc.sh /tmp/add-to-bashrc.sh -RUN chmod +x /tmp/add-to-bashrc.sh && ./tmp/add-to-bashrc.sh +COPY tools/ /tmp/tools +RUN chmod +x /tmp/tools/add-tools-to-shells.sh && ./tmp/tools/add-tools-to-shells.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-tools-to-shells.sh b/.devcontainer/tools/add-tools-to-shells.sh new file mode 100644 index 0000000..34b2f65 --- /dev/null +++ b/.devcontainer/tools/add-tools-to-shells.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +add_tools_to_shells() { + if [ -f "/home/vscode/.bashrc" ]; then + find /tmp/tools/ -type f ! -name "add-tools-to-shells.sh" \ + -exec sh -c 'echo >> /home/vscode/.bashrc; cat "{}" >> /home/vscode/.bashrc' \; + fi + + if [ -d "/home/vscode/.oh-my-zsh/custom" ]; then + find . -type f ! -name "add-tools-to-shells.sh" -name "*.sh" \ + -exec sh -c 'file="{}"; cp "$file" "/home/vscode/.oh-my-zsh/custom/$(basename ${file%.sh}.zsh)"' \; + fi + +} + +add_tools_to_shells diff --git a/.devcontainer/tools/create-ghcr-regcred.sh b/.devcontainer/tools/create-ghcr-regcred.sh new file mode 100644 index 0000000..ff11d86 --- /dev/null +++ b/.devcontainer/tools/create-ghcr-regcred.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +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\"}}}" +} diff --git a/.devcontainer/tools/glueops-fetch-repos.sh b/.devcontainer/tools/glueops-fetch-repos.sh new file mode 100644 index 0000000..2f1eaa1 --- /dev/null +++ b/.devcontainer/tools/glueops-fetch-repos.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +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 +} diff --git a/.devcontainer/tools/run-gha.sh b/.devcontainer/tools/run-gha.sh new file mode 100644 index 0000000..4316810 --- /dev/null +++ b/.devcontainer/tools/run-gha.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +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) +} diff --git a/.devcontainer/tools/yolo.sh b/.devcontainer/tools/yolo.sh new file mode 100644 index 0000000..9c5ffd4 --- /dev/null +++ b/.devcontainer/tools/yolo.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +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 +}