Releasing macOS app on GCP — Part 3

Margaryta Chepiga
Tumiya
Published in
4 min readDec 30, 2019

This is the third part of the series, you can find the rest below:

How to install gcloud on Bitrise

Okay, this is probably the hardest part of the entire series. But, follow me, it will be alright.

The problem is that we can’t simply run one command to install gcloud on the Bitrise. Therefore, we have to go through some steps. Those steps and the scripts they include were written by Azadeh Bagheri that she kindly shared with me.

First, proceed to google sdk documentation:

Scroll down to the section you see above.

Then download the macOS 64-bit (x86_64) archive:

Once the download complete, extract the content of the folder to any location on your file system.

For now I just unzipped the folder.

Now, the big picture of what we are going to do next:

  • Create a repository for our google-cloud-sdk on GitLab
  • Push the google-cloud-sdk to that repository
  • Write a script to configure our gcloud

Create GitLab Repo

Now, let’s set up our newly create repo on our local machine, open the terminal and start typing!

$ git clone ssh://git@gitlab..../gcloud-sdk-demo.git

P.S you can find your repo url, if you click on the Clone button and copy the url under the Clone with SSH.

Now, let’s move our downloaded unzipped folder to our newly created repo:

// move inside your repo
$ cd glcoud-sdk-demo/
// move unzipped google cloud sdk from downloads folder to current working directory (our cloned repo)
$ mv ../Downloads/google-cloud-sdk .

Next step is to push the change:

$ git add .
$ git commit -m "Adding gcloud sdk"
$ git push

Now, we need to create the script file (I named mine config-gcloud.sh) to configure gcloud and place it inside our repo but outside the google-cloud-sdk folder:

Repo structure

Inside the config-gcloud.sh, put the following:

#!/usr/bin/env bash# getting the directory name that holds the sdk 
directory_name=$(dirname $(find $(pwd) -name google-cloud-sdk))
# adding Cloud SDK tools to your path
source $directory_name/google-cloud-sdk/path.bash.inc
echo "Currently running:" $(gcloud version)# service account credentials should be stored in an environment variable named GCP_KEY_JSON.
# credentials should be saved in a json file to be used for authentication to gcr.
echo $GCP_KEY_JSON > ./gcloud_key.json
gcloud auth activate-service-account --key-file=./gcloud_key.json
echo "gcloud setup completed!"

Now you can save the script and proceed back to the Bitrise workflow that we modified earlier.

To be able to use gcloud commands on bitrise, you need to add the following to your script:

git clone ssh://your-url-to-the-repo# call the script
bash ./gcloud-SDK/config-gcloud.sh
#To be able to use the gcloud in other steps
envman add --key PATH --value $PATH:${PWD}/gcloud-SDK/google-cloud-sdk/bin

Save the changes in your workflow. But don’t run the pipeline just yet.

For next steps, continue to the next part of the series.

--

--

Margaryta Chepiga
Tumiya
Writer for

Software Developer, known as overexcited girl who is passionate about technology