Skip to content

Commit

Permalink
Merge pull request #173 from sparkprime/libsonnet
Browse files Browse the repository at this point in the history
Provide examples for new .libsonnet convention
  • Loading branch information
sparkprime committed May 10, 2016
2 parents b8b867e + 08f9af6 commit 8d00178
Show file tree
Hide file tree
Showing 64 changed files with 2,474 additions and 72 deletions.
2 changes: 1 addition & 1 deletion case_studies/fractal/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ service.list
*.tf
service_account_key.json
tilegen/mandelbrot
credentials.jsonnet
credentials.libsonnet
2 changes: 1 addition & 1 deletion case_studies/fractal/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
ALL_IMAGES = $(shell cat service.list | grep '[.]packer.json$$')

default:
../../jsonnet -J ../lib -E USER --multi service.jsonnet > service.list
../../jsonnet -J lib -A ssh_username=$$USER --multi . service.jsonnet > service.list
$(MAKE) all_artifacts
$(MAKE) terraform.done

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

local packer = import "packer.jsonnet";
local packer = import "packer.libsonnet";

{
local cassandra = self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ limitations under the License.
source_image:: error "GcpImage must have field: name",
project_id:: error "GcpImage must have field: project_id",
account_file:: error "GcpImage must have field: account_file",
sshUsername:: error "GcpImage must have field: sshUsername",

local img = self,
builder:: {
Expand All @@ -160,7 +161,7 @@ limitations under the License.
source_image: img.source_image,
instance_name: "packer-" + self.name,
zone: "us-central1-a",
ssh_username: std.extVar("USER"),
ssh_username: img.sshUsername,
[if std.objectHas(img, "disk_size") then "disk_size"]: img.disk_size,
},

Expand Down
File renamed without changes.
13 changes: 8 additions & 5 deletions case_studies/fractal/service.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ limitations under the License.
*/

// Import some libraries
local packer = import "packer.jsonnet";
local terraform = import "terraform.jsonnet";
local cassandra = import "cassandra.jsonnet";
local packer = import "packer.libsonnet";
local terraform = import "terraform.libsonnet";
local cassandra = import "cassandra.libsonnet";

// Credentials file (don't commit this!)
local credentials = import "credentials.jsonnet";
local credentials = import "credentials.libsonnet";


function(ssh_username) {

{
///////////////////////////
// GENERAL CONFIGURATION //
///////////////////////////
Expand Down Expand Up @@ -101,6 +103,7 @@ local credentials = import "credentials.jsonnet";
// For debugging:
local network_debug = ["traceroute", "lsof", "iptraf", "tcpdump", "host", "dnsutils"],
aptPackages+: ["vim", "git", "psmisc", "screen", "strace"] + network_debug,
sshUsername: ssh_username,
},

// Frontend image.
Expand Down
2 changes: 1 addition & 1 deletion case_studies/kubernetes/example.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

local Kube = import "libkube.jsonnet";
local Kube = import "kube.libsonnet";

{

Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions case_studies/micro_fractal/fractal.jsonnet
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
local cmd = import "mmlib/v0.1.1/cmd/cmd.jsonnet";
local service_google = import "mmlib/v0.1.1/service/google.jsonnet";
local cassandra = import "mmlib/v0.1.1/db/cassandra.jsonnet";
local web = import "mmlib/v0.1.1/web/web.jsonnet";
local web_solutions = import "mmlib/v0.1.1/web/solutions.jsonnet";
local cmd = import "mmlib/v0.1.2/cmd/cmd.libsonnet";
local service_google = import "mmlib/v0.1.2/service/google.libsonnet";
local cassandra = import "mmlib/v0.1.2/db/cassandra.libsonnet";
local web = import "mmlib/v0.1.2/web/web.libsonnet";
local web_solutions = import "mmlib/v0.1.2/web/solutions.libsonnet";

{
local app = self,
Expand Down
17 changes: 16 additions & 1 deletion case_studies/micro_fractal/fractal_dev.jsonnet.TEMPLATE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local service_google = import "mmlib/v0.1.0/service/google.jsonnet";
local service_google = import "mmlib/v0.1.2/service/google.libsonnet";

local fractal = import "fractal.jsonnet";

Expand All @@ -15,5 +15,20 @@ local fractal = import "fractal.jsonnet";
cassandraUserPass: "xxxxxxxx", // CHANGE ME!
cassandraRootPass: "XXXXXXXX", // CHANGE ME!
dnsSuffix: "dev.yourdomain.com.", // CHANGE ME!
// By default only 1 node is deployed of each subservice.
// However you can configure this.
appserv+: {
zones: ["XXX", "YYY", "ZZZ"], // CHANGE ME!
},
tilegen+: {
zones: ["XXX", "YYY", "ZZZ"], // CHANGE ME!
},
db+: {
nodes+: {
n1+: {
zone: "XXX", // CHANGE ME!
},
},
},
},
}
2 changes: 1 addition & 1 deletion case_studies/micromanage/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
tests/testenv.jsonnet
tests/testenv.libsonnet
examples/test_google.jsonnet
examples/test_amazon.jsonnet
12 changes: 6 additions & 6 deletions case_studies/micromanage/examples/hello_world_amazon.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

local service_amazon = import "mmlib/v0.1.1/service/amazon.jsonnet";
local service_google = import "mmlib/v0.1.1/service/google.jsonnet";
local web = import "mmlib/v0.1.1/web/web.jsonnet";
local web_solutions = import "mmlib/v0.1.1/web/solutions.jsonnet";
local debian_amis = import "mmlib/v0.1.1/amis/debian.jsonnet";
local cmd = import "mmlib/v0.1.1/cmd/cmd.jsonnet";
local service_amazon = import "mmlib/v0.1.1/service/amazon.libsonnet";
local service_google = import "mmlib/v0.1.1/service/google.libsonnet";
local web = import "mmlib/v0.1.1/web/web.libsonnet";
local web_solutions = import "mmlib/v0.1.1/web/solutions.libsonnet";
local debian_amis = import "mmlib/v0.1.1/amis/debian.libsonnet";
local cmd = import "mmlib/v0.1.1/cmd/cmd.libsonnet";


{
Expand Down
8 changes: 4 additions & 4 deletions case_studies/micromanage/examples/hello_world_google.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

local service_amazon = import "mmlib/v0.1.1/service/amazon.jsonnet";
local service_google = import "mmlib/v0.1.1/service/google.jsonnet";
local web = import "mmlib/v0.1.1/web/web.jsonnet";
local web_solutions = import "mmlib/v0.1.1/web/solutions.jsonnet";
local service_amazon = import "mmlib/v0.1.1/service/amazon.libsonnet";
local service_google = import "mmlib/v0.1.1/service/google.libsonnet";
local web = import "mmlib/v0.1.1/web/web.libsonnet";
local web_solutions = import "mmlib/v0.1.1/web/solutions.libsonnet";

{
environments: {
Expand Down
24 changes: 24 additions & 0 deletions case_studies/micromanage/lib/mmlib/v0.1.2/amis/debian.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Connect to machines using the username "admin" and -i yourkey.pem

// Source: https://wiki.debian.org/Cloud/AmazonEC2Image/Wheezy

// HVM, EBS
{
wheezy: {
amd64: {
"20150128": {
"ap-northeast-1": "ami-b25d44b3",
"ap-southeast-1": "ami-aeb49ffc",
"ap-southeast-2": "ami-6b770351",
"eu-central-1": "ami-98043785",
"eu-west-1": "ami-61e56916",
"sa-east-1": "ami-3d8b3720",
"us-east-1": "ami-e0efab88",
"us-west-1": "ami-b4869ff1",
"us-west-2": "ami-431a4273",
"us-gov-west-1": "ami-d13455f2",
"cn-north-1": "ami-48029071",
},
},
},
}
33 changes: 33 additions & 0 deletions case_studies/micromanage/lib/mmlib/v0.1.2/amis/ubuntu.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Connect to machines using the username "ubuntu" and -i yourkey.pem

// Source: http://cloud-images.ubuntu.com/locator/ec2/
// There is a URL to get a JSON dump but I've lost it.

local regions(amis) = std.set([a[0] for a in amis]);
local region_amis(amis, v) = [a for a in amis if a[0] == v];

local oses(amis) = std.set([a[1] for a in amis]);
local os_amis(amis, v) = [a for a in amis if a[1] == v];

local archs(amis) = std.set([a[3] for a in amis]);
local arch_amis(amis, v) = [a for a in amis if a[3] == v];

local dates(amis) = std.set([a[5] for a in amis]);
local date_amis(amis, v) = [a for a in amis if a[5] == v];

local strip_from_url(url) =
local suffix = std.split(url, ">")[1];
std.substr(suffix, 0, std.length(suffix) - 3);

local all_amis = (import "ubuntu_raw.json").aaData;

{
[os]: local this_os_amis = os_amis(all_amis, os); {
[arch]: local this_arch_amis = arch_amis(this_os_amis, arch); {
[date]: local this_date_amis = date_amis(this_arch_amis, date); {
[r]: strip_from_url(region_amis(this_date_amis, r)[0][6])
for r in regions(this_date_amis)
} for date in dates(this_arch_amis)
} for arch in archs(this_os_amis)
} for os in oses(all_amis)
}
Binary file not shown.
Loading

0 comments on commit 8d00178

Please sign in to comment.