-
Notifications
You must be signed in to change notification settings - Fork 3
Installation ‐ Deployment
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.
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.
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:
- Make sure you have installed and are logged into gCloud CLI
- 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"
- 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.
- Clone the repository to your local machine (if you haven't already)
- 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
- Set up
config.json
file (if you haven't already) - Run the
main.py
script:- Open a terminal
- Navigate using the
cd
command to the root folder of the project. - 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 bemain.py
- 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.
-
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 areroles/bigquery.dataViewer
androles/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
- Clone the repository to Cloud Shell
-
Set up
config.json
file that should be open and ready to edit after clicking the blue button above -
Run the deploy script with the following command in the terminal:
./deploy.sh
-
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 fromGoogle Cloud Platform
->IAM & Admin
- >Service Accounts
- Home
- Project setup
- API Reference
-
Content endpoint
- Query params
-
Body params
- First term source config
- Second term source config
- Output config
- Request examples
- Response examples
- Tasks endpoint
-
Content endpoint