Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,29 @@ sjust # Show available commands
sjust --list # List all tasks
sjust docker-ps # Show running containers
sjust system-upgrade # Update system packages
sjust system-gcloud-reconfigure # Configure Google Cloud SDK and install gke-gcloud-auth-plugin
```

### Google Cloud SDK Configuration

Sparkdock automatically installs and configures Google Cloud SDK during provisioning, including the `gke-gcloud-auth-plugin` component required for GKE authentication.

To manually reconfigure Google Cloud SDK:

```bash
sjust system-gcloud-reconfigure
```

This command will:
- Install Google Cloud SDK via Homebrew (if not present)
- Install the `gke-gcloud-auth-plugin` component
- Configure shell completion in your `.zshrc`
- Verify the installation

After configuration, you can verify the plugin is working:

```bash
gke-gcloud-auth-plugin --version
```

### HTTP Proxy
Expand Down
43 changes: 43 additions & 0 deletions ansible/macos/macos/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,49 @@
failed_when: cask_check.rc != 0
become: false

- name: Install Google Cloud SDK components
block:
- name: Check if Google Cloud SDK is installed
shell: brew list --cask google-cloud-sdk >/dev/null 2>&1
register: gcloud_installed
changed_when: false
failed_when: false

- name: Install gke-gcloud-auth-plugin component
shell: |
source {{ homebrew_prefix }}/share/google-cloud-sdk/path.zsh.inc
gcloud components install gke-gcloud-auth-plugin --quiet
register: gcloud_component_install
changed_when: gcloud_component_install.rc == 0
when: gcloud_installed.rc == 0
become: false

- name: Verify gke-gcloud-auth-plugin installation
shell: |
source {{ homebrew_prefix }}/share/google-cloud-sdk/path.zsh.inc
gke-gcloud-auth-plugin --version
register: gcloud_plugin_check
changed_when: false
when: gcloud_installed.rc == 0
become: false

- name: Add Google Cloud SDK to user's zshrc
lineinfile:
path: "{{ ansible_env.HOME }}/.zshrc"
line: "{{ item }}"
create: yes
backup: yes
loop:
- "# The next line updates PATH for the Google Cloud SDK."
- "if [ -f '{{ homebrew_prefix }}/share/google-cloud-sdk/path.zsh.inc' ]; then . '{{ homebrew_prefix }}/share/google-cloud-sdk/path.zsh.inc'; fi"
- ""
- "# The next line enables shell command completion for gcloud."
- "if [ -f '{{ homebrew_prefix }}/share/google-cloud-sdk/completion.zsh.inc' ]; then . '{{ homebrew_prefix }}/share/google-cloud-sdk/completion.zsh.inc'; fi"
Comment on lines +138 to +148

Copilot AI Sep 2, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using lineinfile with a loop to add multiple related lines can result in non-idempotent behavior and scattered placement if the file is modified externally. Consider using blockinfile instead to manage these Google Cloud SDK configuration lines as a single block, which ensures they remain together and can be updated atomically.

Suggested change
lineinfile:
path: "{{ ansible_env.HOME }}/.zshrc"
line: "{{ item }}"
create: yes
backup: yes
loop:
- "# The next line updates PATH for the Google Cloud SDK."
- "if [ -f '{{ homebrew_prefix }}/share/google-cloud-sdk/path.zsh.inc' ]; then . '{{ homebrew_prefix }}/share/google-cloud-sdk/path.zsh.inc'; fi"
- ""
- "# The next line enables shell command completion for gcloud."
- "if [ -f '{{ homebrew_prefix }}/share/google-cloud-sdk/completion.zsh.inc' ]; then . '{{ homebrew_prefix }}/share/google-cloud-sdk/completion.zsh.inc'; fi"
blockinfile:
path: "{{ ansible_env.HOME }}/.zshrc"
create: yes
backup: yes
marker: "# {mark} ANSIBLE MANAGED BLOCK: Google Cloud SDK"
block: |
# The next line updates PATH for the Google Cloud SDK.
if [ -f '{{ homebrew_prefix }}/share/google-cloud-sdk/path.zsh.inc' ]; then . '{{ homebrew_prefix }}/share/google-cloud-sdk/path.zsh.inc'; fi
# The next line enables shell command completion for gcloud.
if [ -f '{{ homebrew_prefix }}/share/google-cloud-sdk/completion.zsh.inc' ]; then . '{{ homebrew_prefix }}/share/google-cloud-sdk/completion.zsh.inc'; fi

Copilot uses AI. Check for mistakes.
when: gcloud_installed.rc == 0
become: false
when: "'google-cloud-sdk' in all_cask_packages"
become: false

- name: Install homebrew packages
community.general.homebrew:
name: "{{ all_homebrew_packages }}"
Expand Down
65 changes: 65 additions & 0 deletions sjust/recipes/00-default.just
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,71 @@ system-install-mkcert:
mkcert -install
echo "mkcert installed successfully!"

# Configure Google Cloud SDK and install required components.
[group('system')]
system-gcloud-reconfigure:
#!/usr/bin/env bash
set -euo pipefail
echo "Configuring Google Cloud SDK..."

# Install gcloud-cli via Homebrew if not already installed
if ! brew list --cask google-cloud-sdk >/dev/null 2>&1; then
echo "Installing Google Cloud SDK via Homebrew..."
brew install --cask google-cloud-sdk
fi

# Get the Homebrew prefix
HOMEBREW_PREFIX=$(brew --prefix)

# Source the gcloud environment
if [[ -f "${HOMEBREW_PREFIX}/share/google-cloud-sdk/path.zsh.inc" ]]; then
echo "Sourcing Google Cloud SDK environment..."
# shellcheck source=/dev/null
source "${HOMEBREW_PREFIX}/share/google-cloud-sdk/path.zsh.inc"
else
echo "❌ Google Cloud SDK path script not found at ${HOMEBREW_PREFIX}/share/google-cloud-sdk/path.zsh.inc"
exit 1
fi

# Install gke-gcloud-auth-plugin component
echo "Installing gke-gcloud-auth-plugin component..."
gcloud components install gke-gcloud-auth-plugin --quiet

# Verify installation
echo "Verifying gke-gcloud-auth-plugin installation..."
if gke-gcloud-auth-plugin --version >/dev/null 2>&1; then
echo "✅ gke-gcloud-auth-plugin installed successfully!"
gke-gcloud-auth-plugin --version
else
echo "❌ Failed to verify gke-gcloud-auth-plugin installation"
exit 1
fi

# Add Google Cloud SDK paths to zshrc if not already present
ZSHRC_FILE="${HOME}/.zshrc"
echo "Updating ${ZSHRC_FILE} with Google Cloud SDK configuration..."

# Create zshrc if it doesn't exist
touch "${ZSHRC_FILE}"

# Check if Google Cloud SDK lines are already in zshrc
if ! grep -q "google-cloud-sdk/path.zsh.inc" "${ZSHRC_FILE}"; then
{
echo ""
echo "# The next line updates PATH for the Google Cloud SDK."
echo "if [ -f '${HOMEBREW_PREFIX}/share/google-cloud-sdk/path.zsh.inc' ]; then . '${HOMEBREW_PREFIX}/share/google-cloud-sdk/path.zsh.inc'; fi"
echo ""
echo "# The next line enables shell command completion for gcloud."
echo "if [ -f '${HOMEBREW_PREFIX}/share/google-cloud-sdk/completion.zsh.inc' ]; then . '${HOMEBREW_PREFIX}/share/google-cloud-sdk/completion.zsh.inc'; fi"
} >> "${ZSHRC_FILE}"
echo "✅ Added Google Cloud SDK configuration to ${ZSHRC_FILE}"
else
echo "✅ Google Cloud SDK configuration already present in ${ZSHRC_FILE}"
fi
Comment on lines +192 to +205

Copilot AI Sep 2, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code includes an unnecessary else branch that only provides informational output. According to the project shell script standards, when checking if things exist, avoid using else branches unless necessary. Remove the else block and keep only the if condition for adding the configuration.

Copilot generated this review using guidance from repository custom instructions.

echo "🎉 Google Cloud SDK reconfiguration completed successfully!"
echo "💡 You may need to restart your terminal or run 'source ~/.zshrc' to use the updated PATH"

# System cleanup to free up disk space (Homebrew and Docker).
[group('system')]
system-cleanup:
Expand Down
Loading