Skip to content

Commit

Permalink
feat: initial version of google-cloud-sql CLI app
Browse files Browse the repository at this point in the history
  • Loading branch information
edosrecki committed Jan 23, 2022
0 parents commit f7cd542
Show file tree
Hide file tree
Showing 40 changed files with 15,986 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# https://editorconfig.org

root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
end_of_line = lf
insert_final_newline = true

[*.adoc]
trim_trailing_whitespace = false

15 changes: 15 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
"@typescript-eslint/no-explicit-any": 2
}
}

37 changes: 37 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Continuous Integration

on: [push]

jobs:
build:
name: Build app
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Read .nvmrc
id: nvmrc
run: echo "::set-output name=node::$(cat .nvmrc)"

- name: Use Node.js ${{ steps.nvmrc.outputs.node }}
uses: actions/setup-node@v2
with:
node-version: ${{ steps.nvmrc.outputs.node }}

- name: Read npm cache
uses: actions/cache@v2
with:
path: ~/.npm
key: node-cache-${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
node-cache-${{ runner.os }}-npm-
- name: Install packages
run: npm ci

- name: Lint
run: npm run lint

- name: Build
run: npm run bundle
168 changes: 168 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,node
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,node

bin/

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

### Node Patch ###
# Serverless Webpack directories
.webpack/

# Optional stylelint cache

# SvelteKit build / generate output
.svelte-kit

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide

# Support for Project snippet scope

# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,node

4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run lint
2 changes: 2 additions & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
16.13.2

5 changes: 5 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"semi": false,
"singleQuote": true,
"printWidth": 90
}
83 changes: 83 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
:toc: macro
:toc-title:
:toclevels: 10

= ⛅ google-cloud-sql

image:https://img.shields.io/github/package-json/v/edosrecki/google-cloud-sql-cli/release?color=blue&label=google-cloud-sql["google-cloud-sql CLI Version"]
image:https://img.shields.io/github/workflow/status/edosrecki/google-cloud-sql-cli/Continuous Integration["Build Status", link="https://github.com/edosrecki/google-cloud-sql-cli/actions"]

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. 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 Kubernetes cluster.

---

toc::[]

== Install
=== Homebrew
[source,bash]
----
brew install edosrecki/tools/google-cloud-sql
# Update
brew upgrade google-cloud-sql
----

=== Releases
Download a corresponding distribution from https://github.com/edosrecki/google-cloud-sql-cli/releases[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 https://cloud.google.com/sdk/docs/install[`gcloud`] tool
* Install https://kubernetes.io/docs/tasks/tools/#kubectl[`kubectl`] tool
* Authenticate to Google Cloud: `gcloud auth login`
* Get GKE cluster credentials: `gcloud container clusters get-credentials`

=== Run
[source,bash]
----
# Help
google-cloud-sql help
# Create configuration
google-cloud-sql configurations create
# Run configuration
google-cloud-sql configurations run
## Connect to the instance on localhost
psql -h localhost -p <LOCAL_PORT> -U <USER>
----

== Build
[source,bash]
----
npm run clean
npm run build
----

== Package
=== Pre-configured
Package the app for Node.JS 16 on MacOS, Linux, and Windows.

[source,bash]
----
npm run bundle
----

=== Manual
See https://www.npmjs.com/package/pkg#targets[pkg] for details.

[source,bash]
----
npx pkg <NODE_RANGE>-<PLATFORM>-<ARCH>
----
Loading

0 comments on commit f7cd542

Please sign in to comment.