Skip to content

Commit 747163d

Browse files
author
Ace Nassri
authored
Add deployment manager files (GoogleCloudPlatform#91)
* Deployment manager WIP + add (required) config.json * Fix lint * Use more generic Debian filter * Remove config.json, but don't .gitignore it
1 parent 8d143d7 commit 747163d

File tree

12 files changed

+274
-16
lines changed

12 files changed

+274
-16
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ coverage/
66
test/encrypted/nodejs-docs-samples.json
77
*.iml
88
.idea/
9-
config.json
109
key.json
1110
yarn.lock

2-structured-data/books/model-cloudsql.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ function createSchema (config) {
137137

138138
connection.query(
139139
`CREATE DATABASE IF NOT EXISTS \`bookshelf\`
140-
DEFAULT CHARACTER SET = \'utf8\'
141-
DEFAULT COLLATE \'utf8_general_ci\';
140+
DEFAULT CHARACTER SET = 'utf8'
141+
DEFAULT COLLATE 'utf8_general_ci';
142142
USE \`bookshelf\`;
143143
CREATE TABLE IF NOT EXISTS \`bookshelf\`.\`books\` (
144144
\`id\` INT UNSIGNED NOT NULL AUTO_INCREMENT,

3-binary-data/books/model-cloudsql.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ function createSchema (config) {
131131

132132
connection.query(
133133
`CREATE DATABASE IF NOT EXISTS \`bookshelf\`
134-
DEFAULT CHARACTER SET = \'utf8\'
135-
DEFAULT COLLATE \'utf8_general_ci\';
134+
DEFAULT CHARACTER SET = 'utf8'
135+
DEFAULT COLLATE 'utf8_general_ci';
136136
USE \`bookshelf\`;
137137
CREATE TABLE IF NOT EXISTS \`bookshelf\`.\`books\` (
138138
\`id\` INT UNSIGNED NOT NULL AUTO_INCREMENT,

4-auth/books/model-cloudsql.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ function createSchema (config) {
151151

152152
connection.query(
153153
`CREATE DATABASE IF NOT EXISTS \`bookshelf\`
154-
DEFAULT CHARACTER SET = \'utf8\'
155-
DEFAULT COLLATE \'utf8_general_ci\';
154+
DEFAULT CHARACTER SET = 'utf8'
155+
DEFAULT COLLATE 'utf8_general_ci';
156156
USE \`bookshelf\`;
157157
CREATE TABLE IF NOT EXISTS \`bookshelf\`.\`books\` (
158158
\`id\` INT UNSIGNED NOT NULL AUTO_INCREMENT,

5-logging/books/model-cloudsql.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ function createSchema (config) {
149149

150150
connection.query(
151151
`CREATE DATABASE IF NOT EXISTS \`bookshelf\`
152-
DEFAULT CHARACTER SET = \'utf8\'
153-
DEFAULT COLLATE \'utf8_general_ci\';
152+
DEFAULT CHARACTER SET = 'utf8'
153+
DEFAULT COLLATE 'utf8_general_ci';
154154
USE \`bookshelf\`;
155155
CREATE TABLE IF NOT EXISTS \`bookshelf\`.\`books\` (
156156
\`id\` INT UNSIGNED NOT NULL AUTO_INCREMENT,

6-pubsub/books/model-cloudsql.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ function createSchema (config) {
160160

161161
connection.query(
162162
`CREATE DATABASE IF NOT EXISTS \`bookshelf\`
163-
DEFAULT CHARACTER SET = \'utf8\'
164-
DEFAULT COLLATE \'utf8_general_ci\';
163+
DEFAULT CHARACTER SET = 'utf8'
164+
DEFAULT COLLATE 'utf8_general_ci';
165165
USE \`bookshelf\`;
166166
CREATE TABLE IF NOT EXISTS \`bookshelf\`.\`books\` (
167167
\`id\` INT UNSIGNED NOT NULL AUTO_INCREMENT,

7-gce/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
node_modules
22
*.log
3-
config.json

7-gce/books/model-cloudsql.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ function createSchema (config) {
156156

157157
connection.query(
158158
`CREATE DATABASE IF NOT EXISTS \`bookshelf\`
159-
DEFAULT CHARACTER SET = \'utf8\'
160-
DEFAULT COLLATE \'utf8_general_ci\';
159+
DEFAULT CHARACTER SET = 'utf8'
160+
DEFAULT COLLATE 'utf8_general_ci';
161161
USE \`bookshelf\`;
162162
CREATE TABLE IF NOT EXISTS \`bookshelf\`.\`books\` (
163163
\`id\` INT UNSIGNED NOT NULL AUTO_INCREMENT,
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
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+
{# [START all] #}
15+
16+
{# [START env] #}
17+
{% set NAME = "bookshelf-" + env["deployment"] %}
18+
{% set SERVICE = "bookshelf-" + env["deployment"] + "-frontend" %}
19+
{# [END env] #}
20+
21+
#
22+
# Instance group setup
23+
#
24+
25+
# First we have to create an instance template.
26+
# This template will be used by the instance group
27+
# to create new instances.
28+
resources:
29+
- name : {{ NAME }}
30+
type: compute.v1.instanceTemplate
31+
properties:
32+
properties:
33+
tags:
34+
items:
35+
- http-server
36+
disks:
37+
- boot: True
38+
type: PERSISTENT
39+
initializeParams:
40+
sourceImage: {{ properties['machine-image'] }}
41+
diskSizeGb: 10
42+
diskType: pd-ssd
43+
machineType: {{ properties['machine-type'] }}
44+
serviceAccounts:
45+
- email: default
46+
scopes: {{ properties['scopes'] }}
47+
metadata:
48+
items:
49+
- key: startup-script
50+
{# [START startup] #}
51+
value: |
52+
{{imports['startup-script']|indent(14, true)}}
53+
{# [END startup] #}
54+
networkInterfaces:
55+
- network: global/networks/default
56+
accessConfigs:
57+
- type: ONE_TO_ONE_NAT
58+
name: External NAT
59+
60+
# Creates the managed instance group. This is responsible for creating
61+
# new instances using the instance template, as well as providing a named
62+
# port the backend service can target
63+
- name: {{ NAME }}-frontend-group
64+
type: compute.v1.instanceGroupManager
65+
properties:
66+
instanceTemplate: $(ref.{{ NAME }}.selfLink)
67+
baseInstanceName: frontend-group
68+
targetSize: 3
69+
zone: {{ properties['zone'] }}
70+
namedPorts:
71+
- name: http
72+
port: 8080
73+
74+
75+
76+
# Load Balancer Setup
77+
#
78+
79+
# A complete HTTP load balancer is structured as follows:
80+
#
81+
# 1) A global forwarding rule directs incoming requests to a target HTTP proxy.
82+
# 2) The target HTTP proxy checks each request against a URL map to determine the
83+
# appropriate backend service for the request.
84+
# 3) The backend service directs each request to an appropriate backend based on
85+
# serving capacity, zone, and instance health of its attached backends. The
86+
# health of each backend instance is verified using either a health check.
87+
#
88+
# We'll create these resources in reverse order:
89+
# service, health check, backend service, url map, proxy.
90+
91+
# Create a health check
92+
# The load balancer will use this check to keep track of which instances to send traffic to.
93+
# Note that health checks will not cause the load balancer to shutdown any instances.
94+
- name: {{ NAME }}-health-check
95+
type: compute.v1.httpHealthCheck
96+
properties:
97+
requestPath: /_ah/health
98+
port: 8080
99+
100+
# Create a backend service, associate it with the health check and instance group.
101+
# The backend service serves as a target for load balancing.
102+
- name: {{ SERVICE }}
103+
type: compute.v1.backendService
104+
properties:
105+
healthChecks:
106+
- $(ref.{{ NAME }}-health-check.selfLink)
107+
portName: http
108+
backends:
109+
{# [START reference] #}
110+
- group: $(ref.{{ NAME }}-frontend-group.instanceGroup)
111+
zone: {{ properties['zone'] }}
112+
{# [END reference] #}
113+
114+
# Create a URL map and web Proxy. The URL map will send all requests to the
115+
# backend service defined above.
116+
- name: {{ SERVICE }}-map
117+
type: compute.v1.urlMap
118+
properties:
119+
defaultService: $(ref.{{ SERVICE }}.selfLink)
120+
121+
# This is the actual proxy which uses the URL map to route traffic
122+
# to the backend service
123+
- name: {{ SERVICE }}-proxy
124+
type: compute.v1.targetHttpProxy
125+
properties:
126+
urlMap: $(ref.{{ SERVICE }}-map.selfLink)
127+
128+
# This is the global forwarding rule which creates an external IP to
129+
# target the http poxy
130+
- name: {{ SERVICE }}-http-rule
131+
type: compute.v1.globalForwardingRule
132+
properties:
133+
target: $(ref.{{ SERVICE }}-proxy.selfLink)
134+
portRange: 80
135+
136+
# Creates an autoscaler resource (note that when using the gcloud CLI,
137+
# autoscaling is set as a configuration of the managed instance group
138+
# but autoscaler is a resource so in deployment manager we explicitly
139+
# define it
140+
- name: {{ NAME }}-autoscaler
141+
type: compute.v1.autoscaler
142+
properties:
143+
zone: {{ properties['zone'] }}
144+
target: $(ref.{{ NAME }}-frontend-group.selfLink)
145+
autoscalingPolicy:
146+
{# [START properties] #}
147+
minNumReplicas: {{ properties['min-instances'] }}
148+
maxNumReplicas: {{ properties['max-instances'] }}
149+
loadBalancingUtilization:
150+
utilizationTarget: {{ properties['target-utilization'] }}
151+
{# [END properties] #}
152+
153+
# Firewall rule that allows traffic to GCE instances with the
154+
# http server tag we created
155+
- name: {{ NAME }}-allow-http
156+
type: compute.v1.firewall
157+
properties:
158+
allowed:
159+
- IPProtocol: tcp
160+
ports:
161+
- 8080
162+
sourceRanges:
163+
- 0.0.0.0/0
164+
targetTags:
165+
- http-server
166+
description: "Allow port 8080 access to http-server"
167+
168+
{# [END all] #}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
# [START all]
16+
17+
info:
18+
title: Bookshelf GCE Deploy
19+
author: Google Inc.
20+
description: Creates a GCE Deployment
21+
22+
imports:
23+
- name: startup-script
24+
path: ../startup-script.sh
25+
26+
required:
27+
- zone
28+
- machine-type
29+
- min-instances
30+
- max-instances
31+
- scopes
32+
33+
properties:
34+
zone:
35+
description: Zone to create the resources in.
36+
type: string
37+
machine-type:
38+
description: Type of machine to use
39+
type: string
40+
machine-image:
41+
description: The OS image to use on the machines
42+
type: string
43+
min-instances:
44+
description: The minimum number of VMs the autoscaler will create
45+
type: integer
46+
max-instances:
47+
description: The maximum number of VMs the autoscaler will create
48+
type: integer
49+
target-utilization:
50+
description: The target CPU usage for the autoscaler to base its scaling on
51+
type: number
52+
scopes:
53+
description: A list of scopes to create the VM with
54+
type: array
55+
minItems: 1
56+
items:
57+
type: string
58+
59+
# [END all]

0 commit comments

Comments
 (0)