| 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 |
local debian_amis = import "mmlib/v0.1.2/amis/debian.libsonnet"; |
| 20 |
local cmd = import "mmlib/v0.1.2/cmd/cmd.libsonnet"; |
| 21 |
|
| 22 |
|
| 23 |
{ |
| 24 |
environments: { |
| 25 |
default: { |
| 26 |
kind: "Amazon", |
| 27 |
accessKey: "XXXXXXXX", // Change this. |
| 28 |
secretKey: "xxxxxxxx", // Change this. |
| 29 |
region: "us-west-1", |
| 30 |
}, |
| 31 |
}, |
| 32 |
|
| 33 |
mynetwork: service_amazon.Network { |
| 34 |
subnets: { |
| 35 |
"us-west-1c": "10.0.0.0/24", |
| 36 |
}, |
| 37 |
}, |
| 38 |
|
| 39 |
// Simple case -- one machine serving this Python script. |
| 40 |
/* |
| 41 |
helloworld: service_amazon.SingleInstance(null, 'helloworld') + web.HttpSingleInstance |
| 42 |
+ web_solutions.DebianFlaskHttpService { |
| 43 |
zone: "us-west-1c", |
| 44 |
keyName: "kp", |
| 45 |
uwsgiModuleContent: ||| |
| 46 |
import flask |
| 47 |
import socket |
| 48 |
app = flask.Flask(__name__) |
| 49 |
@app.route('/') |
| 50 |
def hello_world(): |
| 51 |
return 'Hello from %s!' % socket.gethostname() |
| 52 |
|||, |
| 53 |
networkName: "mynetwork", |
| 54 |
}, |
| 55 |
*/ |
| 56 |
|
| 57 |
// For production -- allows canarying changes, also use a dns zone |
| 58 |
helloworld2: service_amazon.Cluster3(null, 'helloworld2') + web.HttpService3 |
| 59 |
+ web_solutions.DebianFlaskHttpService { |
| 60 |
local service = self, |
| 61 |
httpPort: 8080, |
| 62 |
zones: ["us-west-1c", "us-west-1b"], |
| 63 |
versions: { |
| 64 |
v1: service.Instance { |
| 65 |
uwsgiModuleContent: ||| |
| 66 |
import flask |
| 67 |
import socket |
| 68 |
app = flask.Flask(__name__) |
| 69 |
@app.route('/') |
| 70 |
def hello_world(): |
| 71 |
return 'Hello from %s!' % socket.gethostname() |
| 72 |
|||, |
| 73 |
}, |
| 74 |
v2: service.Instance { |
| 75 |
uwsgiModuleContent: ||| |
| 76 |
import flask |
| 77 |
import socket |
| 78 |
app = flask.Flask(__name__) |
| 79 |
@app.route('/') |
| 80 |
def hello_world(): |
| 81 |
return 'Greetings from %s!' % socket.gethostname() |
| 82 |
|||, |
| 83 |
}, |
| 84 |
}, |
| 85 |
deployment: { |
| 86 |
v1: { |
| 87 |
deployed: [1, 2, 3], |
| 88 |
attached: [1, 2, 3], |
| 89 |
}, |
| 90 |
v2: { |
| 91 |
deployed: [1], |
| 92 |
attached: [1], |
| 93 |
}, |
| 94 |
}, |
| 95 |
|
| 96 |
// dnsZone: $.dns, |
| 97 |
// dnsZoneName: "dns", |
| 98 |
}, |
| 99 |
|
| 100 |
/* |
| 101 |
dns: service_amazon.DnsZone(null, 'dns') { |
| 102 |
local service = self, |
| 103 |
dnsName: "hw.example.com.", |
| 104 |
}, |
| 105 |
|
| 106 |
// If you own a domain, enable this and the zone service below, then create an NS record to |
| 107 |
// the allocated nameserver. |
| 108 |
www: service_google.DnsRecordWww(null, 'dns') { |
| 109 |
zone: $.dns, |
| 110 |
zoneName: "dns", |
| 111 |
target: "helloworld2", |
| 112 |
}, |
| 113 |
*/ |
| 114 |
|
| 115 |
} |