Skip to content

Commit

Permalink
Update bundles per arm mixin usage (#862)
Browse files Browse the repository at this point in the history
  • Loading branch information
vdice authored Jan 27, 2020
1 parent 4401e74 commit ad06cce
Show file tree
Hide file tree
Showing 30 changed files with 709 additions and 211 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ FILE_EXT=
endif

INT_MIXINS = exec kubernetes
EXT_MIXINS = helm azure terraform
EXT_MIXINS = helm arm terraform
MIXIN_TAG ?= canary
MIXINS_URL = https://cdn.porter.sh/mixins

Expand Down
57 changes: 29 additions & 28 deletions docs/content/wiring.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ Once a parameter has been declared in the `porter.yaml`, Porter provides a simpl

```yaml
install:
- description: "Install MySQL"
helm:
- helm:
description: "Install MySQL"
name: porter-ci-mysql
chart: stable/mysql
version: 0.10.2
Expand Down Expand Up @@ -107,9 +107,10 @@ In addition to parameters and credentials, Porter introduces a type called an ou

```yaml
install:
- description: "Create Azure MySQL"
azure:
type: mysql
- arm:
description: "Create Azure MySQL"
type: arm
template: "arm/mysql.json"
name: demo-mysql-azure-porter-demo-wordpress
resourceGroup: "porter-test"
parameters:
Expand All @@ -120,9 +121,9 @@ install:
version: "5.7"
sslEnforcement: "Disabled"
databaseName: "{{ bundle.parameters.database_name }}"
outputs:
- name: "MYSQL_URL"
key: "MYSQL_HOST"
outputs:
- name: "MYSQL_URL"
key: "MYSQL_HOST"
```

In this example, a new output will be created named `MYSQL_URL`. The Azure mixin allows you to specify the key to fetch the output from, in this case it is `MYSQL_HOST`. Each mixin can provide different ways of addressing outputs, so refer to the schema for each mixin. The Porter runtime will keep a map in memory with each of the outputs declared.
Expand All @@ -136,8 +137,8 @@ Once an output has been declared, it can be referenced in the same way as parame
For example, given the install step above, we can use the `MYSQL_URL` with the helm mixin in the following way:

```yaml
- description: "Helm Install Wordpress"
helm:
- helm:
description: "Helm Install Wordpress"
name: porter-ci-wordpress
chart: stable/wordpress
set:
Expand Down Expand Up @@ -168,8 +169,8 @@ images:
These images will be used to build the `bundle.json` images section, but can also be referenced using the same syntax you would use for referencing `parameters`, `credentials`, and `outputs`.

```yaml
- description: "Helm Install Wordpress"
helm:
- helm:
description: "Helm Install Wordpress"
name: porter-ci-wordpress
chart: stable/wordpress
set:
Expand Down Expand Up @@ -205,22 +206,22 @@ parameters:
env: MYSQL_USER
install:
- description: "Install MySQL"
helm:
- helm:
description: "Install MySQL"
name: porter-ci-mysql
chart: stable/mysql
version: 0.10.2
version: 1.6.2
replace: true
set:
mysqlDatabase: "{{ bundle.parameters.database-name }}"
mysqlUser: "{{ bundle.parameters.mysql-user }}"
outputs:
- name: mysql-root-password
secret: porter-ci-mysql
key: mysql-root-password
- name: mysql-password
secret: porter-ci-mysql
key: mysql-password
outputs:
- name: mysql-root-password
secret: porter-ci-mysql
key: mysql-root-password
- name: mysql-password
secret: porter-ci-mysql
key: mysql-password
```

In this bundle, we see the normal declaration of credentials, parameters and outputs, along with the use of `"{{ bundle.x.y.z }}"` to use these. With this bundle definition, we can build a second bundle to install wordpress and declare a dependency on this bundle. The `porter.yaml` for this might look something like:
Expand Down Expand Up @@ -251,8 +252,8 @@ parameters:
env: WORDPRESS_NAME
install:
- description: "Install Wordpress"
helm:
- helm:
description: "Install Wordpress"
name: "{{ bundle.parameters.wordpress-name }}"
chart: stable/wordpress
replace: true
Expand All @@ -266,8 +267,8 @@ The wordpress bundle declares a dependency on the `mysql` bundle, which we saw a

```yaml
install:
- description: "Install Wordpress"
helm:
- helm:
description: "Install Wordpress"
name: "{{ bundle.parameters.wordpress-name }}"
chart: stable/wordpress
replace: true
Expand All @@ -287,8 +288,8 @@ It is possible to reference multiple parameters, credentials and/or outputs in a

```yaml
install:
- description: "Install Java App"
helm:
- helm:
description: "Install Java App"
name: "{{ bundle.parameters.cool-app}}"
chart: stable/wordpress
replace: true
Expand Down
13 changes: 9 additions & 4 deletions examples/aks-spring-music/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

This bundle demonstrates advanced use cases for Porter.

The bundle leverages a base Dockerfile (cnab/app/Dockerfile.base) to customize the resulting invocation image for the bundle by first installing the `azure cli` so that it can be used by the `exec` mixin. It then uses 4 mixins to access your Azure subscription and deploy the app. These values need to be updated in the porter.yaml.
The bundle leverages a base Dockerfile (Dockerfile.tmpl) to customize the resulting invocation image for the bundle by first installing the `azure cli` so that it can be used by the `exec` mixin. It then uses 4 mixins to access your Azure subscription and deploy the app. These values need to be updated in the porter.yaml.

* The `azure` mixin is used to create an AKS cluster using ARM. This requires subscription and tenant info.
* The `arm` mixin is used to create an AKS cluster using ARM. This requires subscription and tenant info.
* The `exec` mixin uses an Azure Service Principal to access via the CLI and install Helm's Tiller into an AKS cluster.
* The `kubernetes` mixin applys RBAC policies for Helm
* The `helm` mixin deploys the chart into the AKS cluster.
Expand Down Expand Up @@ -37,7 +37,7 @@ The bundle will use the service principal created above to interact with Azure.
```

* Update params for your deployment
* change the `invocationImage` Docker repo to match your Docker Hub account (line 4)
* change the `tag` Docker repo to match your Docker Hub account
* Cosmos and AKS names must be unique. You can either edit the `porter.yaml` file default values (starting on line 90) or you can supply the with the porter CLI as shown below.

* Build the innvocation image
Expand All @@ -50,5 +50,10 @@ The bundle will use the service principal created above to interact with Azure.

```bash
export INSTALL_ID=314
porter install -c azure --param app-resource-group=spring-music-demo-$INSTALL_ID --param aks-resource-group=spring-music-demo-$INSTALL_ID --param aks-cluster-name=briar-aks-spring-$INSTALL_ID --param cosmosdb-service-name=briarspringmusic$INSTALL_ID --param azure-location=eastus
porter install -c azure \
--param app-resource-group=spring-music-demo-$INSTALL_ID \
--param aks-resource-group=spring-music-demo-$INSTALL_ID \
--param aks-cluster-name=briar-aks-spring-$INSTALL_ID \
--param cosmosdb-service-name=briarspringmusic$INSTALL_ID \
--param azure-location=eastus
```
113 changes: 113 additions & 0 deletions examples/aks-spring-music/arm/aks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"clusterName": {
"type": "string",
"defaultValue": "[concat('cnab-aks-', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "AKS cluster name. Defaults to cnab-aks-xxxxxxxxxxxxx, where xxx... is a unique string based of the hash of your resource group id."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "The location of the Managed Cluster resource."
}
},
"dnsPrefix": {
"type": "string",
"defaultValue": "[concat('cnab-aks-', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "Optional DNS prefix to use with hosted Kubernetes API server FQDN."
}
},
"osDiskSizeGB": {
"type": "int",
"defaultValue": 0,
"metadata": {
"description": "Disk size (in GB) to provision for each of the agent pool nodes. This value ranges from 0 to 1023. Specifying 0 will apply the default disk size for that agentVMSize."
},
"minValue": 0,
"maxValue": 1023
},
"agentCount": {
"type": "int",
"defaultValue": 3,
"metadata": {
"description": "The number of nodes for the cluster."
},
"minValue": 1,
"maxValue": 50
},
"agentVMSize": {
"type": "string",
"defaultValue": "Standard_DS2_v2",
"metadata": {
"description": "The size of the Virtual Machine."
}
},
"servicePrincipalClientId": {
"metadata": {
"description": "Client ID (used by cloudprovider)"
},
"type": "securestring"
},
"servicePrincipalClientSecret": {
"metadata": {
"description": "The Service Principal Client Secret."
},
"type": "securestring"
},
"osType": {
"type": "string",
"defaultValue": "Linux",
"allowedValues": [
"Linux"
],
"metadata": {
"description": "The type of operating system."
}
},
"kubernetesVersion": {
"type": "string",
"defaultValue": "1.15.7",
"metadata": {
"description": "The version of Kubernetes."
}
}
},
"resources": [
{
"apiVersion": "2018-03-31",
"type": "Microsoft.ContainerService/managedClusters",
"location": "[parameters('location')]",
"name": "[parameters('clusterName')]",
"properties": {
"kubernetesVersion": "[parameters('kubernetesVersion')]",
"dnsPrefix": "[parameters('dnsPrefix')]",
"agentPoolProfiles": [
{
"name": "agentpool",
"osDiskSizeGB": "[parameters('osDiskSizeGB')]",
"count": "[parameters('agentCount')]",
"vmSize": "[parameters('agentVMSize')]",
"osType": "[parameters('osType')]",
"storageProfile": "ManagedDisks"
}
],
"servicePrincipalProfile": {
"clientId": "[parameters('servicePrincipalClientId')]",
"Secret": "[parameters('servicePrincipalClientSecret')]"
}
}
}
],
"outputs": {
"controlPlaneFQDN": {
"type": "string",
"value": "[reference(parameters('clusterName')).fqdn]"
}
}
}
94 changes: 94 additions & 0 deletions examples/aks-spring-music/arm/cosmosdb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"type": "string",
"defaultValue": "[concat('cnab-cosmos-', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "Cosmos DB account name. Defaults to cnab-cosmos-xxxxxxxxxxxxx, where xxx... is a unique string based of the hash of your resource group id."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for the Cosmos DB account. Defaults to the resource group location."
}
},
"apiVersion": {
"type": "string",
"defaultValue": "2016-03-31",
"metadata": {
"description": "API Version. Defaults to '2016-03-31'."
}
},
"kind": {
"type": "string",
"defaultValue": "MongoDB",
"metadata": {
"description": "The type/kind of API for the Cosmos Database. Defaults to MongoDB."
}
},
"mongoCapabilities": {
"type": "array",
"defaultValue": [
{
"name": "EnableAggregationPipeline"
},
{
"name": "MongoDBv3.4"
}
],
"metadata": {
"description": "MongoDB API capabilities that should be enabled by default."
}
},
"enableMongoCapabilities": {
"type": "array",
"defaultValue": "[if(equals(parameters('kind'), 'MongoDB'), parameters('mongoCapabilities'), '[]')]",
"metadata": {
"description": "Conditional to enable api specific capabilities if MongoDB is the API chosen."
}
}
},
"variables": {},
"resources": [
{
"apiVersion": "[parameters('apiVersion')]",
"kind": "[parameters('kind')]",
"type": "Microsoft.DocumentDB/databaseAccounts",
"name": "[parameters('name')]",
"location": "[parameters('location')]",
"properties": {
"databaseAccountOfferType": "Standard",
"locations": [
{
"id": "[concat(parameters('name'), '-', parameters('location'))]",
"failoverPriority": 0,
"locationName": "[parameters('location')]"
}
],
"enableMultipleWriteLocations": true,
"isVirtualNetworkFilterEnabled": false,
"virtualNetworkRules": [],
"dependsOn": [],
"capabilities": "[parameters('enableMongoCapabilities')]"
}
}
],
"outputs": {
"HOST": {
"type": "string",
"value": "[reference(parameters('name')).documentEndpoint]"
},
"primary_key": {
"type": "string",
"value": "[listKeys(resourceId('Microsoft.DocumentDb/databaseAccounts', parameters('name')), parameters('apiVersion')).primaryMasterKey]"
},
"connection_string": {
"type": "string",
"value": "[listConnectionStrings(resourceId('Microsoft.DocumentDb/databaseAccounts', parameters('name')), parameters('apiVersion')).connectionStrings[0].connectionString]"
}
}
}
Loading

0 comments on commit ad06cce

Please sign in to comment.