|
1 | 1 | # gcp-sql-proxy |
2 | | -Google Cloud Platform SQL Proxy extension |
| 2 | +[Google Cloud Platform SQL Proxy extension](https://github.com/GoogleCloudPlatform/cloud-sql-proxy) |
| 3 | + |
| 4 | +## Why |
| 5 | + |
| 6 | +When working with GCP SQL Proxy, it is a burden to keep configuration for |
| 7 | +different connections easily. This extension allows to define multiple |
| 8 | +connections available to easy pick up. e.g. |
| 9 | + |
| 10 | +having: |
| 11 | +```ini |
| 12 | +# $HOME/.config/gcp-sql-proxy/conf.ini |
| 13 | +[development] |
| 14 | +instances=xxx:xxx:xxx=tcp:15432 |
| 15 | +``` |
| 16 | + |
| 17 | +we can run |
| 18 | +```bash |
| 19 | +gcp-sql-proxy development |
| 20 | +``` |
| 21 | + |
| 22 | +Above command will match the ini section by name and apply all arguments |
| 23 | +defined. It translates to |
| 24 | +```bash |
| 25 | +cloud_sql_proxy -instance=xxx:xxx:xxx=tcp:15432 |
| 26 | +``` |
| 27 | + |
| 28 | +Since all args of `cloud_sql_proxy` are prefixed with a single dash, the |
| 29 | +extension appends the slash to all parameters defined in the `conf.ini` section. |
| 30 | + |
| 31 | +## Systemd unit support |
| 32 | + |
| 33 | +The extension provides systemd unit template called `gcp-sql-proxy`. |
| 34 | + |
| 35 | +Having a `conf.ini` defined, we can run a proxy as a systemd unit. And launch |
| 36 | +several units as well. For example: |
| 37 | +```ini |
| 38 | +# $HOME/.config/gcp-sql-proxy/conf.ini |
| 39 | +[development] |
| 40 | +instances=xxx:xxx:xxx=tcp:15432 |
| 41 | + |
| 42 | +[production] |
| 43 | +instances=yyy:yyy:yyy=tcp:25432 |
| 44 | +``` |
| 45 | +we can enable and start systemd units |
| 46 | +```bash |
| 47 | +> systemctl --user enable --now gcp-sql-proxy@production |
| 48 | +> systemctl --user enable --now gcp-sql-proxy@development |
| 49 | +``` |
| 50 | +Now, we have two units up and running in the background. Each attach GCP SQL |
| 51 | +Proxy to a defined port: |
| 52 | + |
| 53 | +- `production` on port `2543` |
| 54 | +- `development` on port `1543` |
| 55 | + |
| 56 | + |
| 57 | +## Install |
| 58 | +The instalation is for now managed by GNU Stow, so **GNU Stow is required**. |
| 59 | + |
| 60 | +```bash |
| 61 | +> make all |
| 62 | +``` |
0 commit comments