diff --git a/.pipelines/build-linux.sh b/.pipelines/build-linux.sh index 53f6a3a07..8dbf57fdc 100644 --- a/.pipelines/build-linux.sh +++ b/.pipelines/build-linux.sh @@ -15,7 +15,13 @@ echo "----------- Build Docker Provider -------------------------------" make cd $DIR +echo "------------ Bundle Shell Extension Scripts for Agent Release -------------------------" +cd $DIR/../deployment/agent-deployment/ServiceGroupRoot/Scripts +tar -czvf ../artifacts.tar.gz pushAgentToAcr.sh +cd $DIR + echo "------------ Bundle Shell Extension Scripts & HELM chart -------------------------" cd $DIR/../deployment/arc-k8s-extension/ServiceGroupRoot/Scripts tar -czvf ../artifacts.tar.gz ../../../../charts/azuremonitor-containers/ pushChartToAcr.sh + diff --git a/deployment/agent-deployment/ServiceGroupRoot/Parameters/ContainerInsights.Linux.Parameters.json b/deployment/agent-deployment/ServiceGroupRoot/Parameters/ContainerInsights.Linux.Parameters.json new file mode 100644 index 000000000..598ce9698 --- /dev/null +++ b/deployment/agent-deployment/ServiceGroupRoot/Parameters/ContainerInsights.Linux.Parameters.json @@ -0,0 +1,84 @@ +{ + "$schema": "http://schema.express.azure.com/schemas/2015-01-01-alpha/RolloutParameters.json", + "contentVersion": "1.0.0.0", + "wait": [ + { + "name": "waitSdpBakeTime", + "properties": { + "duration": "PT24H" + } + } + ], + "shellExtensions": [ + { + "name": "PushAgentToACR", + "type": "ShellExtensionType", + "properties": { + "maxexecutiontime": "PT1H" + }, + "package": { + "reference": { + "path": "artifacts.tar.gz" + } + }, + "launch": { + "command": [ + "/bin/bash", + "pushAgentToAcr.sh" + ], + "environmentVariables": [ + { + "name": "WINDOWS", + "value": "" + }, + { + "name": "AGENT_IMAGE_URI", + "value": "__CONTAINER_URI__" + }, + { + "name": "AGENT_IMAGE_SAS", + "value": "__CONTAINER_SAS_TOKEN__" + }, + { + "name": "STORAGE_CONTAINER_NAME", + "value": "__STORAGE_CONTAINER_NAME__" + }, + { + "name": "STORAGE_ACCOUNT_NAME", + "value": "__STORAGE_ACCOUNT_NAME__" + }, + { + "name": "AGENT_IMAGE_TAR_FILE_NAME", + "value": "agentimage.tar.gz" + }, + { + "name": "RELEASE_ID", + "value": "__RELEASE_ID__" + }, + { + "name": "ACR_NAME", + "value": "__ACR_NAME__" + }, + { + "name": "AGENT_RELEASE", + "value": "__AGENT_RELEASE__" + }, + { + "name": "AGENT_IMAGE_TAG_SUFFIX", + "value": "__AGENT_IMAGE_TAG_SUFFIX__" + }, + { + "name": "AGENT_IMAGE_FULL_PATH", + "value": "__ACR_NAME__/public/azuremonitor/containerinsights/__AGENT_RELEASE__:__AGENT_RELEASE____AGENT_IMAGE_TAG_SUFFIX__" + } + ], + "identity": { + "type": "userAssigned", + "userAssignedIdentities": [ + "__MANAGED_IDENTITY__" + ] + } + } + } + ] + } \ No newline at end of file diff --git a/deployment/agent-deployment/ServiceGroupRoot/Parameters/ContainerInsights.Windows.Parameters.json b/deployment/agent-deployment/ServiceGroupRoot/Parameters/ContainerInsights.Windows.Parameters.json new file mode 100644 index 000000000..9d208e0c6 --- /dev/null +++ b/deployment/agent-deployment/ServiceGroupRoot/Parameters/ContainerInsights.Windows.Parameters.json @@ -0,0 +1,84 @@ +{ + "$schema": "http://schema.express.azure.com/schemas/2015-01-01-alpha/RolloutParameters.json", + "contentVersion": "1.0.0.0", + "wait": [ + { + "name": "waitSdpBakeTime", + "properties": { + "duration": "PT24H" + } + } + ], + "shellExtensions": [ + { + "name": "PushAgentToACR", + "type": "ShellExtensionType", + "properties": { + "maxexecutiontime": "PT1H" + }, + "package": { + "reference": { + "path": "artifacts.tar.gz" + } + }, + "launch": { + "command": [ + "/bin/bash", + "pushAgentToAcr.sh" + ], + "environmentVariables": [ + { + "name": "WINDOWS", + "value": "win-" + }, + { + "name": "AGENT_IMAGE_URI", + "value": "__CONTAINER_URI__" + }, + { + "name": "AGENT_IMAGE_SAS", + "value": "__CONTAINER_SAS_TOKEN__" + }, + { + "name": "STORAGE_CONTAINER_NAME", + "value": "__STORAGE_CONTAINER_NAME__" + }, + { + "name": "STORAGE_ACCOUNT_NAME", + "value": "__STORAGE_ACCOUNT_NAME__" + }, + { + "name": "AGENT_IMAGE_TAR_FILE_NAME", + "value": "agentimage.tar.zip" + }, + { + "name": "RELEASE_ID", + "value": "__RELEASE_ID__" + }, + { + "name": "ACR_NAME", + "value": "__ACR_NAME__" + }, + { + "name": "AGENT_RELEASE", + "value": "__AGENT_RELEASE__" + }, + { + "name": "AGENT_IMAGE_TAG_SUFFIX", + "value": "__AGENT_IMAGE_TAG_SUFFIX__" + }, + { + "name": "AGENT_IMAGE_FULL_PATH", + "value": "__ACR_NAME__/public/azuremonitor/containerinsights/__AGENT_RELEASE__:win-__AGENT_RELEASE____AGENT_IMAGE_TAG_SUFFIX__" + } + ], + "identity": { + "type": "userAssigned", + "userAssignedIdentities": [ + "__MANAGED_IDENTITY__" + ] + } + } + } + ] + } \ No newline at end of file diff --git a/deployment/agent-deployment/ServiceGroupRoot/RolloutSpecs/RolloutSpecs.json b/deployment/agent-deployment/ServiceGroupRoot/RolloutSpecs/RolloutSpecs.json new file mode 100644 index 000000000..f015cf5d3 --- /dev/null +++ b/deployment/agent-deployment/ServiceGroupRoot/RolloutSpecs/RolloutSpecs.json @@ -0,0 +1,36 @@ +{ + "$schema": "https://ev2schema.azure.net/schemas/2020-01-01/rolloutSpecification.json", + "ContentVersion": "1.0.0.0", + "RolloutMetadata": { + "ServiceModelPath": "ServiceModels//Public.ServiceModel.json", + "ScopeBindingsPath": "ScopeBindings//Public.ScopeBindings.json", + "Name": "ContainerInsightsAgent", + "RolloutType": "Major", + "BuildSource": { + "Parameters": { + "VersionFile": "buildver.txt" + } + }, + "Notification": { + "Email": { + "To": "omscontainers@microsoft.com" + } + } + }, + "OrchestratedSteps": [ + { + "name": "PushLinuxAgent", + "targetType": "ServiceResource", + "targetName": "PushLinuxAgent", + "actions": [ "Shell/PushAgentToACR" ], + "dependsOn": [ ] + }, + { + "name": "PushWindowsAgent", + "targetType": "ServiceResource", + "targetName": "PushWindowsAgent", + "actions": [ "Shell/PushAgentToACR" ], + "dependsOn": [ ] + } + ] + } \ No newline at end of file diff --git a/deployment/agent-deployment/ServiceGroupRoot/ScopeBindings/Public.ScopeBindings.json b/deployment/agent-deployment/ServiceGroupRoot/ScopeBindings/Public.ScopeBindings.json new file mode 100644 index 000000000..99acfb68e --- /dev/null +++ b/deployment/agent-deployment/ServiceGroupRoot/ScopeBindings/Public.ScopeBindings.json @@ -0,0 +1,48 @@ +{ + "$schema": "https://ev2schema.azure.net/schemas/2020-01-01/scopeBindings.json", + "contentVersion": "0.0.0.1", + "scopeBindings": [ + { + "scopeTagName": "Global", + "bindings": [ + { + "find": "__ACR_NAME__", + "replaceWith": "$(ACRName)" + }, + { + "find": "__AGENT_RELEASE__", + "replaceWith": "$(AgentRelease)" + }, + { + "find": "__AGENT_IMAGE_TAG_SUFFIX__", + "replaceWith": "$(AgentImageTagSuffix)" + }, + { + "find": "__RELEASE_ID__", + "replaceWith": "$(Release.ReleaseId)" + }, + { + "find": "__MANAGED_IDENTITY__", + "replaceWith": "$(ManagedIdentity)" + }, + { + "find": "__CONTAINER_URI__", + "replaceWith": "$(Storage.StorageContainerUri)" + }, + { + "find": "__CONTAINER_SAS_TOKEN__", + "replaceWith": "$(Storage.StorageContainerSasToken)" + }, + { + "find": "__STORAGE_CONTAINER_NAME__", + "replaceWith": "$(StorageContainerName)" + }, + { + "find": "__STORAGE_ACCOUNT_NAME__", + "replaceWith": "$(StorageAccountName)" + } + + ] + } + ] +} \ No newline at end of file diff --git a/deployment/agent-deployment/ServiceGroupRoot/Scripts/pushAgentToAcr.sh b/deployment/agent-deployment/ServiceGroupRoot/Scripts/pushAgentToAcr.sh new file mode 100644 index 000000000..7e73a6230 --- /dev/null +++ b/deployment/agent-deployment/ServiceGroupRoot/Scripts/pushAgentToAcr.sh @@ -0,0 +1,110 @@ +#!/bin/bash +set -e + +# Note - This script used in the pipeline as inline script + +if [ -z $AGENT_IMAGE_TAG_SUFFIX ]; then + echo "-e error value of AGENT_IMAGE_TAG_SUFFIX variable shouldnt be empty. check release variables" + exit 1 +fi + +if [ -z $AGENT_RELEASE ]; then + echo "-e error AGENT_RELEASE shouldnt be empty. check release variables" + exit 1 +fi + +if [ -z $AGENT_IMAGE_URI ]; then + echo "-e error value of AGENT_IMAGE_URI shouldn't be empty. check output from file copy release task" + exit 1 +fi + +if [ -z $AGENT_IMAGE_SAS ]; then + echo "-e error value of AGENT_IMAGE_SAS shouldn't be empty. check output from file copy release task" + exit 1 +fi + +if [ -z $STORAGE_CONTAINER_NAME ]; then + echo "-e error value of STORAGE_CONTAINER_NAME shouldn't be empty. check release variables" + exit 1 +fi + +if [ -z $STORAGE_ACCOUNT_NAME ]; then + echo "-e error value of STORAGE_ACCOUNT_NAME shouldn't be empty. check release variables" + exit 1 +fi + +if [ -z $ACR_NAME ]; then + echo "-e error value of ACR_NAME shouldn't be empty. check release variables" + exit 1 +fi + +#Download agentimage tarball from blob storage account +echo "Downloading tarball image from $WINDOWS $AGENT_IMAGE_URI" +wget -O $AGENT_IMAGE_TAR_FILE_NAME "${AGENT_IMAGE_URI}${WINDOWS}${RELEASE_ID}${AGENT_IMAGE_SAS}" + + +if [ ! -f $AGENT_IMAGE_TAR_FILE_NAME ]; then + echo "Agent tarfile: ${AGENT_IMAGE_TAR_FILE_NAME} does not exist, unable to continue" + exit 1 +fi + +#Install crane +echo "Installing crane" +wget -O crane.tar.gz https://github.com/google/go-containerregistry/releases/download/v0.4.0/go-containerregistry_Linux_x86_64.tar.gz +if [ $? -eq 0 ]; then + echo "crane downloaded successfully" +else + echo "-e error crane download failed" + exit 1 +fi +tar xzvf crane.tar.gz +echo "Installed crane" + + +#Login to az cli and authenticate to acr +echo "Login cli using managed identity" +az login --identity + +echo "Getting acr credentials" +TOKEN_QUERY_RES=$(az acr login -n "$ACR_NAME" -t) +TOKEN=$(echo "$TOKEN_QUERY_RES" | jq -r '.accessToken') +if [ -z $TOKEN ]; then + echo "-e error failed to get az acr login token" + exit 1 +fi + +DESTINATION_ACR=$(echo "$TOKEN_QUERY_RES" | jq -r '.loginServer') +if [ -z $DESTINATION_ACR ]; then + echo "-e error value of DESTINATION_ACR shouldnt be empty" + exit 1 +fi + +./crane auth login "$DESTINATION_ACR" -u "00000000-0000-0000-0000-000000000000" -p "$TOKEN" + +#Prepare tarball and push to acr +if [[ "$AGENT_IMAGE_TAR_FILE_NAME" == *"tar.gz"* ]]; then + gunzip $AGENT_IMAGE_TAR_FILE_NAME +fi + +if [[ "$AGENT_IMAGE_TAR_FILE_NAME" == *"tar.zip"* ]]; then + unzip $AGENT_IMAGE_TAR_FILE_NAME +fi + +echo "Pushing file $TARBALL_IMAGE_FILE to $AGENT_IMAGE_FULL_PATH" +./crane push *.tar "$AGENT_IMAGE_FULL_PATH" + + +#Delete agentimage tarball from blob storage to prevent future conflicts +echo "Deleting agentimage copy from blob storage" + +BLOB_EXIST_RESULT=$(az storage blob exists --container-name $STORAGE_CONTAINER_NAME --name $WINDOWS$RELEASE_ID --account-name $STORAGE_ACCOUNT_NAME --sas-token $AGENT_IMAGE_SAS) +BLOB_EXIST=$(echo "$BLOB_EXIST_RESULT" | jq -r '.exists') +echo $BLOB_EXIST_RESULT +echo $BLOB_EXIST + +if $BLOB_EXIST; then + az storage blob delete --container-name "${STORAGE_CONTAINER_NAME}" --name "${WINDOWS}${RELEASE_ID}" --account-name "${STORAGE_ACCOUNT_NAME}" --sas-token "${AGENT_IMAGE_SAS}" + echo "Deleted agentimate copy from blob storage" +else + echo "Agentimage has already been deleted from blob storage" +fi \ No newline at end of file diff --git a/deployment/agent-deployment/ServiceGroupRoot/ServiceModels/Public.ServiceModel.json b/deployment/agent-deployment/ServiceGroupRoot/ServiceModels/Public.ServiceModel.json new file mode 100644 index 000000000..b7bd4aa26 --- /dev/null +++ b/deployment/agent-deployment/ServiceGroupRoot/ServiceModels/Public.ServiceModel.json @@ -0,0 +1,56 @@ +{ + "$schema": "https://ev2schema.azure.net/schemas/2020-01-01/serviceModel.json", + "contentVersion": "1.0.0.2", + "ServiceMetadata": { + "ServiceGroup": "ContainerInsightsAgent", + "Environment": "Dev" + }, + "ServiceResourceGroupDefinitions": [ + { + "Name": "CI-Agent-ServiceResourceGroupDefinition", + "ServiceResourceDefinitions": [ + { + "Name": "ShellExtension", + "ComposedOf": { + "Extension": { + "Shell": [ + { + "type": "ShellExtensionType", + "properties": { + "imageName": "adm-ubuntu-1804-l", + "imageVersion": "v18" + } + } + ] + } + } + } + ] + } + ], + "ServiceResourceGroups": [ + { + "AzureResourceGroupName": "ContainerInsightsAgent-Global-Release", + "Location": "eastus2", + "InstanceOf": "CI-Agent-ServiceResourceGroupDefinition", + "AzureSubscriptionId": "728bbd23-3b47-40c1-8c9a-c6c5ccd674fc", + "ScopeTags": [ + { + "Name": "Global" + } + ], + "ServiceResources": [ + { + "Name": "PushLinuxAgent", + "InstanceOf": "ShellExtension", + "RolloutParametersPath": "Parameters\\ContainerInsights.Linux.Parameters.json" + }, + { + "Name": "PushWindowsAgent", + "InstanceOf": "ShellExtension", + "RolloutParametersPath": "Parameters\\ContainerInsights.Windows.Parameters.json" + } + ] + } + ] + } \ No newline at end of file diff --git a/deployment/agent-deployment/ServiceGroupRoot/buildver.txt b/deployment/agent-deployment/ServiceGroupRoot/buildver.txt new file mode 100644 index 000000000..bd2666abb --- /dev/null +++ b/deployment/agent-deployment/ServiceGroupRoot/buildver.txt @@ -0,0 +1 @@ +1.0.0.0 \ No newline at end of file