Skip to content

Commit

Permalink
fix: zsh and refactor scripts (#159)
Browse files Browse the repository at this point in the history
* fix: zsh to be the default shell by updating how the vscode user is created
fix: scripts so that they are copied to /usr/bin and accessible by all shells with a proper PATH
major: remove run-gha and fetch repos shortct

* feat: update python version to 3.11.10
  • Loading branch information
venkatamutyala authored Oct 6, 2024
1 parent 6c885da commit aefc8d8
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 161 deletions.
19 changes: 15 additions & 4 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,19 @@ ARG VERSION_HASHICORP_PACKER=1.11.2
ENV VAULT_SKIP_VERIFY true
ENV CLOUDSDK_INSTALL_DIR /usr/local/gcloud/

COPY tools/ /etc/tools
RUN chmod +x /etc/tools/add-tools-to-shells.sh && ./etc/tools/add-tools-to-shells.sh
COPY tools/ /etc/tools/

# Install tools to /usr/local/bin
RUN for file in /etc/tools/*; do \
if [ -f "$file" ]; then \
new_name=$(basename "$file" .sh); \
cp "$file" "/usr/local/bin/$new_name"; \
chmod +x "/usr/local/bin/$new_name"; \
echo "Copied and made executable: $new_name"; \
fi; \
done && \
rm -rf /etc/tools

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 tofu_${VERSION_OPENTOFU}_linux_amd64.zip https://github.com/opentofu/opentofu/releases/download/v${VERSION_OPENTOFU}/tofu_${VERSION_OPENTOFU}_linux_amd64.zip \
Expand Down Expand Up @@ -109,7 +120,7 @@ RUN wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor
&& rm vscode_cli.tar.gz

#AWS Debian has a user of admin that uses the UID of 1000. THis is to try and fix that. We are also using UID of 1337 on the system/host level here: https://github.com/GlueOps/development-only-utilities/blob/main/tools/developer-setup/linux-setup.sh#L8
RUN usermod --uid 1337 vscode
RUN usermod --uid 1337 vscode --shell /bin/zsh

ARG NONROOT_USER=vscode
RUN echo "#!/bin/sh\n\
Expand Down Expand Up @@ -154,7 +165,7 @@ RUN code --install-extension yzhang.markdown-all-in-one --extensions-dir /home/v
RUN mkdir -p /home/vscode/.vscode-server
RUN ln -s /home/vscode/.vscode-remote/extensions /home/vscode/.vscode-server/extensions

ADD ../tools/helm-repositories.yaml /home/vscode/.config/helm/repositories.yaml
ADD ../misc-configs/helm-repositories.yaml /home/vscode/.config/helm/repositories.yaml
RUN mkdir -p /home/vscode/.local/share/helm/plugins \
&& curl -L https://github.com/databus23/helm-diff/releases/download/v${VERSION_HELM_DIFF}/helm-diff-linux-amd64.tgz | tar -C /home/vscode/.local/share/helm/plugins -xzv
RUN git config --global --add --bool push.autoSetupRemote true
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"aws-cli": "latest",
"sshd": "latest",
"python": {
"version" : "3.11.8",
"version" : "3.11.10",
"installTools" : true,
"installJupyterlab" : true
},
Expand Down
File renamed without changes.
18 changes: 0 additions & 18 deletions .devcontainer/tools/add-tools-to-shells.sh

This file was deleted.

130 changes: 66 additions & 64 deletions .devcontainer/tools/cordon-drain-nodes-older-than-minutes.sh
Original file line number Diff line number Diff line change
@@ -1,74 +1,76 @@
#!/bin/bash

cordon-drain-nodes-older-than-minutes() {
threshold_minutes=""

while [[ $# -gt 0 ]]; do
key="$1"
case $key in
(-m|--threshold-minutes)
threshold_minutes="$2"
shift
shift
;;
(--help)
echo "Usage: cordon-drain-nodes-older-than-minutes [options]"
echo ""
echo "Options:"
echo " -m, --threshold-minutes VALUE Target nodes older than this many minutes."
echo " --help Show this help message and exit"
return
;;
(*)
echo "Unknown option: $key"
echo "Run 'cordon-drain-nodes-older-than-minutes --help' for usage information."
return
;;
esac
done
threshold_minutes=""

while [[ $# -gt 0 ]]; do
key="$1"
case $key in
(-m|--threshold-minutes)
threshold_minutes="$2"
shift
shift
;;
(--help)
echo "Usage: cordon-drain-nodes-older-than-minutes [options]"
echo ""
echo "Options:"
echo " -m, --threshold-minutes VALUE Target nodes older than this many minutes."
echo " --help Show this help message and exit"
exit 0
;;
(*)
echo "Unknown option: $key"
echo "Run 'cordon-drain-nodes-older-than-minutes --help' for usage information."
exit 1
;;
esac
done

CURRENT_DATE=$(date +%s)
if [ -z "$threshold_minutes" ]; then
echo "Error: --threshold-minutes is required."
echo "Run 'cordon-drain-nodes-older-than-minutes --help' for usage information."
exit 1
fi

NODES=$(kubectl get nodes -o json | jq --arg CURRENT_DATE "$CURRENT_DATE" --arg THRESHOLD_MINUTES "$threshold_minutes" -r '
.items[] |
select(
.metadata.creationTimestamp | fromdateiso8601 < ($CURRENT_DATE | tonumber) - ($THRESHOLD_MINUTES | tonumber * 60)
) | .metadata.name')
CURRENT_DATE=$(date +%s)

if [ -z "$NODES" ]; then
echo "No nodes older than $threshold_minutes minutes found."
exit 0
fi
NODES=$(kubectl get nodes -o json | jq --arg CURRENT_DATE "$CURRENT_DATE" --arg THRESHOLD_MINUTES "$threshold_minutes" -r '
.items[] |
select(
.metadata.creationTimestamp | fromdateiso8601 < ($CURRENT_DATE | tonumber) - ($THRESHOLD_MINUTES | tonumber * 60)
) | .metadata.name')

echo "Nodes found older than $threshold_minutes minutes:"
echo "$NODES"
echo ""
if [ -z "$NODES" ]; then
echo "No nodes older than $threshold_minutes minutes found."
exit 0
fi

echo -n "Cordon the listed nodes? (y/N) "
read response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
echo "$NODES" | while IFS= read -r node; do
echo "Cordoning node: $node"
kubectl cordon "$node"
echo ""
done
else
echo "Cordoning skipped. Will not attempt to drain."
return 0
fi
echo "Nodes found older than $threshold_minutes minutes:"
echo "$NODES"
echo ""

echo -n "Drain the cordoned nodes? (y/N) "
read response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
echo "$NODES" | while IFS= read -r node; do
echo "Draining node: $node"
kubectl drain "$node" --ignore-daemonsets --delete-emptydir-data > "drain-${node}.log" 2>&1 &
done
wait
echo "All nodes drained."
else
echo "Draining skipped."
fi
echo -n "Cordon the listed nodes? (y/N) "
read -r response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
echo "$NODES" | while IFS= read -r node; do
echo "Cordoning node: $node"
kubectl cordon "$node"
echo ""
done
else
echo "Cordoning skipped. Will not attempt to drain."
exit 0
fi

}
echo -n "Drain the cordoned nodes? (y/N) "
read -r response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
echo "$NODES" | while IFS= read -r node; do
echo "Draining node: $node"
kubectl drain "$node" --ignore-daemonsets --delete-emptydir-data > "drain-${node}.log" 2>&1 &
done
wait
echo "All nodes drained."
else
echo "Draining skipped."
fi
86 changes: 43 additions & 43 deletions .devcontainer/tools/create-ghcr-regcred.sh
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
create-ghcr-regcred() {
gh_username=""
gh_token=""
#!/bin/bash

# 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
gh_username=""
gh_token=""

# 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
# 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"
exit 0
;;
(*)
echo "Unknown option: $key"
echo "Run 'create-ghcr-regcred --help' for usage information."
exit 1
;;
esac
done

set -e
b64_enc_regcred=$(echo -n "$gh_username:$gh_token" | base64)
# Check if required arguments were provided
if [[ -z $gh_username || -z $gh_token ]]; then
echo "Error: Both --github-username and --github-token are required."
echo "Run 'create-ghcr-regcred --help' for usage information."
exit 1
fi

echo "{\"auths\":{\"ghcr.io\":{\"auth\":\"$b64_enc_regcred\"}}}"
}
set -e
b64_enc_regcred=$(echo -n "$gh_username:$gh_token" | base64)

echo "{\"auths\":{\"ghcr.io\":{\"auth\":\"$b64_enc_regcred\"}}}"
9 changes: 0 additions & 9 deletions .devcontainer/tools/glueops-fetch-repos.sh

This file was deleted.

4 changes: 0 additions & 4 deletions .devcontainer/tools/run-gha.sh

This file was deleted.

39 changes: 21 additions & 18 deletions .devcontainer/tools/yolo.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
yolo() {
# Always unset GITHUB_TOKEN
unset GITHUB_TOKEN
#!/bin/bash

# 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
# Always unset GITHUB_TOKEN
unset GITHUB_TOKEN

# 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
# 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 &>/dev/null; then
# If the file doesn't exist or 'gh auth status' fails, then proceed with the rest of the script

echo "Set up git with gh auth"
gh auth setup-git
# 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

# Configure git config
git_email=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /user/emails | jq '.[] | select(.primary == true) | .email' -r)
git_name=$(gh api user | jq '.name' -r)
git config --global user.email "${git_email}"
git config --global user.name "${git_name}"
git config --global core.autocrlf input
fi
}
echo "Set up git with gh auth"
gh auth setup-git

# Configure git config
git_email=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /user/emails | jq '.[] | select(.primary == true) | .email' -r)
git_name=$(gh api user | jq '.name' -r)
git config --global user.email "${git_email}"
git config --global user.name "${git_name}"
git config --global core.autocrlf input
else
echo "GitHub authentication is already set up."
gh auth status
fi

0 comments on commit aefc8d8

Please sign in to comment.