Skip to content

Commit

Permalink
feat(gcloud): add gcloud and gcloud-login commands
Browse files Browse the repository at this point in the history
1. run `script.sh` to install the new commands.
2. run `gcloud-login` to authorize your CLI make changes on you account.
3. run `gcloud` to have fun.

Closes #18
  • Loading branch information
DavidCardoso committed Sep 12, 2023
1 parent 445e4c7 commit 76436ae
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Tools via **Unix Command Line Interface** with no installation and just using **
- [Serverless Framework](#serverless-framework)
- [Terraform](#terraform)
- [Ookla Speedtest CLI](#ookla-speedtest-cli)
- [Google Cloud CLI](#google-cloud-cli)
- [Author](#author)
- [Contributors](#contributors)

Expand All @@ -30,6 +31,7 @@ Tools via **Unix Command Line Interface** with no installation and just using **
It adds aliases to your `~/.zshrc` file and symbolic links to your `/usr/local/bin/` folder:

```shell
# Run this script and choose an option
./setup.sh
```

Expand Down Expand Up @@ -229,6 +231,28 @@ speedtest --help
speedtest
```
### Google Cloud CLI
```shell
# If are not logged in, run the command below and follow the steps:
# 1. Copy/paste the provided URL in your browser
# 2. Authorize using your Google account
# 3. Copy/paste the generated auth code back in your terminal
gcloud-login

# If your current project is [None] or you wanna change it, set one.
gcloud config set project <PROJECT_ID>

# Test if it is working...
gcloud version
gcloud help
gcloud storage ls
```
> [gcloud CLI overview](https://cloud.google.com/sdk/gcloud).
> [gcloud auth login](https://cloud.google.com/sdk/gcloud/reference/auth/login).
## Author
[David Cardoso](https://github.com/DavidCardoso)
Expand Down
13 changes: 13 additions & 0 deletions bin/gcloud
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
set -e

IMAGE=eu.gcr.io/google.com/cloudsdktool/google-cloud-cli:latest
WORKDIR=/app

# run from your working directory
docker run -it --rm \
--volume $PWD:$WORKDIR \
--volumes-from gcloud-config \
--workdir $WORKDIR \
--entrypoint gcloud \
$IMAGE "${@}"
19 changes: 19 additions & 0 deletions bin/gcloud-login
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh
set -e

IMAGE=eu.gcr.io/google.com/cloudsdktool/google-cloud-cli:latest
WORKDIR=/app

# Remove previous auth configs
if [[ $(docker ps --all | grep gcloud-config) ]]; then
echo "Removing previous $(gcloud-config) container..."
docker rm gcloud-config
fi

# run from your working directory
docker run -it \
--volume $PWD:$WORKDIR \
--workdir $WORKDIR \
--entrypoint gcloud \
--name gcloud-config \
$IMAGE auth login
13 changes: 12 additions & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Type the number of the OPTION:
# serverless: Serverless Framework CLI
# terraform: Terraform CLI
# speedtest: Ookla Speedtest CLI
# gcloud: Google Cloud CLI
# EXIT: To leave this menu
==============================================================
EOF
Expand Down Expand Up @@ -98,21 +99,30 @@ install_speedtest() {
show_msg "Activating speedtest..."
}

install_gcloud() {
sudo ln -sf ${BASEDIR}/bin/gcloud-login /usr/local/bin/gcloud-login
show_msg "Activating gcloud-login..."

sudo ln -sf ${BASEDIR}/bin/gcloud /usr/local/bin/gcloud
show_msg "Activating gcloud..."
}

install_all() {
install_aws
install_node
install_yarn
install_serverless
install_terraform
install_speedtest
install_gcloud
}

# Main

show_begin

PS3="Choose an option: "
select opt in ALL aws node yarn serverless terraform speedtest EXIT; do
select opt in ALL aws node yarn serverless terraform speedtest gcloud EXIT; do
case ${opt} in
ALL) install_all ;;
aws) install_aws ;;
Expand All @@ -121,6 +131,7 @@ select opt in ALL aws node yarn serverless terraform speedtest EXIT; do
serverless) install_serverless ;;
terraform) install_terraform ;;
speedtest) install_speedtest ;;
gcloud) install_gcloud ;;
EXIT) show_msg "Bye o/" ;;
*) show_help "Error: incorrect option." && exit 2 ;;
esac
Expand Down

0 comments on commit 76436ae

Please sign in to comment.