From 729af81e44704450055f94ece4e97bab11f24406 Mon Sep 17 00:00:00 2001 From: joeduffy Date: Fri, 20 Jan 2017 09:46:59 -0800 Subject: [PATCH] Move all cloud switching to mu/x MuPackage In the old system, the core runtime/toolset understood that we are targeting specific cloud providers at a very deep level. In fact, the whole code-generation phase of the compiler was based on it. In the new system, this difference is less of a "special" concern, and more of a general one of mapping MuIL objects to resource providers, and letting *them* gather up any configuration they need in a more general purpose way. Therefore, most of this stuff can go. I've merged in a small amount of it to the mu/x MuPackage, since that has to switch on cloud IaaS and CaaS providers in order to decide what kind of resources to provision. For example, it has a mu.x.Cluster stack type that itself provisions a lot of the barebone essential resources, like a virtual private cloud and its associated networking components. I suspect *some* knowledge of this will surface again as we implement more runtime presence (discovery, etc). But for the time being, it's a distraction getting the core model running. I've retained some of the old AWS code in the new pkg/resource/providers/aws package, in case I want to reuse some of it when implementing our first AWS resource providers. (Although we won't be using CloudFormation, some of the name generation code might be useful.) So, the ships aren't completely burned to the ground, but they are certainly on :fire:. --- .gitignore | 1 + cmd/build.go | 109 ----------------- lib/mu/cluster.mu | 17 --- lib/mu/cluster.ts | 47 -------- {sdk/javascript => lib/mu/x}/arch.ts | 0 .../cluster.ts => lib/mu/x/bucket/index.ts | 4 +- {sdk/javascript => lib/mu/x}/clouds/index.ts | 0 lib/mu/x/cluster.ts | 82 +++++++++++++ lib/mu/x/index.ts | 11 ++ .../mu/x}/schedulers/index.ts | 0 pkg/cmdutil/clouds.go | 50 -------- pkg/compiler/backends/arch.go | 22 ---- pkg/compiler/backends/clouds/cloud.go | 13 -- pkg/compiler/backends/clouds/clouds.go | 40 ------- pkg/compiler/backends/provider.go | 49 -------- .../backends/schedulers/awsecs/scheduler.go | 42 ------- pkg/compiler/backends/schedulers/scheduler.go | 13 -- .../backends/schedulers/schedulers.go | 48 -------- pkg/compiler/compiler_fe.go | 113 ------------------ pkg/compiler/opts.go | 7 +- .../clouds => resource/providers}/aws/cf.go | 0 .../providers}/aws/cloud.go | 0 .../providers}/aws/errors.go | 0 .../providers}/aws/intrins.go | 0 .../providers}/aws/names.go | 0 .../providers}/aws/names_test.go | 0 sdk/javascript/context.ts | 4 - sdk/javascript/index.ts | 6 - sdk/javascript/tsconfig.json | 7 +- 29 files changed, 98 insertions(+), 587 deletions(-) delete mode 100644 cmd/build.go delete mode 100644 lib/mu/cluster.mu delete mode 100644 lib/mu/cluster.ts rename {sdk/javascript => lib/mu/x}/arch.ts (100%) rename sdk/javascript/cluster.ts => lib/mu/x/bucket/index.ts (54%) rename {sdk/javascript => lib/mu/x}/clouds/index.ts (100%) create mode 100644 lib/mu/x/cluster.ts create mode 100644 lib/mu/x/index.ts rename {sdk/javascript => lib/mu/x}/schedulers/index.ts (100%) delete mode 100644 pkg/cmdutil/clouds.go delete mode 100644 pkg/compiler/backends/arch.go delete mode 100644 pkg/compiler/backends/clouds/cloud.go delete mode 100644 pkg/compiler/backends/clouds/clouds.go delete mode 100644 pkg/compiler/backends/provider.go delete mode 100644 pkg/compiler/backends/schedulers/awsecs/scheduler.go delete mode 100644 pkg/compiler/backends/schedulers/scheduler.go delete mode 100644 pkg/compiler/backends/schedulers/schedulers.go delete mode 100644 pkg/compiler/compiler_fe.go rename pkg/{compiler/backends/clouds => resource/providers}/aws/cf.go (100%) rename pkg/{compiler/backends/clouds => resource/providers}/aws/cloud.go (100%) rename pkg/{compiler/backends/clouds => resource/providers}/aws/errors.go (100%) rename pkg/{compiler/backends/clouds => resource/providers}/aws/intrins.go (100%) rename pkg/{compiler/backends/clouds => resource/providers}/aws/names.go (100%) rename pkg/{compiler/backends/clouds => resource/providers}/aws/names_test.go (100%) diff --git a/.gitignore b/.gitignore index d6453dc97..0bdadde84 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.swp +mu vendor/ diff --git a/cmd/build.go b/cmd/build.go deleted file mode 100644 index 6b14ab603..000000000 --- a/cmd/build.go +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright 2016 Marapongo, Inc. All rights reserved. - -package cmd - -import ( - "fmt" - "os" - "path/filepath" - "strings" - - "github.com/golang/glog" - "github.com/spf13/cobra" - - "github.com/marapongo/mu/pkg/cmdutil" - "github.com/marapongo/mu/pkg/compiler" -) - -// defaultIn is where the Mu compiler looks for inputs by default. -const defaultInp = "." - -// defaultOutput is where the Mu compiler places build artifacts by default. -const defaultOutp = ".mu" - -func newBuildCmd() *cobra.Command { - var outp string - var cluster string - var targetArch string - var cmd = &cobra.Command{ - Use: "build [source] -- [args]", - Short: "Compile a Mu Stack", - Run: func(cmd *cobra.Command, args []string) { - flags := cmd.Flags() - ddash := flags.ArgsLenAtDash() - - // If there's a --, we need to separate out the command args from the stack args. - var sargs []string - if ddash != -1 { - sargs = args[ddash:] - args = args[0:ddash] - } - - // Fetch the input source directory. - inp := defaultInp - if len(args) > 0 { - inp = args[0] - } - abs, err := filepath.Abs(inp) - if err != nil { - glog.Fatal(err) - } - - opts := compiler.DefaultOptions() - - // Set the cluster and architecture if specified. - opts.Cluster = cluster - cmdutil.SetCloudArchOptions(targetArch, opts) - - // See if there are any arguments and, if so, accumulate them. - if len(sargs) > 0 { - opts.Args = make(map[string]interface{}) - // TODO[marapongo/mu#7]: This is a very rudimentary parser. We can and should do better. - for i := 0; i < len(sargs); i++ { - sarg := sargs[i] - - // Eat - or -- at the start. - if sarg[0] == '-' { - sarg = sarg[1:] - if sarg[0] == '-' { - sarg = sarg[1:] - } - } - // Now find an k=v, and split the k/v part. - if eq := strings.IndexByte(sarg, '='); eq != -1 { - opts.Args[sarg[:eq]] = sarg[eq+1:] - } else { - // No =; if the next arg doesn't start with '-', use it. Else it must be a boolean "true". - if i+1 < len(sargs) && sargs[i+1][0] != '-' { - opts.Args[sarg] = sargs[i+1] - i++ - } else { - // TODO(joe): support --no-key style "false"s. - opts.Args[sarg] = "true" - } - } - } - - } - - // Now new up a compiler and actually perform the build. - mup, err := compiler.New(abs, opts) - if err != nil { - fmt.Fprintf(os.Stderr, "fatal: %v", err) - } - mup.Compile() - }, - } - - cmd.PersistentFlags().StringVar( - &outp, "out", defaultOutp, - "The directory in which to place build artifacts") - cmd.PersistentFlags().StringVarP( - &cluster, "cluster", "c", "", - "Generate output for an existing, named cluster") - cmd.PersistentFlags().StringVarP( - &targetArch, "target", "t", "", - "Generate output for the target cloud architecture (format: \"cloud[:scheduler]\")") - - return cmd -} diff --git a/lib/mu/cluster.mu b/lib/mu/cluster.mu deleted file mode 100644 index afbb49132..000000000 --- a/lib/mu/cluster.mu +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2016 Marapongo, Inc. All rights reserved. - -module mu -import mu/clouds/aws - -// A base Mu cluster that can run on any cloud/scheduler target. -service Cluster { - new() { - switch context.arch.cloud { - case "aws": - cf := new aws.Cluster {} - default: - mu.Panic("Unrecognized cloud target: %v", context.arch.cloud) - } - } -} - diff --git a/lib/mu/cluster.ts b/lib/mu/cluster.ts deleted file mode 100644 index 098a14e4f..000000000 --- a/lib/mu/cluster.ts +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2016 Marapongo, Inc. All rights reserved. - -import * as mu from 'mu'; -import * as aws from 'mu-aws'; - -// A base Mu cluster, ready to host stacks. -// @name: mu/cluster -export default class Cluster extends mu.Stack { - constructor(ctx: mu.Context) { - super(ctx); - switch (ctx.arch.cloud) { - case mu.clouds.AWS: - this.createAWSCloudResources(ctx); - break; - default: - throw new Error(`Unrecognized cloud target: ctx.arch.cloud`); - } - } - - // This function creates all of the basic resources necessary for an AWS cluster ready to host Mu stacks. - private createAWSCloudResources(ctx: mu.Context): void { - // First set up a VPC with a single subnet. - let cidr = "10.0.0.0/16"; - let vpc = new aws.ec2.VPC(ctx, { name: `${ctx.cluster.name}-VPC`, cidrBlock: cidr }); - let subnet = new aws.ec2.Subnet(ctx, { name: `${ctx.cluster.name}-Subnet`, vpc: vpc, cidrBlock: cidr }); - - // Now create an Internet-facing gateway to expose this cluster's subnet to Internet traffic. - let internetGateway = new aws.ec2.InternetGateway(ctx, { name: `${ctx.cluster.name}-InternetGateway` }); - let vpcGatewayAttachment = new aws.ec2.VPCGatewayAttachment( - ctx, { internetGateway: internetGateway, vpc: vpc }); - let routeTable = new aws.ec2.RouteTable(ctx, { name: `${ctx.cluster.name}-RouteTable`, vpc: vpc }); - let route = new aws.ec2.Route(ctx, { - destinationCidrBlock: "0.0.0.0/0", - internetGateway: internetGateway, - vpcGatewayAttachment: vpcGatewayAttachment, - routeTable: routeTable, - }); - - // Finally, create a sole security group to use for everything by default. - let securityGroup = new aws.ec2.SecurityGroup(ctx, { - name: `${ctx.cluster.name}-SecurityGroup`, - vpc: vpc, - groupDescription: "The primary cluster's security group.", - }); - } -} - diff --git a/sdk/javascript/arch.ts b/lib/mu/x/arch.ts similarity index 100% rename from sdk/javascript/arch.ts rename to lib/mu/x/arch.ts diff --git a/sdk/javascript/cluster.ts b/lib/mu/x/bucket/index.ts similarity index 54% rename from sdk/javascript/cluster.ts rename to lib/mu/x/bucket/index.ts index 334582133..bf8fcba24 100644 --- a/sdk/javascript/cluster.ts +++ b/lib/mu/x/bucket/index.ts @@ -1,6 +1,4 @@ // Copyright 2016 Marapongo, Inc. All rights reserved. -export interface Cluster { - name: string; -} +export let todo = "todo"; diff --git a/sdk/javascript/clouds/index.ts b/lib/mu/x/clouds/index.ts similarity index 100% rename from sdk/javascript/clouds/index.ts rename to lib/mu/x/clouds/index.ts diff --git a/lib/mu/x/cluster.ts b/lib/mu/x/cluster.ts new file mode 100644 index 000000000..75cc0aa7f --- /dev/null +++ b/lib/mu/x/cluster.ts @@ -0,0 +1,82 @@ +// Copyright 2016 Marapongo, Inc. All rights reserved. + +import * as mu from 'mu'; +import * as aws from 'mu-aws'; + +// A base Mu cluster, ready to host stacks. +export default class Cluster extends mu.Stack { + constructor(args: ClusterArgs) { + super(); + + // TODO: support anonymous clusters (e.g., for local testing). + // TODO: load cluster targeting information from other places: + // 1) workspace settings (e.g., map keyed by cluster name). + // 2) general configuration system (e.g., defaults). + + switch(args.arch.cloud) { + case "aws": + this.createAWSCloudResources(args); + break; + default: + throw new Error(`Unrecognized/unimplemented cloud target: ${args.arch.cloud}`); + } + } + + // This function creates all of the basic resources necessary for an AWS cluster ready to host Mu stacks. + private createAWSCloudResources(args: ClusterArgs): void { + // First set up a VPC with a single subnet. + let cidr = "10.0.0.0/16"; + let vpc = new aws.ec2.VPC({ name: `${args.name}-VPC`, cidrBlock: cidr }); + let subnet = new aws.ec2.Subnet({ name: `${args.name}-Subnet`, vpc: vpc, cidrBlock: cidr }); + + // Now create an Internet-facing gateway to expose this cluster's subnet to Internet traffic. + let internetGateway = new aws.ec2.InternetGateway({ name: `${args.name}-InternetGateway` }); + let vpcGatewayAttachment = new aws.ec2.VPCGatewayAttachment( + { internetGateway: internetGateway, vpc: vpc }); + let routeTable = new aws.ec2.RouteTable({ name: `${args.name}-RouteTable`, vpc: vpc }); + let route = new aws.ec2.Route({ + destinationCidrBlock: "0.0.0.0/0", + internetGateway: internetGateway, + vpcGatewayAttachment: vpcGatewayAttachment, + routeTable: routeTable, + }); + + // Finally, create a sole security group to use for everything by default. + let securityGroup = new aws.ec2.SecurityGroup({ + name: `${args.name}-SecurityGroup`, + vpc: vpc, + groupDescription: "The primary cluster's security group.", + }); + } +} + +export interface ClusterArgs { + name: string; // the cluster name. + arch: Arch; // the required architecture to target. +} + +// Arch is the target cloud "architecture" to target. It combines a cloud IaaS provider with an optional +// cloud CaaS container management/scheduling layer. All mu/x abstractions switch on these to do the right thing. +export interface Arch { + cloud: Cloud; // the cloud IaaS provider. + scheduler?: Scheduler; // the optional cloud CaaS scheduler. +} + +// Cloud specifies a cloud infrastructure (IaaS) to target. +export type Cloud = + "aws" | // Amazon Web Services + "gcp" | // Google Cloud Platform + "azure" | // Microsoft Azure + "vmware" // VMWare vSphere, etc. +; + +// Scheduler specifies a cloud container management/scheduling layer (CaaS) to target. +export type Scheduler = + "swarm" | // Docker Swarm + "kubernetes" | // Kubernetes + "mesos" | // Apache Mesos + "awsecs" | // Amazon Elastic Container Service (only valid when targeting aws) + "gcpgke" | // Google Container Engine (only valid when targeting gcp) + "azurecs" // Microsoft Azure Container Service (only valid when targeting azure) +; + diff --git a/lib/mu/x/index.ts b/lib/mu/x/index.ts new file mode 100644 index 000000000..284f7e858 --- /dev/null +++ b/lib/mu/x/index.ts @@ -0,0 +1,11 @@ +// Copyright 2016 Marapongo, Inc. All rights reserved. + +// Export some things directly. +export * from "./cluster"; + +// Export top-level submodules. +import * as bucket from "./bucket"; +import * as clouds from "./clouds"; +import * as schedulers from "./schedulers"; +export {bucket, clouds, schedulers}; + diff --git a/sdk/javascript/schedulers/index.ts b/lib/mu/x/schedulers/index.ts similarity index 100% rename from sdk/javascript/schedulers/index.ts rename to lib/mu/x/schedulers/index.ts diff --git a/pkg/cmdutil/clouds.go b/pkg/cmdutil/clouds.go deleted file mode 100644 index cbf37c277..000000000 --- a/pkg/cmdutil/clouds.go +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2016 Marapongo, Inc. All rights reserved. - -package cmdutil - -import ( - "fmt" - "os" - "strings" - - "github.com/marapongo/mu/pkg/compiler" - "github.com/marapongo/mu/pkg/compiler/backends" - "github.com/marapongo/mu/pkg/compiler/backends/clouds" - "github.com/marapongo/mu/pkg/compiler/backends/schedulers" -) - -func SetCloudArchOptions(arch string, opts *compiler.Options) { - // If an architecture was specified, parse the pieces and set the options. This isn't required because stacks - // and workspaces can have defaults. This simply overrides or provides one where none exists. - if arch != "" { - // The format is "cloud[:scheduler]"; parse out the pieces. - var cloud string - var scheduler string - if delim := strings.IndexRune(arch, ':'); delim != -1 { - cloud = arch[:delim] - scheduler = arch[delim+1:] - } else { - cloud = arch - } - - cloudArch, ok := clouds.Values[cloud] - if !ok { - fmt.Fprintf(os.Stderr, "Unrecognized cloud arch '%v'\n", cloud) - os.Exit(-1) - } - - var schedulerArch schedulers.Arch - if scheduler != "" { - schedulerArch, ok = schedulers.Values[scheduler] - if !ok { - fmt.Fprintf(os.Stderr, "Unrecognized cloud scheduler arch '%v'\n", scheduler) - os.Exit(-1) - } - } - - opts.Arch = backends.Arch{ - Cloud: cloudArch, - Scheduler: schedulerArch, - } - } -} diff --git a/pkg/compiler/backends/arch.go b/pkg/compiler/backends/arch.go deleted file mode 100644 index 7dc735594..000000000 --- a/pkg/compiler/backends/arch.go +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2016 Marapongo, Inc. All rights reserved. - -package backends - -import ( - "github.com/marapongo/mu/pkg/compiler/backends/clouds" - "github.com/marapongo/mu/pkg/compiler/backends/schedulers" -) - -// Arch is the target cloud "architecture" we are compiling against. -type Arch struct { - Cloud clouds.Arch - Scheduler schedulers.Arch -} - -func (a Arch) String() string { - s := clouds.Names[a.Cloud] - if a.Scheduler != schedulers.None { - s += ":" + schedulers.Names[a.Scheduler] - } - return s -} diff --git a/pkg/compiler/backends/clouds/cloud.go b/pkg/compiler/backends/clouds/cloud.go deleted file mode 100644 index 1ddafc8cb..000000000 --- a/pkg/compiler/backends/clouds/cloud.go +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2016 Marapongo, Inc. All rights reserved. - -package clouds - -import ( - "github.com/marapongo/mu/pkg/compiler/core" -) - -// Cloud is an interface for providers that can target a Mu stack to a specific cloud IaaS. -type Cloud interface { - core.Backend - Arch() Arch -} diff --git a/pkg/compiler/backends/clouds/clouds.go b/pkg/compiler/backends/clouds/clouds.go deleted file mode 100644 index c75ab3536..000000000 --- a/pkg/compiler/backends/clouds/clouds.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2016 Marapongo, Inc. All rights reserved. - -package clouds - -// Arch selects a cloud infrastructure to target when compiling. -type Arch int - -const ( - None Arch = iota // no target specified. - AWS // Amazon Web Services. - GCP // Google Cloud Platform. - Azure // Microsoft Azure. - VMWare // VMWare vSphere, etc. -) - -const ( - none = "" - aws = "aws" - gcp = "gcp" - azure = "azure" - vmware = "vmware" -) - -// Names maps Archs to human-friendly names. -var Names = map[Arch]string{ - None: none, - AWS: aws, - GCP: gcp, - Azure: azure, - VMWare: vmware, -} - -// Values maps human-friendly names to the Archs for those names. -var Values = map[string]Arch{ - none: None, - aws: AWS, - gcp: GCP, - azure: Azure, - vmware: VMWare, -} diff --git a/pkg/compiler/backends/provider.go b/pkg/compiler/backends/provider.go deleted file mode 100644 index a2d6a7e11..000000000 --- a/pkg/compiler/backends/provider.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2016 Marapongo, Inc. All rights reserved. - -package backends - -import ( - "github.com/marapongo/mu/pkg/compiler/backends/clouds" - "github.com/marapongo/mu/pkg/compiler/backends/clouds/aws" - "github.com/marapongo/mu/pkg/compiler/backends/schedulers" - "github.com/marapongo/mu/pkg/compiler/backends/schedulers/awsecs" - "github.com/marapongo/mu/pkg/compiler/core" - "github.com/marapongo/mu/pkg/diag" - "github.com/marapongo/mu/pkg/util/contract" -) - -func New(arch Arch, d diag.Sink) core.Backend { - // Bind to the cloud provider. - var cloud clouds.Cloud - switch arch.Cloud { - case clouds.AWS: - // TODO(joe): come up with a way to get options from CLI/workspace/etc. to here. - cloud = aws.New(d, aws.Options{}) - case clouds.None: - contract.Failf("Expected a non-None cloud architecture") - default: - contract.Failf("Cloud architecture '%v' not yet supported", clouds.Names[arch.Cloud]) - } - contract.Assert(cloud != nil) - contract.Assert(cloud.Arch() == arch.Cloud) - - // Set the backend to the cloud provider. - var be core.Backend = cloud - - // Now bind to the scheduler, if any, wrapping the cloud and replacing the backend. - var scheduler schedulers.Scheduler - switch arch.Scheduler { - case schedulers.None: - // Nothing to do. - case schedulers.AWSECS: - scheduler = awsecs.New(d, cloud) - default: - contract.Failf("Scheduler architecture '%v' not yet supported", schedulers.Names[arch.Scheduler]) - } - if scheduler != nil { - contract.Assert(scheduler.Arch() == arch.Scheduler) - be = scheduler - } - - return be -} diff --git a/pkg/compiler/backends/schedulers/awsecs/scheduler.go b/pkg/compiler/backends/schedulers/awsecs/scheduler.go deleted file mode 100644 index 67bc65699..000000000 --- a/pkg/compiler/backends/schedulers/awsecs/scheduler.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2016 Marapongo, Inc. All rights reserved. - -package awsecs - -import ( - "github.com/marapongo/mu/pkg/compiler/backends/clouds" - "github.com/marapongo/mu/pkg/compiler/backends/schedulers" - "github.com/marapongo/mu/pkg/compiler/core" - "github.com/marapongo/mu/pkg/compiler/errors" - "github.com/marapongo/mu/pkg/diag" -) - -// New returns a fresh instance of an AWS ECS Scheduler implementation. This requires an AWS backend, since ECS only -// works in an AWS environment. The code-gen outputs are idiomatic ECS, using Tasks and so on. -// -// For more details, see https://github.com/marapongo/mu/blob/master/docs/targets.md#aws-ec2-container-service-ecs -func New(d diag.Sink, be clouds.Cloud) schedulers.Scheduler { - arch := be.Arch() - if arch != clouds.AWS { - d.Errorf(errors.ErrorIllegalCloudSchedulerCombination, clouds.Names[arch], "awsecs") - } - return &awsECSScheduler{d: d, be: be} -} - -type awsECSScheduler struct { - schedulers.Scheduler - d diag.Sink - be clouds.Cloud // an AWS cloud provider. -} - -func (s *awsECSScheduler) Arch() schedulers.Arch { - return schedulers.AWSECS -} - -func (s *awsECSScheduler) Diag() diag.Sink { - return s.d -} - -func (s *awsECSScheduler) CodeGen(comp core.Compiland) { - // For now, simply rely on the underlying AWS code-generator to do its thing. - s.be.CodeGen(comp) -} diff --git a/pkg/compiler/backends/schedulers/scheduler.go b/pkg/compiler/backends/schedulers/scheduler.go deleted file mode 100644 index ba3996e70..000000000 --- a/pkg/compiler/backends/schedulers/scheduler.go +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2016 Marapongo, Inc. All rights reserved. - -package schedulers - -import ( - "github.com/marapongo/mu/pkg/compiler/core" -) - -// Scheduler is an interface for providers that can target a Mu stack to a specific cloud CaaS. -type Scheduler interface { - core.Backend - Arch() Arch -} diff --git a/pkg/compiler/backends/schedulers/schedulers.go b/pkg/compiler/backends/schedulers/schedulers.go deleted file mode 100644 index 2cd2a2ab2..000000000 --- a/pkg/compiler/backends/schedulers/schedulers.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2016 Marapongo, Inc. All rights reserved. - -package schedulers - -// selects a cloud scheduler to target when compiling. -type Arch int - -const ( - None Arch = iota // no scheduler, just use native VMs. - DockerSwarm // Docker Swarm - Kubernetes // Kubernetes - Mesos // Apache Mesos - AWSECS // Amazon Elastic Container Service (only valid for AWS) - GCPGKE // Google Container Engine (only valid for GCP) - AzureACS // Microsoft Azure Container Service (only valid for Azure) -) - -const ( - none = "" - dockerSwarm = "swarm" - kubernetes = "kubernetes" - mesos = "mesos" - awsECS = "ecs" - gcpGKE = "gke" - azureACS = "acs" -) - -// Names maps s to human-friendly names. -var Names = map[Arch]string{ - None: none, - DockerSwarm: dockerSwarm, - Kubernetes: kubernetes, - Mesos: mesos, - AWSECS: awsECS, - GCPGKE: gcpGKE, - AzureACS: azureACS, -} - -// Values maps human-friendly names to the s for those names. -var Values = map[string]Arch{ - none: None, - dockerSwarm: DockerSwarm, - kubernetes: Kubernetes, - mesos: Mesos, - awsECS: AWSECS, - gcpGKE: GCPGKE, - azureACS: AzureACS, -} diff --git a/pkg/compiler/compiler_fe.go b/pkg/compiler/compiler_fe.go deleted file mode 100644 index 1156f827c..000000000 --- a/pkg/compiler/compiler_fe.go +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright 2016 Marapongo, Inc. All rights reserved. - -package compiler - -import ( - "github.com/satori/go.uuid" - - "github.com/marapongo/mu/pkg/compiler/backends" - "github.com/marapongo/mu/pkg/compiler/backends/clouds" - "github.com/marapongo/mu/pkg/compiler/backends/schedulers" - "github.com/marapongo/mu/pkg/compiler/errors" - "github.com/marapongo/mu/pkg/config" - "github.com/marapongo/mu/pkg/workspace" -) - -// detectClusterArch uses a variety of mechanisms to discover the target architecture, returning it. If no -// architecture was discovered, an error is issued, and the bool return will be false. -func (c *compiler) detectClusterArch(w workspace.W) (*config.Cluster, backends.Arch) { - // Cluster and architectures settings may come from one of two places, in order of search preference: - // 1) command line arguments. - // 2) cluster-wide settings in a workspace. - var arch backends.Arch - var cluster *config.Cluster - - // If a cluster was specified, look it up and load up its options. - clname := c.Options().Cluster - if clname != "" { - if cl, exists := w.Settings().Clusters[clname]; exists { - cluster = cl - } else { - c.Diag().Errorf(errors.ErrorClusterNotFound, clname) - return nil, arch - } - } - - // If no cluster was specified or discovered yet, see if there is a default one to use. - if cluster == nil { - for _, cl := range w.Settings().Clusters { - if cl.Default { - cluster = cl - break - } - } - } - - if cluster == nil { - // If no target was found, and we don't have an architecture, error out. - if arch.Cloud == clouds.None { - c.Diag().Errorf(errors.ErrorMissingTarget) - return nil, arch - } - - // If we got here, generate an "anonymous" cluster, so that we at least have a name. - cluster = c.newAnonCluster(arch) - } else { - // If a target was found, go ahead and extract and validate the target architecture. - a, ok := c.extractClusterArch(cluster, arch) - if !ok { - return nil, arch - } - arch = a - } - - return cluster, arch -} - -// newAnonCluster creates an anonymous cluster for stacks that didn't declare one. -func (c *compiler) newAnonCluster(arch backends.Arch) *config.Cluster { - // TODO: ensure this is unique. - // TODO: we want to cache names somewhere (~/.mu/?) so that we can reuse temporary local stacks, etc. - return &config.Cluster{ - Name: uuid.NewV4().String(), - Cloud: clouds.Names[arch.Cloud], - Scheduler: schedulers.Names[arch.Scheduler], - } -} - -// extractClusterArch gets and validates the architecture from an existing target. -func (c *compiler) extractClusterArch(cluster *config.Cluster, existing backends.Arch) (backends.Arch, bool) { - targetCloud := existing.Cloud - targetScheduler := existing.Scheduler - - // If specified, look up the cluster's architecture settings. - if cluster.Cloud != "" { - tc, ok := clouds.Values[cluster.Cloud] - if !ok { - c.Diag().Errorf(errors.ErrorUnrecognizedCloudArch, cluster.Cloud) - return existing, false - } - targetCloud = tc - } - if cluster.Scheduler != "" { - ts, ok := schedulers.Values[cluster.Scheduler] - if !ok { - c.Diag().Errorf(errors.ErrorUnrecognizedSchedulerArch, cluster.Scheduler) - return existing, false - } - targetScheduler = ts - } - - // Ensure there aren't any conflicts, comparing compiler options to cluster settings. - tarch := backends.Arch{targetCloud, targetScheduler} - if targetCloud != existing.Cloud && existing.Cloud != clouds.None { - c.Diag().Errorf(errors.ErrorConflictingClusterArchSelection, existing, cluster.Name, tarch) - return tarch, false - } - if targetScheduler != existing.Scheduler && existing.Scheduler != schedulers.None { - c.Diag().Errorf(errors.ErrorConflictingClusterArchSelection, existing, cluster.Name, tarch) - return tarch, false - } - - return tarch, true -} diff --git a/pkg/compiler/opts.go b/pkg/compiler/opts.go index 6e2dda011..b9c16a0d2 100644 --- a/pkg/compiler/opts.go +++ b/pkg/compiler/opts.go @@ -3,16 +3,13 @@ package compiler import ( - "github.com/marapongo/mu/pkg/compiler/backends" "github.com/marapongo/mu/pkg/diag" ) // Options contains all of the settings a user can use to control the compiler's behavior. type Options struct { - Diag diag.Sink // a sink to use for all diagnostics. - Arch backends.Arch // a target cloud architecture. - Cluster string // a named cluster with predefined settings to target. - Args map[string]interface{} // optional blueprint arguments passed at the CLI. + Diag diag.Sink // a sink to use for all diagnostics. + Args map[string]interface{} // optional blueprint arguments passed at the CLI. } // DefaultOptions returns the default set of compiler options. diff --git a/pkg/compiler/backends/clouds/aws/cf.go b/pkg/resource/providers/aws/cf.go similarity index 100% rename from pkg/compiler/backends/clouds/aws/cf.go rename to pkg/resource/providers/aws/cf.go diff --git a/pkg/compiler/backends/clouds/aws/cloud.go b/pkg/resource/providers/aws/cloud.go similarity index 100% rename from pkg/compiler/backends/clouds/aws/cloud.go rename to pkg/resource/providers/aws/cloud.go diff --git a/pkg/compiler/backends/clouds/aws/errors.go b/pkg/resource/providers/aws/errors.go similarity index 100% rename from pkg/compiler/backends/clouds/aws/errors.go rename to pkg/resource/providers/aws/errors.go diff --git a/pkg/compiler/backends/clouds/aws/intrins.go b/pkg/resource/providers/aws/intrins.go similarity index 100% rename from pkg/compiler/backends/clouds/aws/intrins.go rename to pkg/resource/providers/aws/intrins.go diff --git a/pkg/compiler/backends/clouds/aws/names.go b/pkg/resource/providers/aws/names.go similarity index 100% rename from pkg/compiler/backends/clouds/aws/names.go rename to pkg/resource/providers/aws/names.go diff --git a/pkg/compiler/backends/clouds/aws/names_test.go b/pkg/resource/providers/aws/names_test.go similarity index 100% rename from pkg/compiler/backends/clouds/aws/names_test.go rename to pkg/resource/providers/aws/names_test.go diff --git a/sdk/javascript/context.ts b/sdk/javascript/context.ts index 7607a0ecb..18eed6bd9 100644 --- a/sdk/javascript/context.ts +++ b/sdk/javascript/context.ts @@ -1,14 +1,10 @@ // Copyright 2016 Marapongo, Inc. All rights reserved. -import { Arch } from './arch'; -import { Cluster } from './cluster'; import { Options } from './options'; // A collection of information pertaining to the current compilation activity, like target cloud architecture, the // cluster name, any compile-time options, and so on. export interface Context { - arch: Arch; // the cloud architecture to target. - cluster: Cluster; // the cluster we will be deploying to. options: Options; // any compiler options supplied. } diff --git a/sdk/javascript/index.ts b/sdk/javascript/index.ts index 994a50e4a..71bcb41b2 100644 --- a/sdk/javascript/index.ts +++ b/sdk/javascript/index.ts @@ -1,14 +1,8 @@ // Copyright 2016 Marapongo, Inc. All rights reserved. -export * from './arch'; -export * from './cluster'; export * from './context'; export * from './extension'; export * from './json'; export * from './options'; export * from './stack'; -import * as clouds from './clouds'; -import * as schedulers from './schedulers'; -export { clouds, schedulers }; - diff --git a/sdk/javascript/tsconfig.json b/sdk/javascript/tsconfig.json index c846493b8..d1563da75 100644 --- a/sdk/javascript/tsconfig.json +++ b/sdk/javascript/tsconfig.json @@ -18,16 +18,11 @@ "files": [ "index.ts", - "arch.ts", - "cluster.ts", "context.ts", "extension.ts", "json.ts", "options.ts", - "stack.ts", - - "clouds/index.ts", - "schedulers/index.ts" + "stack.ts" ] }