Created
April 23, 2025 12:49
-
-
Save ParkerRex/d305047edcad95b6cda192259b434995 to your computer and use it in GitHub Desktop.
mount-my-bucket
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Below is a concise, step-by-step recap of the process we followed to set up a Google Cloud Storage (GCS) bucket to be mounted in Finder on a Mac using gcsfuse, make it persist across reboots with a Launch Agent, pin it to the Finder sidebar, and add mountgcp and unmountgcp aliases as fallbacks. These instructions are designed to be shared with a friend who wants to replicate the setup. They assume a macOS environment with Homebrew installed and a Google Cloud Platform (GCP) project. The instructions include troubleshooting tips and notes for reliability. | |
Step-by-Step Guide to Mount a Google Cloud Storage Bucket in Finder on macOS | |
This guide shows you how to mount a Google Cloud Storage (GCS) bucket in Finder on a Mac, make it auto-mount at login, pin it to the Finder sidebar, and add terminal aliases for manual mounting/unmounting. It uses gcsfuse with macFUSE and assumes you’re starting from scratch. | |
Prerequisites | |
• macOS with Homebrew installed (brew command available). | |
• A Google Cloud Platform (GCP) project with billing enabled. | |
• Basic terminal knowledge. | |
• Admin access to allow kernel extensions. | |
Step 1: Set Up Google Cloud Platform | |
1 Create a GCP Project: | |
◦ Go to Google Cloud Console. | |
◦ Create a new project (e.g., “Automations”). | |
◦ Note the project ID. | |
2 Create a GCS Bucket: | |
◦ In the GCP Console, navigate to Cloud Storage > Buckets. | |
◦ Click Create Bucket. | |
◦ Configure: | |
▪ Name: Choose a globally unique name (e.g., my-youtube-videos-2025). | |
▪ Location: Select a region (e.g., us-central1) or multi-region. | |
▪ Storage Class: Use Standard. | |
▪ Access Control: Select Uniform. | |
◦ Click Create. | |
◦ Note the bucket name exactly (case-sensitive). | |
3 Create a Service Account: | |
◦ Go to IAM & Admin > Service Accounts. | |
◦ Click Create Service Account. | |
◦ Name: gcsfuse-automation, Description: “For mounting GCS bucket”. | |
◦ Grant the role Storage Admin (or Storage Object Admin for minimal access). | |
◦ Click Done. | |
◦ In the Service Accounts list, click the new account, go to Keys tab, and create a JSON key. | |
◦ Download the key file (e.g., project-id-123456.json). | |
◦ Move it to a secure location: mkdir -p ~/.gcp | |
◦ mv ~/Downloads/project-id-123456.json ~/.gcp/gcsfuse-key.json | |
◦ chmod 600 ~/.gcp/gcsfuse-key.json | |
◦ | |
4 Install Google Cloud CLI (for testing): | |
◦ Run: brew install google-cloud-sdk | |
◦ gcloud init | |
◦ | |
◦ Follow prompts to authenticate with your GCP project. | |
Step 2: Install Dependencies | |
1 Install macFUSE: | |
◦ Install macFUSE to enable file system mounting: brew install --cask macfuse | |
◦ | |
◦ If prompted, go to System Settings > Security & Privacy and Allow the kernel extension. | |
◦ Restart if required. | |
2 Install Go: | |
◦ gcsfuse requires Go to build from source: brew install go | |
◦ go version | |
◦ | |
3 Install gcsfuse: | |
◦ Install gcsfuse to ~/code/go/bin (or adjust based on your GOPATH): go install github.com/googlecloudplatform/gcsfuse@latest | |
◦ | |
◦ Verify: ls -l ~/code/go/bin/gcsfuse | |
◦ Should show an executable (e.g., -rwxr-xr-x ... gcsfuse). | |
◦ If your GOPATH is different, check go env GOPATH and look in /bin. | |
Step 3: Create Mount Script | |
1 Create the Mount Script: | |
◦ Create ~/mount-gcs.sh to mount the bucket: nano ~/mount-gcs.sh | |
◦ | |
◦ Add: #!/bin/bash | |
◦ # Set PATH to include Go binaries | |
◦ export PATH="/Users//code/go/bin:/opt/homebrew/bin:/usr/local/bin:$PATH" | |
◦ export GOOGLE_APPLICATION_CREDENTIALS="$HOME/.gcp/gcsfuse-key.json" | |
◦ # Log PATH and gcsfuse location for debugging | |
◦ echo "PATH is: $PATH" >> ~/gcsfuse.log | |
◦ which gcsfuse >> ~/gcsfuse.log 2>&1 | |
◦ # Wait for network connectivity | |
◦ sleep 10 | |
◦ # Ensure mount point exists | |
◦ mkdir -p ~/gcs-bucket | |
◦ # Unmount any stale mounts | |
◦ umount ~/gcs-bucket 2>/dev/null || diskutil unmount ~/gcs-bucket 2>/dev/null || true | |
◦ # Mount the bucket | |
◦ gcsfuse --implicit-dirs my-youtube-videos-2025 ~/gcs-bucket >> ~/gcsfuse.log 2>&1 | |
◦ | |
◦ Replace with your macOS username (whoami). | |
◦ Replace my-youtube-videos-2025 with your bucket name. | |
◦ Save and exit. | |
◦ Make executable: chmod +x ~/mount-gcs.sh | |
◦ | |
2 Test the Script: | |
◦ Run: bash ~/mount-gcs.sh | |
◦ | |
◦ Check if mounted: ls ~/gcs-bucket | |
◦ | |
◦ Open in Finder: open ~/gcs-bucket | |
◦ | |
◦ Check log for errors: cat ~/gcsfuse.log | |
◦ | |
Step 4: Set Up Auto-Mounting with Launch Agent | |
1 Create Launch Agent: | |
◦ Create ~/Library/LaunchAgents/com.user.mountgcs.plist: nano ~/Library/LaunchAgents/com.user.mountgcs.plist | |
◦ | |
◦ Add: | |
◦ | |
◦ | |
◦ | |
◦ Label | |
◦ com.user.mountgcs | |
◦ ProgramArguments | |
◦ | |
◦ /bin/bash | |
◦ /Users//mount-gcs.sh | |
◦ | |
◦ RunAtLoad | |
◦ | |
◦ KeepAlive | |
◦ | |
◦ StandardOutPath | |
◦ /Users//gcsfuse.log | |
◦ StandardErrorPath | |
◦ /Users//gcsfuse.log | |
◦ | |
◦ | |
◦ | |
◦ Replace with your username. | |
◦ Save and exit. | |
2 Load Launch Agent: | |
◦ Load the Launch Agent: launchctl load ~/Library/LaunchAgents/com.user.mountgcs.plist | |
◦ | |
◦ Verify it’s running: launchctl list | grep com.user.mountgcs | |
◦ | |
◦ Check if mounted: ls ~/gcs-bucket | |
◦ | |
Step 5: Add Finder Sidebar | |
1 Pin to Sidebar: | |
◦ Run the mount script if not mounted: bash ~/mount-gcs.sh | |
◦ | |
◦ In Finder, navigate to ~/gcs-bucket. | |
◦ Right-click and select Add to Sidebar (or drag to Favorites). | |
◦ Test clicking the sidebar link. | |
Step 6: Add `mountgcp` and `unmountgcp` Aliases | |
1 Edit .zshrc: | |
◦ Open: nano ~/.zshrc | |
◦ | |
◦ Find the Aliases - Common section (or add at the end): # GCP Bucket Mounting | |
◦ alias mountgcp='bash ~/mount-gcs.sh' | |
◦ alias unmountgcp='umount ~/gcs-bucket 2>/dev/null || diskutil unmount ~/gcs-bucket 2>/dev/null || true' | |
◦ | |
◦ Save and exit. | |
◦ Apply: source ~/.zshrc | |
◦ | |
2 Test Aliases: | |
◦ Mount: mountgcp | |
◦ ls ~/gcs-bucket | |
◦ | |
◦ Unmount: unmountgcp | |
◦ ls ~/gcs-bucket | |
◦ | |
Step 7: Test with Restart | |
1 Restart Mac: sudo shutdown -r now | |
2 | |
3 Verify: | |
◦ Check if mounted: ls ~/gcs-bucket | |
◦ | |
◦ Click the Finder sidebar link. | |
◦ Check log: cat ~/gcsfuse.log | |
◦ | |
4 Fallback: | |
◦ If not mounted, use: mountgcp | |
◦ | |
Troubleshooting | |
• gcsfuse: command not found: | |
◦ Check log: cat ~/gcsfuse.log. | |
◦ If gcsfuse isn’t found, modify ~/mount-gcs.sh to use the full path: /Users//code/go/bin/gcsfuse --implicit-dirs my-youtube-videos-2025 ~/gcs-bucket >> ~/gcsfuse.log 2>&1 | |
◦ Reload Launch Agent: launchctl unload ~/Library/LaunchAgents/com.user.mountgcs.plist | |
◦ launchctl load ~/Library/LaunchAgents/com.user.mountgcs.plist | |
◦ | |
• macFUSE Issues: | |
◦ Verify: kextstat | grep macfuse | |
◦ Reinstall: brew reinstall --cask macfuse | |
◦ | |
• Bucket Access: | |
◦ Test: gsutil ls gs://my-youtube-videos-2025 | |
◦ Check service account permissions. | |
• Network Delay: | |
◦ Increase sleep 10 to sleep 20 in ~/mount-gcs.sh. | |
Notes | |
• Performance: gcsfuse on macOS isn’t officially supported and may have latency. Test with your files (e.g., YouTube videos). | |
• Alternatives: For better Finder integration, consider CloudMounter or ExpanDrive (paid). | |
• Automation: To trigger actions when files are added, use: fswatch -o ~/gcs-bucket | while read f; do /path/to/your/script.sh; done | |
• Or use GCP Cloud Functions for bucket events. | |
Sharing Tips | |
• Replace and my-youtube-videos-2025 with your friend’s username and bucket name. | |
• Ensure they have Homebrew and a GCP account. | |
• If they don’t use zsh, adjust .zshrc references to .bashrc or equivalent. | |
• Encourage them to check ~/gcsfuse.log for errors and share if they need help. | |
Let me know if you need a specific part clarified or additional details for your friend! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment