This repository has been archived by the owner on May 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from buzzfrog/dagk/create-environment
Script to create a developer environment
- Loading branch information
Showing
13 changed files
with
410 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// ------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information. | ||
// ------------------------------------------------------------ | ||
targetScope = 'subscription' | ||
|
||
@description('The common name for this application') | ||
param applicationName string | ||
|
||
@description('Location of resources') | ||
@allowed([ | ||
'westeurope' | ||
'northeurope' | ||
'westus' | ||
'swedencentral' | ||
]) | ||
param location string = 'westeurope' | ||
|
||
var applicationNameWithoutDashes = '${replace(applicationName,'-','')}' | ||
var resourceGroupName = 'rg-${applicationNameWithoutDashes}' | ||
var aksName = '${take('aks-${applicationNameWithoutDashes}',20)}' | ||
var acrName = 'acr${applicationNameWithoutDashes}' | ||
var storageAccountName = 'st${take(applicationNameWithoutDashes,14)}' | ||
var eventHubNameSpaceName = 'evh${take(applicationNameWithoutDashes,14)}' | ||
|
||
resource rg 'Microsoft.Resources/resourceGroups@2020-10-01' = { | ||
name: resourceGroupName | ||
location: location | ||
} | ||
|
||
module aks 'modules/aks.bicep' = { | ||
name: 'aksDeployment' | ||
scope: resourceGroup(rg.name) | ||
params: { | ||
aksName: aksName | ||
} | ||
} | ||
|
||
module acr 'modules/arc.bicep' = { | ||
scope: resourceGroup(rg.name) | ||
name: 'acrDeployment' | ||
params: { | ||
acrName: acrName | ||
aksPrincipalId: aks.outputs.clusterPrincipalID | ||
} | ||
|
||
dependsOn: [ | ||
aks | ||
] | ||
} | ||
|
||
module storage 'modules/azurestorage.bicep' = { | ||
scope: resourceGroup(rg.name) | ||
name: 'storageDeployment' | ||
params: { | ||
storageAccountName: storageAccountName | ||
} | ||
} | ||
|
||
module eventhub 'modules/eventhub.bicep' = { | ||
scope: resourceGroup(rg.name) | ||
name: 'eventHubDeployment' | ||
params: { | ||
eventHubNameSpaceName: eventHubNameSpaceName | ||
} | ||
} | ||
|
||
output acrName string = acrName | ||
output aksName string = aks.outputs.aksName | ||
output resourceGroupName string = resourceGroupName | ||
output storageKey string = storage.outputs.storageKey | ||
output storageName string = storage.outputs.storageName | ||
output eventHubConnectionString string = eventhub.outputs.eventHubConnectionString |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// ------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information. | ||
// ------------------------------------------------------------ | ||
@maxLength(20) | ||
@description('AKS Name') | ||
param aksName string | ||
|
||
// optional params | ||
@minValue(0) | ||
@maxValue(1023) | ||
param osDiskSizeGB int = 0 | ||
|
||
@minValue(1) | ||
@maxValue(50) | ||
param agentCount int = 3 | ||
|
||
param agentVMSize string = 'Standard_B4ms' | ||
|
||
resource aks 'Microsoft.ContainerService/managedClusters@2020-09-01' = { | ||
name: aksName | ||
location: resourceGroup().location | ||
identity: { | ||
type: 'SystemAssigned' | ||
} | ||
properties: { | ||
enableRBAC: true | ||
dnsPrefix: uniqueString(aksName) | ||
agentPoolProfiles: [ | ||
{ | ||
name: 'agentpool' | ||
enableAutoScaling: false | ||
osDiskSizeGB: osDiskSizeGB | ||
count: agentCount | ||
vmSize: agentVMSize | ||
osType: 'Linux' | ||
mode: 'System' | ||
} | ||
] | ||
servicePrincipalProfile: { | ||
clientId: 'msi' | ||
} | ||
} | ||
} | ||
|
||
output controlPlaneFQDN string = aks.properties.fqdn | ||
output aksName string = aks.name | ||
output clusterPrincipalID string = aks.properties.identityProfile.kubeletidentity.objectId |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// ------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information. | ||
// ------------------------------------------------------------ | ||
@description('ACR Name') | ||
@maxLength(20) | ||
param acrName string | ||
|
||
@description('The principal ID of the AKS cluster') | ||
param aksPrincipalId string | ||
|
||
@allowed([ | ||
'b24988ac-6180-42a0-ab88-20f7382dd24c' // Contributor | ||
'acdd72a7-3385-48ef-bd42-f606fba81ae7' // Reader | ||
]) | ||
param roleAcrPull string = 'b24988ac-6180-42a0-ab88-20f7382dd24c' | ||
|
||
resource acr 'Microsoft.ContainerRegistry/registries@2021-06-01-preview' = { | ||
name: acrName | ||
location: resourceGroup().location | ||
sku: { | ||
name: 'Standard' | ||
} | ||
properties: { | ||
adminUserEnabled: true | ||
} | ||
} | ||
|
||
resource assignAcrPullToAks 'Microsoft.Authorization/roleAssignments@2020-04-01-preview' = { | ||
name: guid(resourceGroup().id, acrName, aksPrincipalId, 'AssignAcrPullToAks') | ||
scope: acr | ||
properties: { | ||
description: 'Assign AcrPull role to AKS' | ||
principalId: aksPrincipalId | ||
principalType: 'ServicePrincipal' | ||
roleDefinitionId: '/subscriptions/${subscription().subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/${roleAcrPull}' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
param storageAccountName string | ||
|
||
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-04-01' = { | ||
name: storageAccountName | ||
location: resourceGroup().location | ||
sku: { | ||
name: 'Standard_LRS' | ||
} | ||
kind: 'StorageV2' | ||
properties: { | ||
accessTier: 'Hot' | ||
} | ||
} | ||
|
||
output storageKey string = storageAccount.listKeys().keys[0].value | ||
output storageName string = storageAccountName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// ------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information. | ||
// ------------------------------------------------------------ | ||
@maxLength(20) | ||
@description('AKS Name') | ||
param eventHubNameSpaceName string | ||
|
||
resource eventHubNamespace 'Microsoft.EventHub/namespaces@2021-01-01-preview' = { | ||
name: eventHubNameSpaceName | ||
location: resourceGroup().location | ||
sku: { | ||
name: 'Standard' | ||
tier: 'Standard' | ||
capacity: 1 | ||
} | ||
properties: { | ||
zoneRedundant: false | ||
} | ||
} | ||
|
||
var eventHubName = '${eventHubNameSpaceName}hub' | ||
resource eventHubNamespaceName_eventHubName 'Microsoft.EventHub/namespaces/eventhubs@2021-01-01-preview' = { | ||
parent: eventHubNamespace | ||
name: eventHubName | ||
properties: { | ||
messageRetentionInDays: 7 | ||
partitionCount: 1 | ||
} | ||
} | ||
|
||
resource eventHubNamespaceName_eventHubName_ListenSend 'Microsoft.EventHub/namespaces/eventhubs/authorizationRules@2021-01-01-preview' = { | ||
parent: eventHubNamespaceName_eventHubName | ||
name: 'iot-edge' | ||
properties: { | ||
rights: [ | ||
'Listen' | ||
'Send' | ||
] | ||
} | ||
dependsOn: [ | ||
eventHubNamespace | ||
] | ||
} | ||
var eventHubConnectionString = listKeys(eventHubNamespaceName_eventHubName_ListenSend.id, eventHubNamespaceName_eventHubName_ListenSend.apiVersion).primaryConnectionString | ||
|
||
output eventHubConnectionString string = eventHubConnectionString | ||
output eventHubName string = eventHubName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# ------------------------------------------------------------ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License (MIT). See License.txt in the repo root for license information. | ||
# ------------------------------------------------------------ | ||
|
||
Param( | ||
[string] | ||
$ResourceGroupName | ||
) | ||
|
||
if(!$env:RESOURCEGROUPNAME -and !$ResourceGroupName) | ||
{ | ||
Write-Error "Environment variable RESOURCEGROUPNAME is not set and ResourceGroupName parameter is not set" | ||
Exit | ||
} | ||
if(!$ResourceGroupName) | ||
{ | ||
$ResourceGroupName = $env:RESOURCEGROUPNAME | ||
} | ||
|
||
Function Write-Title ($text) { | ||
$width = (Get-Host).UI.RawUI.WindowSize.Width | ||
$title = "" | ||
if($text.length -ne 0) | ||
{ | ||
$title = "=[ " + $text + " ]=" | ||
} | ||
|
||
Write-Host $title.PadRight($width, "=") -ForegroundColor green | ||
} | ||
|
||
$deploymentId = Get-Random | ||
$startTime = Get-Date | ||
$acrName = (az acr list -g $ResourceGroupName --query [].name -o tsv) | ||
|
||
# ----- Build and Push Containers | ||
Write-Title("Build and Push Containers") | ||
$deplymentDir = Get-Location | ||
Set-Location -Path ../iotedge/Distributed.IoT.Edge | ||
az acr build --image datagatewaymodule:$deploymentId --registry $acrName --file Distributed.IoT.Edge.DataGatewayModule/Dockerfile . | ||
az acr build --image simulatedtemperaturesensormodule:$deploymentId --registry $acrName --file Distributed.IoT.Edge.SimulatedTemperatureSensorModule/Dockerfile . | ||
Set-Location -Path $deplymentDir | ||
|
||
# ----- Run Helm | ||
Write-Title("Upgrade Pod/Containers with Helm in Cluster") | ||
$datagatewaymoduleimage = $acrName + ".azurecr.io/datagatewaymodule:" + $deploymentId | ||
$simtempimage = $acrName + ".azurecr.io/simulatedtemperaturesensormodule:" + $deploymentId | ||
helm upgrade iot-edge-accelerator ./helm/iot-edge-accelerator ` | ||
--set-string images.datagatewaymodule="$datagatewaymoduleimage" ` | ||
--set-string images.simulatedtemperaturesensormodule="$simtempimage" ` | ||
|
||
$runningTime = New-TimeSpan -Start $startTime | ||
|
||
Write-Host "Tag: " $deploymentId -ForegroundColor Green | ||
Write-Host "Running time:" $runningTime.ToString() -ForegroundColor Yellow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Setup an developer environment | ||
|
||
## Introduction | ||
This environment is used to setup a fast developer environment, which means that Acr and Flux is not included | ||
in the environment. | ||
|
||
## How to execute it | ||
Go to the `development` folder and run `deploy-aks-dapr.ps1 -ApplicationName <short-name>` | ||
|
||
## The main functions in the script | ||
1. Deploy infrastructure with Bicep | ||
* AKS | ||
* ACR | ||
|
||
2. Use `az acr build` to build and push images to the ACR | ||
|
||
3. Download AKS credentials | ||
|
||
4. Install Dapr with Helm in AKS | ||
|
||
5. Install Redis with Helm in AKS | ||
|
||
6. Install our components with Helm in AKS |
Oops, something went wrong.