-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup
executable file
·55 lines (44 loc) · 1.84 KB
/
setup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
DIR="$(dirname "$0")"
. "${DIR}/config"
# Required services
gcloud services enable --quiet \
bigquery-json.googleapis.com \
bigquerystorage.googleapis.com \
compute.googleapis.com \
cloudbuild.googleapis.com \
dataflow.googleapis.com \
iam.googleapis.com \
pubsub.googleapis.com \
run.googleapis.com
# PubSub
gcloud pubsub topics create $SERVICE_NAME
# BigQuery
bq mk $SERVICE_NAME
bq mk --schema id:string,repo:string,type:string,actor:string,event_time:timestamp,countable:boolean \
-t "${SERVICE_NAME}.events"
# Dataflow
gcloud dataflow jobs run $SERVICE_NAME \
--gcs-location gs://dataflow-templates/latest/PubSub_to_BigQuery \
--region $SERVICE_REGION \
--parameters "inputTopic=projects/${PROJECT}/topics/${SERVICE_NAME},outputTableSpec=${PROJECT}:${SERVICE_NAME}.events"
# Account
gcloud iam service-accounts create "${SERVICE_NAME}-sa" \
--display-name "Service Invoker Account for ${SERVICE_NAME}" \
--quiet
gcloud beta run services add-iam-policy-binding $SERVICE_NAME \
--member="serviceAccount:${SERVICE_NAME}-sa@${PROJECT}.iam.gserviceaccount.com" \
--region="${SERVICE_REGION}" \
--role=roles/run.invoker
gcloud projects add-iam-policy-binding $PROJECT \
--member "serviceAccount:${SERVICE_NAME}-sa@${PROJECT}.iam.gserviceaccount.com" \
--role roles/pubsub.publisher
gcloud projects add-iam-policy-binding $PROJECT \
--member "serviceAccount:${SERVICE_NAME}-sa@${PROJECT}.iam.gserviceaccount.com" \
--role roles/logging.logWriter
gcloud projects add-iam-policy-binding $PROJECT \
--member "serviceAccount:${SERVICE_NAME}-sa@${PROJECT}.iam.gserviceaccount.com" \
--role roles/cloudtrace.agent
gcloud projects add-iam-policy-binding $PROJECT \
--member "serviceAccount:${SERVICE_NAME}-sa@${PROJECT}.iam.gserviceaccount.com" \
--role roles/monitoring.metricWriter