Skip to content

Installation ‐ Deployment

Juan Gabriel Griggio edited this page Jan 21, 2025 · 14 revisions

This project has two main running options. The first one is locally like any other Python project, running the script main.py. The second one is in GCP via Google Cloud Run.

Google Cloud Platform (GCP) roles needed

There are some GCP roles that are needed to run this project. Please read the roles needed section for the running mode that you will be using.

[Option 1] Run locally

This running mode is intended for single time runs, runs with different parameters every time or for testing before deployment. If you are going to be running this project regularly with the same config, refer to Option 2.

Before starting:

  1. Make sure you have installed and are logged into gCloud CLI
  2. Make sure you have Application Default Credentials (ADC) set up correctly with the necessary scopes before running the project.
    • To do so, run the following command in the terminal:
gcloud auth application-default login --scopes "https://www.googleapis.com/auth/adwords,https://www.googleapis.com/auth/bigquery,https://www.googleapis.com/auth/spreadsheets,https://www.googleapis.com/auth/drive,https://www.googleapis.com/auth/cloud-platform"
  1. Make sure the spreadsheet(s) that are going to be used are shared with the Google account that is logged in to GCP locally with edit permission.

Wait a minute! Do I also need a GCP account even if I'm not going to run it in GCP? Yes, the usage of Google APIs do require a GCP account regardless of the environment your code is going to run on.

Instructions

  1. Clone the repository to your local machine (if you haven't already)
    1. For that, you need to have Git installed in your machine and run the following command in a terminal:
    git clone https://github.com/google-marketing-solutions/topic-mine
  2. Set up config.json file (if you haven't already)
  3. Run the main.py script:
    1. Open a terminal
    2. Navigate using the cd command to the root folder of the project.
    3. Check that you are in the right folder with the command ls. It should show a list of files and directories, and one of them should be main.py
    4. Run the python file with the following command (check which one works for you):
    python main.py
    python3 main.py

[Option 2] Deploy in Google Cloud Run

This running mode is intended for scheduling recurring runs (e.g.: once a week). For single time runs or if you are going to be changing parameters regularly, refer to Option 1.

GCP roles needed for the account that will be executing the deploy script

  • Cloud Run Admin (roles/run.admin) to create and deploy a new Cloud Run service
  • Service Account Admin (roles/iam.serviceAccountAdmin) to create the service account that will be the one used by Topic Mine and assign its corresponding roles, which are roles/bigquery.dataViewer and roles/run.invoker
  • Service Usage Admin (roles/serviceusage.serviceUsageAdmin) to enable the required APIs in the GCP project
  • Cloud Scheduler Admin (roles/cloudscheduler.admin) optional, only needed to create a recurring Cloud Scheduler job

Instructions

  1. Clone the repository to Cloud Shell

Open in Cloud Shell

  1. Set up config.json file that should be open and ready to edit after clicking the blue button above

  2. Run the deploy script with the following command in the terminal:

    ./deploy.sh
  3. Share the spreadsheet(s) that are going to be used with the newly-created service account with edit permission. That service account is the one specified in the config.json file, and its full address can be retrieved from Google Cloud Platform -> IAM & Admin - > Service Accounts

Clone this wiki locally