Debian Codegraph @

case_studies/micromanage/examples/hello_world_google.jsonnet

raw
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 local service_amazon = import "mmlib/v0.1.2/service/amazon.libsonnet";
16 local service_google = import "mmlib/v0.1.2/service/google.libsonnet";
17 local web = import "mmlib/v0.1.2/web/web.libsonnet";
18 local web_solutions = import "mmlib/v0.1.2/web/solutions.libsonnet";
19
20 {
21 environments: {
22 default: {
23 kind: "Google",
24 project: "readable-name-123", // Change this.
25 region: "us-central1", // Maybe change this.
26 // Download this file from the developers console.
27 serviceAccount: import "service_account.json",
28 sshUser: "yourusername", // Change this.
29 },
30 },
31
32 // The following examples support HTTPs, thus require DNS names and
33 // SSL certificates. Removing the httpsPort will disable that.
34
35 // Simple case -- one machine serving this Python script.
36 helloworld: service_google.SingleInstance(null, 'helloworld') + web.HttpSingleInstance
37 + web_solutions.DebianFlaskHttpService {
38 httpsPort: 443,
39 sslCertificate: importstr 'cert.pem', // You will need to provision this.
40 sslCertificateKey: importstr 'key.pem', // You will need to provision this.
41 zone: "us-central1-f",
42 uwsgiModuleContent: |||
43 import flask
44 import socket
45 app = flask.Flask(__name__)
46 @app.route('/')
47 def hello_world():
48 return 'Hello from %s!' % socket.gethostname()
49 |||,
50 dnsZone: $.dns,
51 },
52
53 // For production -- allows canarying changes, also use a dns zone
54 helloworld2: service_google.Cluster3(null, 'helloworld2') + web.HttpService3
55 + web_solutions.DebianFlaskHttpService {
56 local service = self,
57 httpPort: null,
58 httpsPort: 443,
59 sslCertificate: importstr 'cert.pem', // You will need to provision this.
60 sslCertificateKey: importstr 'key.pem', // You will need to provision this.
61 zones: ["us-central1-b", "us-central1-c", "us-central1-f"],
62 versions: {
63 v1: service.Instance {
64 uwsgiModuleContent: |||
65 import flask
66 import socket
67 app = flask.Flask(__name__)
68 @app.route('/')
69 def hello_world():
70 return 'Hello from %s!' % socket.gethostname()
71 |||,
72 },
73 v2: service.Instance {
74 uwsgiModuleContent: |||
75 import flask
76 import socket
77 app = flask.Flask(__name__)
78 @app.route('/')
79 def hello_world():
80 return 'Greetings from %s!' % socket.gethostname()
81 |||,
82 },
83 },
84 deployment: {
85 v1: {
86 deployed: [1, 2, 3],
87 attached: [1, 2, 3],
88 },
89 v2: {
90 deployed: [1],
91 attached: [1],
92 },
93 },
94
95 dnsZone: $.dns,
96 },
97
98 dns: service_google.DnsZone(null, 'dns') {
99 local service = self,
100 dnsName: "hw.example.com.",
101 },
102
103 // If you own a domain, enable this and the zone service below, then create an NS record to
104 // the allocated nameserver.
105 www: service_google.DnsRecordWww(null, 'www') {
106 zone: $.dns,
107 target: "helloworld2",
108 },
109
110 }