Git Product home page Git Product logo

google-cloud-sql-cli's Introduction

⛅ google-cloud-sql

google-cloud-sql CLI Version Build Status

A CLI app which establishes a connection to a private Google Cloud SQL instance and port-forwards it to a local machine.

Connection is established by running a Google Cloud SQL Auth Proxy pod in a Google Kubernetes Engine cluster which runs in the same VPC network as the private Cloud SQL instance. Connection is then port-forwarded to the local machine, where a user can connect to the instance on localhost. Corresponding workload identity has to be configured in the cluster, with service account which has Cloud SQL Client role on the given SQL instance. Configurations in the app can be saved for practical future usage.

The app relies on local gcloud and kubectl commands which have to be configured and authenticated with the proper Google Cloud user and GKE Kubernetes cluster.

screenshot

Install

Homebrew

brew install edosrecki/tools/google-cloud-sql

# Update
brew upgrade google-cloud-sql

Releases

Download a corresponding distribution from Releases and add the executable to your PATH.

Build from source

Build the app from source by building and packaging it manually: see Build and Package sections.

Use

Prerequisites

  • Install gcloud tool

  • Install kubectl tool

  • Authenticate to Google Cloud: gcloud auth login

  • Get GKE cluster credentials: gcloud container clusters get-credentials

  • Configure workload identity in GKE namespace(s) and assign Cloud SQL Client role in IAM for Cloud SQL instances that you want to use

  • Enable Cloud SQL Admin API for project(s) that host Cloud SQL instances that you want to use: gcloud services enable sqladmin.googleapis.com --project=$PROJECT

Run

# Help
google-cloud-sql help

# Create (or override existing) configuration
google-cloud-sql configurations create

# Run configuration (interactive mode)
google-cloud-sql configurations run
# Run configuration (non-interactive mode)
google-cloud-sql configurations run $NAME
# HINT: Add alias
alias myDbProd="google-cloud-sql configurations run $NAME"

## Connect to the instance on localhost
psql -h localhost -p $LOCAL_PORT -U $USER

# Export configurations (and share :-])
cat $(google-cloud-sql configurations path)

Build

npm run clean
npm run build

Package

Pre-configured

Package the app for Node.JS 18 on MacOS, Linux, and Windows.

npm run bundle

Manual

See pkg for details.

npx pkg <NODE_RANGE>-<PLATFORM>-<ARCH>

Deploy

To deploy a new version of google-cloud-sql app, manually run a "Continuous Deployment" worklow in GitHub Actions.

Todo

  • Add snap for Linux

  • Add completions

  • Cache user’s running pods, and alert user on next startup if they were not cleaned up on previous app exit.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.