Skip to content

Fixing Running the Python Bookshelf on Compute Engine Sample Code #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions 7-gce/gce/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ ZONE=us-central1-f
GROUP=frontend-group
TEMPLATE=$GROUP-tmpl
MACHINE_TYPE=f1-micro
IMAGE=debian-8
IMAGE_FAMILY=debian-8
IMAGE_PROJECT=debian-cloud
Copy link
Contributor Author

@michaelawyu michaelawyu Sep 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Param -image is deprecated. Updated to use -image-family and -image-project.

STARTUP_SCRIPT=startup-script.sh
SCOPES="userinfo-email,cloud-platform"
TAGS=http-server
Expand All @@ -41,7 +42,8 @@ SERVICE=frontend-web-service

# [START create_template]
gcloud compute instance-templates create $TEMPLATE \
--image $IMAGE \
--image-family $IMAGE_FAMILY \
--image-project $IMAGE_PROJECT \
Copy link
Contributor Author

@michaelawyu michaelawyu Sep 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Param -image is deprecated. Updated to use -image-family and -image-project.

--machine-type $MACHINE_TYPE \
--scopes $SCOPES \
--metadata-from-file startup-script=$STARTUP_SCRIPT \
Expand Down Expand Up @@ -97,13 +99,15 @@ gcloud compute http-health-checks create ah-health-check \

# [START create_backend_service]
gcloud compute backend-services create $SERVICE \
--http-health-checks ah-health-check
--http-health-checks ah-health-check \
--global
# [END create_backend_service]

# [START add_backend_service]
gcloud compute backend-services add-backend $SERVICE \
--instance-group $GROUP \
--instance-zone $ZONE
--instance-group-zone $ZONE \
--global
# [END add_backend_service]

# Create a URL map and web Proxy. The URL map will send all requests to the
Expand All @@ -125,7 +129,7 @@ gcloud compute target-http-proxies create $SERVICE-proxy \
gcloud compute forwarding-rules create $SERVICE-http-rule \
--global \
--target-http-proxy $SERVICE-proxy \
--port-range 80
--ports=80
Copy link
Contributor Author

@michaelawyu michaelawyu Sep 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Param --port-range is deprecated. Updated to use --ports.

# [END create_forwarding_rule]

#
Expand All @@ -140,9 +144,16 @@ gcloud compute instance-groups managed set-autoscaling \
# [END set_autoscaling]

# [START create_firewall]
gcloud compute firewall-rules create default-allow-http-8080 \
# Check if the firewall rule has been created in previous steps of the documentation
if gcloud compute firewall-rules list --filter="name~'default-allow-http-8080'" \
--format="table(name)" | grep -q 'NAME'; then
echo "Firewall rule default-allow-http-8080 already exists."
else
gcloud compute firewall-rules create default-allow-http-8080 \
--allow tcp:8080 \
--source-ranges 0.0.0.0/0 \
--target-tags http-server \
--description "Allow port 8080 access to http-server"
--description "Allow port 8080 access to http-server"
fi

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old script may fail if user has created a default-allow-http-8080 firewall rule in previous steps of the tutorial. Added a new command to create the firewall rule only when the rule has not already existed.

# [END create_firewall]
2 changes: 1 addition & 1 deletion 7-gce/gce/startup-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pip install --upgrade pip virtualenv
# git requires $HOME and it's not set during the startup script.
export HOME=/root
git config --global credential.helper gcloud.sh
git clone https://source.developers.google.com/p/$PROJECTID /opt/app
git clone https://source.developers.google.com/p/$PROJECTID/r/[YOUR_REPO_NAME] /opt/app
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use the current format of Cloud Repo addresses.


# Install app dependencies
virtualenv /opt/app/7-gce/env
Expand Down
16 changes: 8 additions & 8 deletions 7-gce/gce/teardown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ SERVICE=frontend-web-service

gcloud compute instance-groups managed stop-autoscaling $GROUP --zone $ZONE

gcloud compute forwarding-rules delete $SERVICE-http-rule --global
gcloud compute forwarding-rules delete $SERVICE-http-rule --global --quiet

gcloud compute target-http-proxies delete $SERVICE-proxy
gcloud compute target-http-proxies delete $SERVICE-proxy --quiet

gcloud compute url-maps delete $SERVICE-map
gcloud compute url-maps delete $SERVICE-map --quiet

gcloud compute backend-services delete $SERVICE
gcloud compute backend-services delete $SERVICE --global --quiet

gcloud compute http-health-checks delete ah-health-check
gcloud compute http-health-checks delete ah-health-check --quiet

gcloud compute instance-groups managed delete $GROUP
gcloud compute instance-groups managed delete $GROUP --quiet

gcloud compute instance-templates delete $TEMPLATE
gcloud compute instance-templates delete $TEMPLATE --quiet

gcloud compute firewall-rules delete default-allow-http-8080
gcloud compute firewall-rules delete default-allow-http-8080 --quiet
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Param --quiet is specified so that user will not be interrupted to confirm on each of the operations when running the script.