Requirements
- Python 3.7+ is installed
- virtualenv is installed
Install the dependencies
- Create a virtual environment:
virtualenv --python python3.7 env
- Activate virtual environment:
source ./env/bin/activate
- Install the dependencies:
pip install -r requirements.txt
Requirements
- A Google Cloud Platform project exists
- gcloud is installed and initialised
-
Enable the required APIs
gcloud services enable pubsub.googleapis.com gcloud services enable cloudfunctions.googleapis.com gcloud services enable vision.googleapis.com
-
Create a service account
gcloud iam service-accounts create photo-analysis-function --display-name "photo-analysis-function"
-
Create a Cloud Pub/Sub Topic:
gcloud pubsub topics create photo-analysis-request
Deploy the Cloud Function.
GCP_PROJECT=YOUR-PROJECT-ID
WP_HOST=https://YOUR-HOST.ORG
GCP_REGION=europe-west1
GCP_TOPIC=photo-analysis-request
# 'beta' is required to set the service account
gcloud --project ${GCP_PROJECT} beta functions deploy photo_analysis \
--runtime python37 \
--trigger-topic ${GCP_TOPIC} \
--region ${GCP_REGION} \
--set-env-vars WP_HOST=${WP_HOST} \
--service-account photo-analysis-function@${GCP_PROJECT}.iam.gserviceaccount.com