Skip to content

Commit 08a5dc2

Browse files
committed
Merge pull request GoogleCloudPlatform#63 from GoogleCloudPlatform/deploy
Add Deploy
2 parents 8f60858 + 97593b0 commit 08a5dc2

File tree

3 files changed

+242
-0
lines changed

3 files changed

+242
-0
lines changed
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
{#
2+
Copyright 2016 Google Inc. All rights reserved.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
#}
13+
14+
{% set NAME = "bookshelf-" + env["deployment"] %}
15+
{% set SERVICE = "bookshelf-" + env["deployment"] + "-frontend" %}
16+
17+
#
18+
# Instance group setup
19+
#
20+
21+
# First we have to create an instance template.
22+
# This template will be used by the instance group
23+
# to create new instances.
24+
resources:
25+
- name : {{ NAME }}
26+
type: compute.v1.instanceTemplate
27+
properties:
28+
properties:
29+
tags:
30+
items:
31+
- http-server
32+
disks:
33+
- boot: True
34+
type: PERSISTENT
35+
initializeParams:
36+
sourceImage: {{ properties['machine-image'] }}
37+
diskSizeGb: 10
38+
diskType: pd-ssd
39+
machineType: {{ properties['machine-type'] }}
40+
serviceAccounts:
41+
- email: default
42+
scopes: {{ properties['scopes'] }}
43+
metadata:
44+
items:
45+
- key: startup-script
46+
value: |
47+
{{imports['startup-script']|indent(14, true)}}
48+
networkInterfaces:
49+
- network: global/networks/default
50+
accessConfigs:
51+
- type: ONE_TO_ONE_NAT
52+
name: External NAT
53+
54+
# Creates the managed instance group. This is responsible for creating
55+
# new instances using the instance template, as well as providing a named
56+
# port the backend service can target
57+
- name: {{ NAME }}-frontend-group
58+
type: compute.v1.instanceGroupManager
59+
properties:
60+
instanceTemplate: $(ref.{{ NAME }}.selfLink)
61+
baseInstanceName: frontend-group
62+
targetSize: 3
63+
zone: {{ properties['zone'] }}
64+
namedPorts:
65+
- name: http
66+
port: 8080
67+
68+
69+
70+
# Load Balancer Setup
71+
#
72+
73+
# A complete HTTP load balancer is structured as follows:
74+
#
75+
# 1) A global forwarding rule directs incoming requests to a target HTTP proxy.
76+
# 2) The target HTTP proxy checks each request against a URL map to determine the
77+
# appropriate backend service for the request.
78+
# 3) The backend service directs each request to an appropriate backend based on
79+
# serving capacity, zone, and instance health of its attached backends. The
80+
# health of each backend instance is verified using either a health check.
81+
#
82+
# We'll create these resources in reverse order:
83+
# service, health check, backend service, url map, proxy.
84+
85+
# Create a health check
86+
# The load balancer will use this check to keep track of which instances to send traffic to.
87+
# Note that health checks will not cause the load balancer to shutdown any instances.
88+
- name: {{ NAME }}-health-check
89+
type: compute.v1.httpHealthCheck
90+
properties:
91+
requestPath: /_ah/health
92+
port: 8080
93+
94+
# Create a backend service, associate it with the health check and instance group.
95+
# The backend service serves as a target for load balancing.
96+
- name: {{ SERVICE }}
97+
type: compute.v1.backendService
98+
properties:
99+
healthChecks:
100+
- $(ref.{{ NAME }}-health-check.selfLink)
101+
portName: http
102+
backends:
103+
- group: $(ref.{{ NAME }}-frontend-group.instanceGroup)
104+
zone: {{ properties['zone'] }}
105+
106+
# Create a URL map and web Proxy. The URL map will send all requests to the
107+
# backend service defined above.
108+
- name: {{ SERVICE }}-map
109+
type: compute.v1.urlMap
110+
properties:
111+
defaultService: $(ref.{{ SERVICE }}.selfLink)
112+
113+
# This is the actual proxy which uses the URL map to route traffic
114+
# to the backend service
115+
- name: {{ SERVICE }}-proxy
116+
type: compute.v1.targetHttpProxy
117+
properties:
118+
urlMap: $(ref.{{ SERVICE }}-map.selfLink)
119+
120+
# This is the global forwarding rule which creates an external IP to
121+
# target the http poxy
122+
- name: {{ SERVICE }}-http-rule
123+
type: compute.v1.globalForwardingRule
124+
properties:
125+
target: $(ref.{{ SERVICE }}-proxy.selfLink)
126+
portRange: 80
127+
128+
# Creates an autoscaler resource (note that when using the gcloud CLI,
129+
# autoscaling is set as a configuration of the managed instance group
130+
# but autoscaler is a resource so in deployment manager we explicitly
131+
# define it
132+
- name: {{ NAME }}-autoscaler
133+
type: compute.v1.autoscaler
134+
properties:
135+
zone: {{ properties['zone'] }}
136+
target: $(ref.{{ NAME }}-frontend-group.selfLink)
137+
autoscalingPolicy:
138+
minNumReplicas: {{ properties['min-instances'] }}
139+
maxNumReplicas: {{ properties['max-instances'] }}
140+
loadBalancingUtilization:
141+
utilizationTarget: {{ properties['target-utilization'] }}
142+
143+
# Firewall rule that allows traffic to GCE instances with the
144+
# http server tag we created
145+
- name: {{ NAME }}-allow-http
146+
type: compute.v1.firewall
147+
properties:
148+
allowed:
149+
- IPProtocol: tcp
150+
ports:
151+
- 8080
152+
sourceRanges:
153+
- 0.0.0.0/0
154+
targetTags:
155+
- http-server
156+
description: "Allow port 8080 access to http-server"
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright 2016 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
info:
16+
title: Bookshelf GCE Deploy
17+
author: Google Inc.
18+
description: Creates a GCE Deployment
19+
20+
imports:
21+
- name: startup-script
22+
path: ../startup-script.sh
23+
24+
required:
25+
- zone
26+
- machine-type
27+
- min-instances
28+
- max-instances
29+
- scopes
30+
31+
properties:
32+
zone:
33+
description: Zone to create the resources in.
34+
type: string
35+
machine-type:
36+
description: Type of machine to use
37+
type: string
38+
machine-image:
39+
description: The OS image to use on the machines
40+
type: string
41+
min-instances:
42+
description: The minimum number of VMs the autoscaler will create
43+
type: integer
44+
max-instances:
45+
description: The maximum number of VMs the autoscaler will create
46+
type: integer
47+
target-utilization:
48+
description: The target CPU usage for the autoscaler to base its scaling on
49+
type: number
50+
scopes:
51+
description: A list of scopes to create the VM with
52+
type: array
53+
minItems: 1
54+
items:
55+
type: string
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2015 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
imports:
16+
- name: bookshelf.jinja
17+
path: ./bookshelf.jinja
18+
19+
resources:
20+
- name: bookshelf
21+
type: bookshelf.jinja
22+
properties:
23+
zone: us-central1-f
24+
machine-type: n1-standard-1
25+
machine-image: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-8-jessie-v20151104
26+
min-instances: 1
27+
max-instances: 10
28+
target-utilization: 0.6
29+
scopes:
30+
- https://www.googleapis.com/auth/cloud-platform
31+

0 commit comments

Comments
 (0)