Skip to content

Commit 66f1d9c

Browse files
committed
warnings when integ test is run on a new project
1 parent d78c229 commit 66f1d9c

13 files changed

+166
-84
lines changed

.gcloudignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11

22
test_scripts/
3-
3+
uninstall_scripts/
4+
scripts/
45
sample_data/
5-
memray/
6+
67
README.md
78
*.sh
89
TEMP*

deploy.sh

+8-2
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,20 @@ if [[ "$deploy_org" != "true" ]] && [[ "$deploy_proj" != "true" ]]; then
105105
deploy_proj=true
106106
fi
107107

108+
gcloud services enable cloudresourcemanager.googleapis.com --project $PROJECT_ID > /dev/null ||true
109+
108110
gcloud projects describe "$PROJECT_ID" >/dev/null || {
109111
echo "Project $PROJECT_ID not found"
110112
exit 1
111113
}
112114

113-
gcloud auth application-default set-quota-project $PROJECT_ID > /dev/null 2>&1
114-
gcloud config set project "$PROJECT_ID" > /dev/null 2>&1
115+
gcloud config set project "$PROJECT_ID" > /dev/null
116+
117+
export LOG_SINK=iris_log
115118

119+
# Get organization id for this project
120+
ORGID=$(gcloud projects get-ancestors "$PROJECT_ID" --format='value(TYPE,ID)' | awk '/org/ {print $2}')
121+
export ORGID
116122

117123
if [[ "$deploy_org" == "true" ]]; then
118124
./scripts/_deploy-org.sh || exit 1

scripts/_deploy-org.sh

+4-19
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@
77
#set -x
88
# The following lines must come before set -u
99
if [[ -z "$IRIS_CUSTOM_ROLE" ]]; then IRIS_CUSTOM_ROLE=iris3; fi
10-
if [[ -z "$SKIP_ADDING_IAM_BINDINGS" ]]; then SKIP_ADDING_IAM_BINDINGS=""; fi
1110
set -u
1211
set -e
1312

14-
LOG_SINK=iris_log
15-
16-
# Get organization id for this project
17-
ORGID=$(gcloud projects get-ancestors "$PROJECT_ID" --format='value(TYPE,ID)' | awk '/org/ {print $2}')
1813

1914
set +e
2015
# Create custom role to run iris
@@ -50,13 +45,12 @@ fi
5045
gcloud organizations add-iam-policy-binding "$ORGID" \
5146
--member "serviceAccount:$PROJECT_ID@appspot.gserviceaccount.com" \
5247
--role "organizations/$ORGID/roles/$IRIS_CUSTOM_ROLE" \
53-
--condition=None >/dev/null 2>&1
48+
--condition=None >/dev/null
5449

5550
if [[ "$LABEL_ON_CREATION_EVENT" != "true" ]]; then
5651
echo >&2 "Will not label on creation event."
5752
gcloud logging sinks delete -q --organization="$ORGID" "$LOG_SINK" || true
5853
else
59-
# Create PubSub topic for receiving logs about new GCP objects
6054

6155
log_filter=("")
6256

@@ -91,26 +85,17 @@ else
9185
log_filter+=(')')
9286

9387
# Create or update a sink at org level
88+
# Logs topic does not yet exist!
9489
if ! gcloud logging sinks describe --organization="$ORGID" "$LOG_SINK" >&/dev/null; then
9590
gcloud logging sinks create "$LOG_SINK" \
9691
pubsub.googleapis.com/projects/"$PROJECT_ID"/topics/"$LOGS_TOPIC" \
9792
--organization="$ORGID" --include-children \
98-
--log-filter="${log_filter[*]}" --quiet >/dev/null 2>&1
93+
--log-filter="${log_filter[*]}" --quiet >/dev/null
9994
else
10095
gcloud logging sinks update "$LOG_SINK" \
10196
pubsub.googleapis.com/projects/"$PROJECT_ID"/topics/"$LOGS_TOPIC" \
10297
--organization="$ORGID" \
103-
--log-filter="${log_filter[*]}" --quiet >/dev/null 2>&1
98+
--log-filter="${log_filter[*]}" --quiet >/dev/null
10499
fi
105100

106-
# Extract service account from sink configuration.
107-
# This is the service account that publishes to PubSub.
108-
svcaccount=$(gcloud logging sinks describe --organization="$ORGID" "$LOG_SINK" |
109-
grep writerIdentity | awk '{print $2}')
110-
111-
if [[ "$SKIP_ADDING_IAM_BINDINGS" != "true" ]]; then
112-
# Assign a publisher role to the extracted service account.
113-
gcloud projects add-iam-policy-binding "$PROJECT_ID" \
114-
--member="$svcaccount" --role=roles/pubsub.publisher --quiet >/dev/null 2>&1
115-
fi
116101
fi

scripts/_deploy-project.sh

+45-19
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,18 @@ fi
3636
appengineHostname=$(gcloud app describe --project $PROJECT_ID | grep defaultHostname | cut -d":" -f2 | awk '{$1=$1};1')
3737
if [[ -z "$appengineHostname" ]]; then
3838
echo "App Engine is not enabled in $PROJECT_ID.
39-
To do this, please enable it with \"gcloud app create [--region=REGION]\",
40-
and then deploy a simple \"Hello World\" default service to enable App Engine."
39+
As a pre-req for this, as for all App Engine services, please
40+
(1) Create the app with \"gcloud app create [--region=REGION]\",
41+
(2) and then deploy a simple \"Hello World\" default-service."
4142
exit 1
4243
fi
4344

4445
appengine_sa_has_editor_role=$(gcloud projects get-iam-policy ${PROJECT_ID} \
4546
--flatten="bindings[].members" \
46-
--format='table(bindings.role)' \
47+
--format='table[no-heading](bindings.role)' \
4748
--filter="bindings.members:${PROJECT_ID}@appspot.gserviceaccount.com" | grep "roles/editor" || true)
4849

50+
4951
if [ -z "$appengine_sa_has_editor_role" ]; then
5052
echo "Must bind role Project Editor for project ${PROJECT_ID} to service account ${PROJECT_ID}@appspot.gserviceaccount.com.
5153
(The binding exists by default but is missing.)"
@@ -79,10 +81,35 @@ required_svcs=(
7981
)
8082
for svc in "${required_svcs[@]}"; do
8183
if ! [ ${enabled_services["$svc"]+_} ]; then
82-
gcloud services enable "$svc"
84+
gcloud services enable "$svc" --project $PROJECT_ID
8385
fi
8486
done
8587

88+
89+
# Extract service account from sink configuration.
90+
# This is the service account that publishes to PubSub.
91+
sink_svc_account=$(gcloud logging sinks describe --organization="$ORGID" "$LOG_SINK" |
92+
grep writerIdentity | awk '{print $2}')
93+
94+
if [[ "$SKIP_ADDING_IAM_BINDINGS" != "true" ]]; then
95+
# Assign a publisher role to the extracted service account.
96+
gcloud projects add-iam-policy-binding "$PROJECT_ID" \
97+
--member="$sink_svc_account" --role=roles/pubsub.publisher --quiet >/dev/null
98+
else
99+
#Check to avoid situation where a test does SKIP_ADDING_IAM_BINDINGS and they don't at all exist
100+
already_have_binding=$( gcloud projects get-iam-policy $PROJECT_ID \
101+
--flatten="bindings[].members" \
102+
--format='table[no-heading](bindings.role)' \
103+
--filter="bindings.members:${sink_svc_account}" |grep "pubsub.publisher" ||true)
104+
105+
if [ -z $already_have_binding ]; then
106+
echo "SKIP_ADDING_IAM_BINDINGS is meant for tests
107+
(to avoid overloading the quotas when you repeated run the tests).
108+
First deploy the usual way before running the tests."
109+
exit 1
110+
fi
111+
fi
112+
86113
# Create PubSub topic for receiving commands from the /schedule handler that is triggered from cron
87114
gcloud pubsub topics describe "$SCHEDULELABELING_TOPIC" --project="$PROJECT_ID" &>/dev/null ||
88115
gcloud pubsub topics create "$SCHEDULELABELING_TOPIC" --project="$PROJECT_ID" --quiet >/dev/null
@@ -99,21 +126,21 @@ if gcloud pubsub subscriptions describe "$DEADLETTER_SUB" --project="$PROJECT_ID
99126
gcloud pubsub subscriptions update $DEADLETTER_SUB \
100127
--project="$PROJECT_ID" \
101128
--message-retention-duration=2d \
102-
--quiet >/dev/null 2>&1
129+
--quiet >/dev/null
103130

104131
else
105132
gcloud pubsub subscriptions create $DEADLETTER_SUB \
106133
--project="$PROJECT_ID" \
107134
--topic $DEADLETTER_TOPIC \
108135
--message-retention-duration=2d \
109-
--quiet >/dev/null 2>&1
136+
--quiet >/dev/null
110137
fi
111138

112139
project_number=$(gcloud projects describe $PROJECT_ID --format json | jq -r '.projectNumber')
113140
PUBSUB_SERVICE_ACCOUNT="service-${project_number}@gcp-sa-pubsub.iam.gserviceaccount.com"
114141
# The following line is only needed on first deployment, and so slows things
115142
# down unnecessarily otherwise. But most users do not install Iris repeatedly.
116-
gcloud beta services identity create --project $PROJECT_ID --service pubsub >/dev/null 2>&1
143+
gcloud beta services identity create --project $PROJECT_ID --service pubsub >/dev/null
117144

118145
if ! gcloud iam service-accounts describe iris-msg-sender@${PROJECT_ID}.iam.gserviceaccount.com --project $PROJECT_ID >/dev/null ;
119146
then
@@ -139,7 +166,7 @@ then
139166
--dead-letter-topic=$DEADLETTER_TOPIC \
140167
--min-retry-delay=$MIN_RETRY \
141168
--max-retry-delay=$MAX_RETRY \
142-
--quiet >/dev/null 2>&1
169+
--quiet >/dev/null
143170
else
144171
gcloud pubsub subscriptions create "$DO_LABEL_SUBSCRIPTION" \
145172
--topic "$SCHEDULELABELING_TOPIC" --project="$PROJECT_ID" \
@@ -150,7 +177,7 @@ else
150177
--dead-letter-topic=$DEADLETTER_TOPIC \
151178
--min-retry-delay=$MIN_RETRY \
152179
--max-retry-delay=$MAX_RETRY \
153-
--quiet >/dev/null 2>&1
180+
--quiet >/dev/null
154181
fi
155182

156183
if [[ "$LABEL_ON_CREATION_EVENT" != "true" ]];
@@ -160,7 +187,7 @@ then
160187
else
161188
# Create PubSub topic for receiving logs about new GCP objects
162189
gcloud pubsub topics describe "$LOGS_TOPIC" --project="$PROJECT_ID" &>/dev/null ||
163-
gcloud pubsub topics create $LOGS_TOPIC --project="$PROJECT_ID" --quiet >/dev/null 2>&1
190+
gcloud pubsub topics create $LOGS_TOPIC --project="$PROJECT_ID" --quiet >/dev/null
164191

165192
# Create or update PubSub subscription for receiving log about new GCP objects
166193
if gcloud pubsub subscriptions describe "$LABEL_ONE_SUBSCRIPTION" --project="$PROJECT_ID" &>/dev/null ;
@@ -173,7 +200,7 @@ else
173200
--dead-letter-topic=$DEADLETTER_TOPIC \
174201
--min-retry-delay=$MIN_RETRY \
175202
--max-retry-delay=$MAX_RETRY \
176-
--quiet >/dev/null 2>&1
203+
--quiet >/dev/null
177204
else
178205
gcloud pubsub subscriptions create "$LABEL_ONE_SUBSCRIPTION" \
179206
--topic "$LOGS_TOPIC" --project="$PROJECT_ID" \
@@ -184,15 +211,14 @@ else
184211
--dead-letter-topic=$DEADLETTER_TOPIC \
185212
--min-retry-delay=$MIN_RETRY \
186213
--max-retry-delay=$MAX_RETRY \
187-
--quiet >/dev/null 2>&1
214+
--quiet >/dev/null
188215
fi
189216

190217
fi
191218

192219
gcloud pubsub topics describe "$LABEL_ALL_TOPIC" --project="$PROJECT_ID" &>/dev/null ||
193220
gcloud pubsub topics create $LABEL_ALL_TOPIC --project="$PROJECT_ID" --quiet >/dev/null
194221

195-
196222
if gcloud pubsub subscriptions describe "$LABEL_ALL_SUBSCRIPTION" --project="$PROJECT_ID" &>/dev/null; then
197223
gcloud pubsub subscriptions update "$LABEL_ALL_SUBSCRIPTION" \
198224
--project="$PROJECT_ID" \
@@ -203,7 +229,7 @@ if gcloud pubsub subscriptions describe "$LABEL_ALL_SUBSCRIPTION" --project="$PR
203229
--dead-letter-topic=$DEADLETTER_TOPIC \
204230
--min-retry-delay=$MIN_RETRY \
205231
--max-retry-delay=$MAX_RETRY \
206-
--quiet >/dev/null 2>&1
232+
--quiet >/dev/null
207233
else
208234
gcloud pubsub subscriptions create "$LABEL_ALL_SUBSCRIPTION" \
209235
--topic "$LABEL_ALL_TOPIC" --project="$PROJECT_ID" \
@@ -221,28 +247,28 @@ if [[ "$LABEL_ON_CREATION_EVENT" == "true" ]]; then
221247
# Allow Pubsub to delete failed message from this sub
222248
gcloud pubsub subscriptions add-iam-policy-binding $DO_LABEL_SUBSCRIPTION \
223249
--member="serviceAccount:$PUBSUB_SERVICE_ACCOUNT" \
224-
--role="roles/pubsub.subscriber" --project $PROJECT_ID >/dev/null 2>&1
250+
--role="roles/pubsub.subscriber" --project $PROJECT_ID >/dev/null
225251

226252
fi
227253

228254
gcloud pubsub subscriptions add-iam-policy-binding $LABEL_ALL_SUBSCRIPTION \
229255
--member="serviceAccount:$PUBSUB_SERVICE_ACCOUNT" \
230-
--role="roles/pubsub.subscriber" --project $PROJECT_ID >/dev/null 2>&1
256+
--role="roles/pubsub.subscriber" --project $PROJECT_ID >/dev/null
231257

232258
# Allow Pubsub to delete failed message from this sub
233259
gcloud pubsub subscriptions add-iam-policy-binding $LABEL_ONE_SUBSCRIPTION \
234260
--member="serviceAccount:$PUBSUB_SERVICE_ACCOUNT" \
235-
--role="roles/pubsub.subscriber" --project $PROJECT_ID >/dev/null 2>&1
261+
--role="roles/pubsub.subscriber" --project $PROJECT_ID >/dev/null
236262

237263
# Allow Pubsub to publish into the deadletter topic
238264
gcloud pubsub topics add-iam-policy-binding $DEADLETTER_TOPIC \
239265
--member="serviceAccount:$PUBSUB_SERVICE_ACCOUNT" \
240-
--role="roles/pubsub.publisher" --project "$PROJECT_ID" >/dev/null 2>&1
266+
--role="roles/pubsub.publisher" --project "$PROJECT_ID" >/dev/null
241267

242268
if [[ "$SKIP_ADDING_IAM_BINDINGS" != "true" ]]; then
243269
gcloud projects add-iam-policy-binding "${PROJECT_ID}" \
244270
--member="serviceAccount:${PUBSUB_SERVICE_ACCOUNT}" \
245-
--role='roles/iam.serviceAccountTokenCreator' >/dev/null 2>&1
271+
--role='roles/iam.serviceAccountTokenCreator' >/dev/null
246272
fi
247273

248274
if [[ "$LABEL_ON_CRON" == "true" ]]; then

test_scripts/create_project.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Creates a project. Useful for testing. Creates the App Engine default service as well -- a prereq for Iris.
2+
set -u
3+
#set -x
4+
set -e
5+
6+
gcloud projects create $PROJ --folder=$FOLDER # or else --organization=$ORG
7+
gcloud billing projects link $PROJ --billing-account $BILL
8+
pushd helloworld_appengine ||exit
9+
gcloud app create --region us-west4 --project $PROJ
10+
gcloud app deploy -q --project $PROJ
11+
popd ||exit
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This file specifies files that are *not* uploaded to Google Cloud
2+
# using gcloud. It follows the same syntax as .gitignore, with the addition of
3+
# "#!include" directives (which insert the entries of the given .gitignore-style
4+
# file at that point).
5+
#
6+
# For more information, run:
7+
# $ gcloud topic gcloudignore
8+
#
9+
.gcloudignore
10+
# If you would like to upload your .git directory, .gitignore file or files
11+
# from your .gitignore file, remove the corresponding line
12+
# below:
13+
.git
14+
.gitignore
15+
16+
# Python pycache:
17+
__pycache__/
18+
# Ignored by the build system
19+
/setup.cfg
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
runtime: python39
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from flask import Flask
2+
3+
4+
app = Flask(__name__)
5+
6+
7+
@app.route('/', defaults={'path': ''})
8+
@app.route('/<path:path>')
9+
def catch_all(path):
10+
return 'You want path: %s' % path
11+
12+
@app.errorhandler(404)
13+
def handle_404(e):
14+
# handle all other routes here
15+
return f'Not Found {e}, but we HANDLED IT'
16+
17+
if __name__ == '__main__':
18+
app.run(host='0.0.0.0', port=80)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Flask
2+
3+
4+
5+

0 commit comments

Comments
 (0)